Ñò æLRc @sÊdZyddklZWn#ej oddklZnXdZeeƒZd d„Zd„Z ee ƒe edd e d„ƒZ hdd 6d d 6Zed jodd kZeiƒnd 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ÿÿÿÿ(tmd5t23456789abcdefghjkmnpqrtuvwxyzcstˆtƒp t‚ndˆf‡‡‡fd†ƒY‰dˆiˆ_d„ˆ_d„ˆ_d„ˆ_d„ˆ_‡fd†}|S( sCDecorator to allow for on-demand evaluation (limited scope of use!)t _lazy_classcs7eZdˆi‡‡fd†Zd„Zd„ZRS(s#lazified access to value of %s typecstˆ|ƒi|ˆƒS(N(tsupert__new__(tselftargstkwargs(t dummy_initialR(sI/usr/lib/python2.6/site-packages/weberror/util/serial_number_generator.pyRsc_s||_||_t|_dS(N(t_argst_kwargstEllipsist_active(RRR((sI/usr/lib/python2.6/site-packages/weberror/util/serial_number_generator.pyt__init__s  c[sC|itjo,|i|iƒ|i|i|Ž|_n|iS(N(R R tupdateR t _generatorR (RR((sI/usr/lib/python2.6/site-packages/weberror/util/serial_number_generator.pyt__call__!s(t__name__t __module__RR R((RRt return_type(sI/usr/lib/python2.6/site-packages/weberror/util/serial_number_generator.pyRs  slazy_%scSs t|ƒƒS((tstr(R((sI/usr/lib/python2.6/site-packages/weberror/util/serial_number_generator.pyt*scSs t|ƒƒS((trepr(R((sI/usr/lib/python2.6/site-packages/weberror/util/serial_number_generator.pyR+scSst|ƒ|ƒS((tcmp(Rtother((sI/usr/lib/python2.6/site-packages/weberror/util/serial_number_generator.pyR,sc[st|ƒ|S((tslice(Rtkws((sI/usr/lib/python2.6/site-packages/weberror/util/serial_number_generator.pyR-scst|ƒˆ_ˆS(N(t staticmethodR(t generator(R(sI/usr/lib/python2.6/site-packages/weberror/util/serial_number_generator.pyt_generating_lazy_class/s(t issubclasst basestringtNotImplementedErrorRt__str__t__repr__t__cmp__t __getslice__(RRR((RRRsI/usr/lib/python2.6/site-packages/weberror/util/serial_number_generator.pyt lazy_results "    cCs’t|ttfƒptd|ƒ‚n|djotd|ƒ‚ng}x1|o)|t}|it|ƒ|t}qTWdi|ƒS(s, Encodes a number as an identifier. s6You can only make identifiers out of integers (not %r)is7You cannot make identifiers out of negative numbers: %rt(t isinstancetinttlongt ValueErrortbasetappendtgood_characterstjoin(tnumbertresulttnext((sI/usr/lib/python2.6/site-packages/weberror/util/serial_number_generator.pytmake_identifier5s  R&cCsft|ƒp |i}n|djo|tjotd|‚nt|tƒo|idƒ}n|t|ƒƒ}|iƒ}t |} d} x,t |ƒD]} | dt | ƒ| } q£Wt | ƒ} |o t d|t| ƒ| } n|oHg} x,| o$| id| | ƒ| | } qWdi| ƒ} 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. isJmd5 cannot create hashes longer than 26 characters in length (you gave %s)sutf-8iit-(tcallabletnewRR*R'tunicodetencodeRtdigestR+tlisttordR2R-tlentinsertR.tupper(tstlengthtpadthashertprefixtgroupR=thtbin_hashtmoduloR/tctidenttparts((sI/usr/lib/python2.6/site-packages/weberror/util/serial_number_generator.pythash_identifierIs8        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' R2s' >>> 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' RJt__main__N(t__doc__thashlibRt ImportErrorR-R;R+tNoneR%R2RtTruetFalseRJt__test__Rtdoctestttestmod(((sI/usr/lib/python2.6/site-packages/weberror/util/serial_number_generator.pyt s"  !   +