index.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:aptrepo 作者: jwodder 项目源码 文件源码
def subindex(self, *path):
        """
        Returns an `IndexFile` object listing only those files in or below the
        directory given by ``*path``.  The path keys in the resulting object
        will be relative to ``*path``.

        ``*path`` may be any relative path specification accepted by
        `PurePath.relative_to`, such as a string (e.g., ``"main"`` or
        ``"main/binary-amd64"``), a sequence of strings (e.g., ``"main",
        "binary-amd64"``), or a `PurePosixPath` object.
        """
        ### TODO: Add an option for also updating the `filename` attributes of
        ### the IndexEntries?
        ### TODO: Add an option for controlling whether to keep `fields`?
        subfiles = {}
        for p, entry in self.files.items():
            pathobj = PurePosixPath(p)
            ### TODO: Handle absolute paths and paths beginning with .. (or .?)
            try:
                subpath = pathobj.relative_to(*path)
            except ValueError:
                pass
            else:
                subfiles[str(subpath)] = entry
        return type(self)(files=subfiles, fields=self.fields.copy())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号