var/opt/nydus/ops/shortuuid/__pycache__/main.cpython-38.pyc000064400000011533147205631620017724 0ustar00U afP@sdZddlZddlZddlZddlmZddlmZd eee eee dddZ e ee edd d Z Gd d d e Z e ZejZejZejZejZejZejZdS)zConcise UUID generation.N)List)Optional)numberalphabetpaddingreturncCs`d}t|}|r,t||\}}|||7}q |rRt|t|d}||d|}|dddS)zw Convert a number to a string, using the given alphabet. The output has the most significant digit first. rN)lendivmodmax)rrroutput alpha_lendigit remainderr?/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/shortuuid/main.py int_to_string sr)stringrrcCs,d}t|}|D]}||||}q|S)z Convert a string to a number, using the given alphabet. The input is assumed to have the most significant digit first. r)r index)rrrrcharrrr string_to_ints rc@seZdZdeeddddZeedddZde j eeedd d Z dee e j d d dZ d eeeeedddZd!eeedddZedddZeddddZd"eedddZdS)# ShortUUIDN)rrcCs|dkr d}||dS)NZ923456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz) set_alphabet)selfrrrr__init__+szShortUUID.__init__)rcCstttdd|jS)zNReturn the necessary length to fit the entire UUID given the current alphabet.)intmathceillog _alpha_lenrrrr_length1szShortUUID._length)uuid pad_lengthrcCs4t|tjstd|dkr"|j}t|j|j|dS)z Encode a UUID into a string (LSB first) according to the alphabet. If leftmost (MSB) bits are 0, the string might be shorter. z#Input `uuid` must be a UUID object.N)r) isinstance_uuUUID ValueErrorr$rr _alphabet)rr%r&rrrencode6s  zShortUUID.encodeF)rlegacyrcCs8t|tstd|r$|ddd}tjt||jdS)aL Decode a string according to the current alphabet into a UUID. Raises ValueError when encountering illegal characters or a too-long string. If string too short, fills leftmost (MSB) bits with 0. Pass `legacy=True` if your UUID was encoded with a ShortUUID version prior to 1.0.0. zInput `string` must be a str.Nr )r)r'strr*r(r)rr+)rrr-rrrdecodeBs zShortUUID.decode)namer&rcCsX|dkr|j}|dkr t}n,|dr>ttj|}nttj|}|||S)z Generate and return a UUID. If the name parameter is provided, set the namespace to the provided name and generate a UUID. N)zhttp://zhttps://) r$r(uuid4lower startswithuuid5 NAMESPACE_URL NAMESPACE_DNSr,)rr0r&urrrr%Ss zShortUUID.uuid)lengthrcs*|dkrj}dfddt|DS)zOGenerate and return a cryptographically secure short random string of `length`.Nrc3s|]}tjVqdS)N)secretschoicer+).0_r#rr ksz#ShortUUID.random..)r$joinrange)rr8rr#rrandomfszShortUUID.randomcCs d|jS)z/Return the current alphabet used for new UUIDs.r)r>r+r#rrr get_alphabetmszShortUUID.get_alphabetcCs<ttt|}t|dkr0||_t|j|_ntddS)z*Set the alphabet to be used for new UUIDs.z4Alphabet with more than one unique symbols required.N)listsortedsetr r+r"r*)rrZ new_alphabetrrrrqs  zShortUUID.set_alphabet) num_bytesrcCs(tdt|j}tt||S)z/Return the string length of the shortened UUID.)rr!r"rr )rrGZfactorrrrencoded_length|szShortUUID.encoded_length)N)N)F)NN)N)rF)__name__ __module__ __qualname__rr.rpropertyrr$r(r)r,boolr/r%r@rArrIrrrrr*s  r)N)__doc__rr9r%r(typingrrrr.rrobjectrZ_global_instancer,r/r@rArrrrrs*    Y