def encoded_path(root, identifiers, extension=".enc", depth=3, digest_filenames=True): """Generate a unique file-accessible path from the given list of identifiers starting at the given root directory.""" ident = "_".join(identifiers) global sha1 if sha1 is None: from beaker.crypto import sha1 if digest_filenames: if isinstance(ident, unicode_text): ident = sha1(ident.encode('utf-8')).hexdigest() else: ident = sha1(ident).hexdigest() ident = os.path.basename(ident) tokens = [] for d in range(1, depth): tokens.append(ident[0:d]) dir = os.path.join(root, *tokens) verify_directory(dir) return os.path.join(dir, ident + extension)
def _session_id(): id_str = "%f%s%f%s" % (time.time(), id({}), random.random(), getpid()) # NB: nothing against second parameter to b64encode, but it seems # to be slower than simple chained replacement if not PY2: raw_id = b64encode(sha1(id_str.encode("ascii")).digest()) return str(raw_id.replace(b"+", b"-").replace(b"/", b"_").rstrip(b"=")) else: raw_id = b64encode(sha1(id_str).digest()) return raw_id.replace("+", "-").replace("/", "_").rstrip("=")
def _session_id(): id_str = "%f%s%f%s" % (time.time(), id({}), random.random(), getpid()) # NB: nothing against second parameter to b64encode, but it seems # to be slower than simple chained replacement if not PY2: raw_id = b64encode(sha1(id_str.encode('ascii')).digest()) return str( raw_id.replace(b'+', b'-').replace(b'/', b'_').rstrip(b'=')) else: raw_id = b64encode(sha1(id_str).digest()) return raw_id.replace('+', '-').replace('/', '_').rstrip('=')
def _session_id(): id_str = "%f%s%f%s" % ( time.time(), id({}), random.random(), getpid() ) # NB: nothing against second parameter to b64encode, but it seems # to be slower than simple chained replacement if not PY2: raw_id = b64encode(sha1(id_str.encode('ascii')).digest()) return str(raw_id.replace(b'+', b'-').replace(b'/', b'_').rstrip(b'=')) else: raw_id = b64encode(sha1(id_str).digest()) return raw_id.replace('+', '-').replace('/', '_').rstrip('=')