HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/shortuuid/__pycache__/main.cpython-39.pyc
a

�,�hP�@s�dZddlZddlZddlZddlmZddlmZd
eee	eee	d�dd�Z
e	ee	ed�d	d
�ZGdd�de�Z
e
�ZejZejZejZejZejZejZdS)zConcise UUID generation.�N)�List)�Optional)�number�alphabet�padding�returncCs`d}t|�}|r,t||�\}}|||7}q|rRt|t|�d�}||d|}|ddd�S)zw
    Convert a number to a string, using the given alphabet.

    The output has the most significant digit first.
    �rN���)�len�divmod�max)rrr�output�	alpha_len�digit�	remainder�r�?/opt/nydus/tmp/pip-target-wkfpz8uv/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)rrrr�charrrr�
string_to_ints
rc@s�eZdZdeedd�dd�Zeed�dd��Zde	j
eeed�d	d
�Zdeee	j
d�d
d�Z
d eeeeed�dd�Zd!eeed�dd�Zed�dd�Zedd�dd�Zd"eed�dd�ZdS)#�	ShortUUIDN)rrcCs|durd}|�|�dS)NZ923456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz)�set_alphabet)�selfrrrr�__init__+szShortUUID.__init__)rcCstt�t�dd|j���S)zNReturn the necessary length to fit the entire UUID given the current alphabet.��)�int�math�ceil�log�
_alpha_len�rrrr�_length1szShortUUID._length)�uuid�
pad_lengthrcCs4t|tj�std��|dur"|j}t|j|j|d�S)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�_uu�UUID�
ValueErrorr$rr�	_alphabet)rr%r&rrr�encode6s
zShortUUID.encodeF)r�legacyrcCs8t|t�std��|r$|ddd�}tjt||j�d�S)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-rrr�decodeBs

zShortUUID.decode)�namer&rcCsX|dur|j}|dur t��}n,|���d�r>t�tj|�}nt�tj|�}|�||�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(�uuid4�lower�
startswith�uuid5�
NAMESPACE_URL�
NAMESPACE_DNSr,)rr0r&�urrrr%Ss
zShortUUID.uuid)�lengthrcs*|dur�j}d��fdd�t|�D��S)zOGenerate and return a cryptographically secure short random string of `length`.Nrc3s|]}t��j�VqdS)N)�secrets�choicer+)�.0�_r#rr�	<genexpr>k�z#ShortUUID.random.<locals>.<genexpr>)r$�join�range)rr8rr#r�randomfszShortUUID.randomcCsd�|j�S)z/Return the current alphabet used for new UUIDs.r)r?r+r#rrr�get_alphabetmszShortUUID.get_alphabetcCs<ttt|���}t|�dkr0||_t|j�|_ntd��dS)z*Set the alphabet to be used for new UUIDs.�z4Alphabet with more than one unique symbols required.N)�list�sorted�setr
r+r"r*)rrZnew_alphabetrrrrqs
zShortUUID.set_alphabet�)�	num_bytesrcCs(t�d�t�|j�}tt�||��S)z/Return the string length of the shortened UUID.�)rr!r"rr )rrHZfactorrrr�encoded_length|szShortUUID.encoded_length)N)N)F)NN)N)rG)�__name__�
__module__�__qualname__rr.r�propertyrr$r(r)r,�boolr/r%rArBrrJrrrrr*sr)N)�__doc__rr9r%r(�typingrrrr.rr�objectrZ_global_instancer,r/rArBrrrrr�<module>s&��
Y