Back to index

python3.2  3.2.2
Functions | Variables
hashlib Namespace Reference

Functions

def __get_builtin_constructor
def __get_openssl_constructor
def __py_new
def __hash_new

Variables

string __doc__
tuple __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')
tuple algorithms_guaranteed = set(__always_supported)
tuple algorithms_available = set(__always_supported)
tuple __all__
 new = __py_new
 __get_hash = __get_builtin_constructor

Function Documentation

def hashlib.__get_builtin_constructor (   name) [private]

Definition at line 66 of file hashlib.py.

00066 
00067 def __get_builtin_constructor(name):
00068     try:
00069         if name in ('SHA1', 'sha1'):
00070             import _sha1
00071             return _sha1.sha1
00072         elif name in ('MD5', 'md5'):
00073             import _md5
00074             return _md5.md5
00075         elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
00076             import _sha256
00077             bs = name[3:]
00078             if bs == '256':
00079                 return _sha256.sha256
00080             elif bs == '224':
00081                 return _sha256.sha224
00082         elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
00083             import _sha512
00084             bs = name[3:]
00085             if bs == '512':
00086                 return _sha512.sha512
00087             elif bs == '384':
00088                 return _sha512.sha384
00089     except ImportError:
00090         pass  # no extension module, this hash is unsupported.
00091 
00092     raise ValueError('unsupported hash type %s' % name)
00093 

Here is the caller graph for this function:

def hashlib.__get_openssl_constructor (   name) [private]

Definition at line 94 of file hashlib.py.

00094 
00095 def __get_openssl_constructor(name):
00096     try:
00097         f = getattr(_hashlib, 'openssl_' + name)
00098         # Allow the C module to raise ValueError.  The function will be
00099         # defined but the hash not actually available thanks to OpenSSL.
00100         f()
00101         # Use the C function directly (very fast)
00102         return f
00103     except (AttributeError, ValueError):
00104         return __get_builtin_constructor(name)
00105 

Here is the call graph for this function:

def hashlib.__hash_new (   name,
  data = b'' 
) [private]
new(name, data=b'') - Return a new hashing object using the named algorithm;
optionally initialized with data (which must be bytes).

Definition at line 113 of file hashlib.py.

00113 
00114 def __hash_new(name, data=b''):
00115     """new(name, data=b'') - Return a new hashing object using the named algorithm;
00116     optionally initialized with data (which must be bytes).
00117     """
00118     try:
00119         return _hashlib.new(name, data)
00120     except ValueError:
00121         # If the _hashlib module (OpenSSL) doesn't support the named
00122         # hash, try using our builtin implementations.
00123         # This allows for SHA224/256 and SHA384/512 support even though
00124         # the OpenSSL library prior to 0.9.8 doesn't provide them.
00125         return __get_builtin_constructor(name)(data)
00126 
00127 
00128 try:
00129     import _hashlib
00130     new = __hash_new
00131     __get_hash = __get_openssl_constructor
00132     algorithms_available = algorithms_available.union(
            _hashlib.openssl_md_meth_names)

Here is the call graph for this function:

def hashlib.__py_new (   name,
  data = b'' 
) [private]
new(name, data=b'') - Return a new hashing object using the named algorithm;
optionally initialized with data (which must be bytes).

Definition at line 106 of file hashlib.py.

00106 
00107 def __py_new(name, data=b''):
00108     """new(name, data=b'') - Return a new hashing object using the named algorithm;
00109     optionally initialized with data (which must be bytes).
00110     """
00111     return __get_builtin_constructor(name)(data)
00112 

Here is the call graph for this function:


Variable Documentation

Initial value:
00001 __always_supported+('new', 'algorithms_guaranteed',
00002                                 'algorithms_available')

Definition at line 62 of file hashlib.py.

tuple hashlib.__always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')

Definition at line 57 of file hashlib.py.

Definition at line 5 of file hashlib.py.

Definition at line 135 of file hashlib.py.

Definition at line 60 of file hashlib.py.

Definition at line 59 of file hashlib.py.

Definition at line 134 of file hashlib.py.