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
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