示例#1
0
def safe_id(identifier):
    if not SAFENAME.match(identifier):
        identifier = u'sha1-' + sha1(identifier.encode('utf-8')).hexdigest()
    elif SHA1_ID.match(identifier):
        # could collide with "safe" id and should never happen anyway
        raise ValueError("illegal doc id: {!r}".format(identifier))
    return identifier
示例#2
0
def safe_id(identifier):
    if not SAFENAME.match(identifier):
        identifier = u'sha1-' + sha1(identifier.encode('utf-8')).hexdigest()
    elif SHA1_ID.match(identifier):
        # could collide with "safe" id and should never happen anyway
        raise ValueError("illegal doc id: {!r}".format(identifier))
    return identifier
示例#3
0
def safejoin(root, subpath):
    if not SAFENAME.match(subpath):
        raise BadName(u"unsafe path name: %r" % subpath)
    path = join(root, subpath)
    if commonprefix([root + sep, path]) != root + sep:
        raise BadName(u"invalid relative path: %r" % subpath)
    return path
示例#4
0
def safepath(path):
    if (path.startswith(("/", ".")) or
            "/../" in path or
            path.endswith("/..") or
            not SAFENAME.match(path)):
        raise BadName("unsafe path name: %r" % path)
    return path
示例#5
0
def safejoin(root, subpath):
    if not SAFENAME.match(subpath):
        raise BadName(u"unsafe path name: %r" % subpath)
    path = join(root, subpath)
    if commonprefix([root + sep, path]) != root + sep:
        raise BadName(u"invalid relative path: %r" % subpath)
    return path
示例#6
0
def safepath(path):
    if (path.startswith(("/", ".")) or
            "/../" in path or
            path.endswith("/..") or
            not SAFENAME.match(path)):
        raise BadName(u"unsafe path name: %r" % path)
    return path
示例#7
0
def safejoin(root, subpath):
    """Join root to subpath ensuring that the result is actually inside root
    """
    root = realpath(root)
    if not SAFENAME.match(subpath):
        raise BadName(u"unsafe path name: %r" % subpath)
    path = realpath(join(root, subpath))
    if commonprefix([root + sep, path]) != root + sep:
        raise BadName(u"invalid relative path: %r" % subpath)
    return path
示例#8
0
def safejoin(root, subpath):
    """Join root to subpath ensuring that the result is actually inside root
    """
    root = realpath(root)
    if not SAFENAME.match(subpath):
        raise BadName(u"unsafe path name: %r" % subpath)
    path = realpath(join(root, subpath))
    if commonprefix([root + sep, path]) != root + sep:
        raise BadName(u"invalid relative path: %r" % subpath)
    return path