]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
filesystem: check if name exists (__contains__)
authorDmitry Selyutin <ghostmansd@gmail.com>
Tue, 3 Oct 2017 07:42:52 +0000 (10:42 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 3 Oct 2017 07:42:52 +0000 (10:42 +0300)
pygnulib/filesystem.py

index 4ce446315f37911bb15ce6c78420a39e5d6cfcc2..ded4268a58748b86f655ceeafca8c19682257857 100644 (file)
@@ -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)