Esempio n. 1
0
def safe_id(identifier):
    if not SAFENAME.match(identifier):
        identifier = '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
Esempio n. 2
0
def safe_id(identifier):
    if not SAFENAME.match(identifier):
        identifier = '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
Esempio n. 3
0
def safejoin(root, subpath):
    if not SAFENAME.match(subpath):
        raise BadName("unsafe path name: %r" % subpath)
    path = join(root, subpath)
    if commonprefix([root + sep, path]) != root + sep:
        raise BadName("invalid relative path: %r" % subpath)
    return path
Esempio n. 4
0
def safejoin(root, subpath):
    if not SAFENAME.match(subpath):
        raise BadName("unsafe path name: %r" % subpath)
    path = join(root, subpath)
    if commonprefix([root + sep, path]) != root + sep:
        raise BadName("invalid relative path: %r" % subpath)
    return path