From: Dmitry Selyutin Date: Tue, 3 Oct 2017 07:42:52 +0000 (+0300) Subject: filesystem: check if name exists (__contains__) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=997c42e2fdac61b0a88a173058dda7f442759d6d;p=thirdparty%2Fgnulib.git filesystem: check if name exists (__contains__) --- diff --git a/pygnulib/filesystem.py b/pygnulib/filesystem.py index 4ce446315f..ded4268a58 100644 --- a/pygnulib/filesystem.py +++ b/pygnulib/filesystem.py @@ -47,6 +47,15 @@ class Directory: return "{}.{}{}".format(module, name, repr(self.__name)) + def __contains__(self, name): + path = _os_.path.normpath(name) + if _os_.path.isabs(name): + raise ValueError("name must be a relative path") + path = _os_.path.join(self.__path, name) + return _os_.path.exists(path) + + + def __getitem__(self, name): """retrieve the canonical path of the specified file name""" _type_assert_("name", name, str)