Ñò
ô³Kc
@ s² d Z y d d k l Z Wn# e j
o d d k l Z n Xd Z e e Z d Z e e d d e
d Z h d d 6d d
6Z e
d j o d d k Z e i n d S(
sê
Creates a human-readable identifier, using numbers and digits,
avoiding ambiguous numbers and letters. hash_identifier can be used
to create compact representations that are unique for a certain string
(or concatenation of strings)
i˙˙˙˙( t md5t 23456789abcdefghjkmnpqrtuvwxyzc C s t | t t f p t d | n | d j o t d | n g } x1 | o) | t } | i t | | t } qT Wd i | S( s,
Encodes a number as an identifier.
s6 You can only make identifiers out of integers (not %r)i s7 You cannot make identifiers out of negative numbers: %rt ( t
isinstancet intt longt
ValueErrort baset appendt good_characterst join( t numbert resultt next( ( sL /usr/lib/python2.6/site-packages/paste/exceptions/serial_number_generator.pyt make_identifier s
R c C sf t | p
| i } n | d j o | t j o t d | n t | t o | i d } n | t | } | i } t | } d }
x, t
| D] } |
d t | | }
q£ Wt |
} | o t
d | t | | } n | oH g }
x, | o$ |
i d | | | | } qWd i |
} n | o | i } n | | S( s
Hashes the string (with the given hashing module), then turns that
hash into an identifier of the given length (using modulo to
reduce the length of the identifier). If ``pad`` is False, then
the minimum-length identifier will be used; otherwise the
identifier will be padded with 0's as necessary.
``prefix`` will be added last, and does not count towards the
target length. ``group`` will group the characters with ``-`` in
the given lengths, and also does not count towards the target
length. E.g., ``group=4`` will cause a identifier like
``a5f3-hgk3-asdf``. Grouping occurs before the prefix.
i sJ md5 cannot create hashes longer than 26 characters in length (you gave %s)s utf-8i i t -( t callablet newR R R t unicodet encodet strt digestR t listt ordR R t lent insertR
t upper( t st lengtht padt hashert prefixt groupR t ht bin_hasht moduloR t ct identt parts( ( sL /usr/lib/python2.6/site-packages/paste/exceptions/serial_number_generator.pyt hash_identifier( s8
sż
>>> make_identifier(0)
''
>>> make_identifier(1000)
'c53'
>>> make_identifier(-100)
Traceback (most recent call last):
...
ValueError: You cannot make identifiers out of negative numbers: -100
>>> make_identifier('test')
Traceback (most recent call last):
...
ValueError: You can only make identifiers out of integers (not 'test')
>>> make_identifier(1000000000000)
'c53x9rqh3'
R s'
>>> hash_identifier(0, 5)
'cy2dr'
>>> hash_identifier(0, 10)
'cy2dr6rg46'
>>> hash_identifier('this is a test of a long string', 5)
'awatu'
>>> hash_identifier(0, 26)
'cy2dr6rg46cx8t4w2f3nfexzk4'
>>> hash_identifier(0, 30)
Traceback (most recent call last):
...
ValueError: md5 cannot create hashes longer than 26 characters in length (you gave 30)
>>> hash_identifier(0, 10, group=4)
'cy-2dr6-rg46'
>>> hash_identifier(0, 10, group=4, upper=True, prefix='M-')
'M-CY-2DR6-RG46'
R' t __main__N( t __doc__t hashlibR t ImportErrorR R R R t Truet Nonet FalseR' t __test__t __name__t doctestt testmod( ( ( sL /usr/lib/python2.6/site-packages/paste/exceptions/serial_number_generator.pyt