MCPcopy Create free account
hub / github.com/ipython/ipython / code_name

Function code_name

IPython/core/compilerop.py:54–63  ·  view source on GitHub ↗

Compute a (probably) unique name for code for caching. This now expects code to be unicode.

(code, number=0)

Source from the content-addressed store, hash-verified

52#-----------------------------------------------------------------------------
53
54def code_name(code, number=0):
55 """ Compute a (probably) unique name for code for caching.
56
57 This now expects code to be unicode.
58 """
59 hash_digest = hashlib.sha1(code.encode("utf-8")).hexdigest()
60 # Include the number and 12 characters of the hash in the name. It's
61 # pretty much impossible that in a single session we'll have collisions
62 # even with truncated hashes, and the full one makes tracebacks too long
63 return '<ipython-input-{0}-{1}>'.format(number, hash_digest[:12])
64
65#-----------------------------------------------------------------------------
66# Classes and functions

Callers 1

cacheMethod · 0.85

Calls 1

formatMethod · 0.45

Tested by

no test coverage detected