repository.py 文件源码

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

项目:knowledge-repo 作者: airbnb 项目源码 文件源码
def dir(self, prefix=None, status=None):
        if prefix is None or isinstance(prefix, str):
            prefixes = [prefix]
        else:
            prefixes = prefix
        assert all([prefix is None or isinstance(prefix, str) for prefix in prefixes]), "All path prefixes must be strings."
        prefixes = [prefix if prefix is None else posixpath.relpath(prefix) for prefix in prefixes]
        if isinstance(status, str):
            if status == 'all':
                status = [self.PostStatus.DRAFT, self.PostStatus.SUBMITTED, self.PostStatus.PUBLISHED, self.PostStatus.UNPUBLISHED]
            else:
                raise ValueError('Status alias `{}` not recognised.'.format(status))
        if status is not None and not isinstance(status, list):
            status = [status]
        elif status is None:
            status = [self.PostStatus.PUBLISHED]

        # Use old syntax for "yielding from" to maintain support for python 2
        for prefix in prefixes:
            for path in self._dir(prefix=prefix, statuses=status):
                yield path
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号