internals.py 文件源码

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

项目:aptrepo 作者: jwodder 项目源码 文件源码
def unprefix(suite, component):
    """
    If ``component`` begins with one or more path components (excluding the
    last) that also occur at the end of ``suite`` (excluding the first), remove
    the prefix from ``component`` and return the remainder.

    This function is used for removing prefixes that may occur in component
    names listed in suite Release files when the suite name contains multiple
    path components.

    >>> unprefix('stable', 'main')
    'main'

    >>> unprefix('stable/updates', 'updates/main')
    'main'

    >>> unprefix('stable/updates', 'main')
    'main'

    >>> unprefix('trusty', 'trusty/main')
    'trusty/main'

    >>> unprefix('foo', 'foo')
    'foo'

    >>> unprefix('foo', 'foo/bar')
    'foo/bar'

    >>> unprefix('foo/bar', 'bar')
    'bar'
    """
    suite = PurePosixPath(suite)
    component = PurePosixPath(component)
    for i in range(min(len(suite.parts), len(component.parts))):
        if suite.parts[-(i+1):] != component.parts[:i+1]:
            break
    return str(PurePosixPath(*component.parts[i:]))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号