Example #1
0
 def listdir(self):
     if self.exists():
         if self.isdir():
             return self.archive.childmap[self.pathInArchive].keys()
         else:
             raise UnlistableError("Leaf zip entry listed")
     else:
         raise UnlistableError("Non-existent zip entry listed")
Example #2
0
    def listdir(self):
        extent = self._iso.findDir(self._path)

        if extent is None:
            raise UnlistableError()

        return [r.name for r in self._iso.readRecords(extent, self._path)]
Example #3
0
    def listdir(self):
        """
        Pretend that we are a directory and get a listing of child names.
        """

        if self._path not in self._fs._dirs:
            raise UnlistableError()

        i = chain(self._fs._dirs, self._fs._store.keys())

        # Linear-time search. Could be better.
        p = self._path
        l = len(p) + 1
        ks = [t[-1] for t in i if t[:-1] == p and len(t) == l]

        return ks
Example #4
0
    def listdir(self):
        """
        List the base names of the direct children of this :py:class:`FilePath`.

        :return: A L{list} of L{bytes} giving the names of the contents of the
                 directory this :py:class:`FilePath` refers to.  These names
                 are relative to this :py:class:`FilePath`.
        :rtype: L{list}

        :raise OSError: If an error occurs while listing the directory.  If
                        the error is 'serious', meaning that the operation
                        failed due to an access violation, exhaustion of some
                        kind of resource (file descriptors or memory), OSError
                        or a platform-specific variant will be raised.

        :raise UnlistableError: If the inability to list the directory is due
                                to this path not existing or not being a
                                directory, the more specific OSError subclass
                                L{UnlistableError} is raised instead.

        :raise: Anything the platform L{os.listdir} implementation might raise
                (typically L{OSError}).
        """
        try:
            subnames = listdir(self.path)
        except WindowsError as winErrObj:
            # WindowsError is an OSError subclass, so if not for this clause
            # the OSError clause below would be handling these.  Windows error
            # codes aren't the same as POSIX error codes, so we need to handle
            # them differently.

            # Under Python 2.5 on Windows, WindowsError has a winerror
            # attribute and an errno attribute.  The winerror attribute is
            # bound to the Windows error code while the errno attribute is
            # bound to a translation of that code to a perhaps equivalent POSIX
            # error number.

            # Under Python 2.4 on Windows, WindowsError only has an errno
            # attribute.  It is bound to the Windows error code.

            # For simplicity of code and to keep the number of paths through
            # this suite minimal, we grab the Windows error code under either
            # version.

            # Furthermore, attempting to use os.listdir on a non-existent path
            # in Python 2.4 will result in a Windows error code of
            # ERROR_PATH_NOT_FOUND.  However, in Python 2.5,
            # ERROR_FILE_NOT_FOUND results instead. -exarkun
            winerror = getattr(winErrObj, 'winerror', winErrObj.errno)
            if winerror not in (ERROR_PATH_NOT_FOUND, ERROR_FILE_NOT_FOUND,
                                ERROR_INVALID_NAME, ERROR_DIRECTORY):
                raise
            raise UnlistableError(winErrObj)
        except OSError as ose:
            if ose.errno not in (errno.ENOENT, errno.ENOTDIR):
                # Other possible errors here, according to linux manpages:
                # EACCES, EMIFLE, ENFILE, ENOMEM.  None of these seem like the
                # sort of thing which should be handled normally. -glyph
                raise
            raise UnlistableError(ose)
        return subnames