
    GohP              	       .   d Z ddlZddlZddlZddlmZ ddlmZ 	 ddedee	   dee   de	fd	Z
d
e	dee	   defdZ G d de      Z e       Zej                  Zej                   Zej                  Zej"                  Zej$                  Zej&                  Zy)zConcise UUID generation.    N)List)Optionalnumberalphabetpaddingreturnc                     d}t        |      }| rt        | |      \  } }|||   z  }| r|r#t        |t        |      z
  d      }||d   |z  z   }|ddd   S )zw
    Convert a number to a string, using the given alphabet.

    The output has the most significant digit first.
     r   N)lendivmodmax)r   r   r   output	alpha_lendigit	remainders          j/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/shortuuid/main.pyint_to_stringr   
   ss     FHI
vy1(5/!  #f+-q1	(1+	11$B$<    stringc                 \    d}t        |      }| D ]  }||z  |j                  |      z   } |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)r   r   r   r   chars        r   string_to_intr      s>     FHI ;)#hnnT&::;Mr   c                       e Zd Zddee   ddfdZedefd       Zdde	j                  dee   defdZdd	ed
ede	j                  fdZddee   dee   defdZddee   defdZdefdZdeddfdZddedefdZy)	ShortUUIDNr   r   c                 .    |d}| j                  |       y )N923456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz)set_alphabet)selfr   s     r   __init__zShortUUID.__init__+   s    UH(#r   c                     t        t        j                  t        j                  ddz  | j                                    S )zNReturn the necessary length to fit the entire UUID given the current alphabet.      )intmathceillog
_alpha_lenr    s    r   _lengthzShortUUID._length1   s+     499TXXafdoo>?@@r   uuid
pad_lengthc                     t        |t        j                        st        d      || j                  }t        |j                  | j                  |      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.)r   )
isinstance_uuUUID
ValueErrorr+   r   r%   	_alphabet)r    r,   r-   s      r   encodezShortUUID.encode6   sD     $)BCCJTXXt~~zJJr   r   legacyc                     t        |t              st        d      |r|ddd   }t        j                  t        || j                              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.
        zInput `string` must be a str.Nr   )r%   )r/   strr2   r0   r1   r   r3   )r    r   r5   s      r   decodezShortUUID.decodeB   sD     &#&<==DbD\FxxM&$..ABBr   namec                 @   || j                   }|t        j                         }nh|j                         j	                  d      r%t        j
                  t        j                  |      }n$t        j
                  t        j                  |      }| j                  ||      S )z
        Generate and return a UUID.

        If the name parameter is provided, set the namespace to the provided
        name and generate a UUID.
        )zhttp://zhttps://)	r+   r0   uuid4lower
startswithuuid5NAMESPACE_URLNAMESPACE_DNSr4   )r    r9   r-   us       r   r,   zShortUUID.uuidS   sw     J <		AZZ\$$%<=		#++T2A		#++T2A{{1j))r   lengthc                 f     | j                   }dj                   fdt        |      D              S )zOGenerate and return a cryptographically secure short random string of `length`.r
   c              3   \   K   | ]#  }t        j                  j                         % y wN)secretschoicer3   ).0_r    s     r   	<genexpr>z#ShortUUID.random.<locals>.<genexpr>k   s     M!w~~dnn5Ms   ),)r+   joinrange)r    rB   s   ` r   randomzShortUUID.randomf   s*    >\\FwwMuV}MMMr   c                 8    dj                  | j                        S )z/Return the current alphabet used for new UUIDs.r
   )rK   r3   r*   s    r   get_alphabetzShortUUID.get_alphabetm   s    wwt~~&&r   c                     t        t        t        |                  }t        |      dkD  r"|| _        t        | j                        | _        yt        d      )z*Set the alphabet to be used for new UUIDs.   z4Alphabet with more than one unique symbols required.N)listsortedsetr   r3   r)   r2   )r    r   new_alphabets      r   r   zShortUUID.set_alphabetq   sG     F3x=12|q )DN!$..1DOVWWr   	num_bytesc                     t        j                  d      t        j                  | j                        z  }t        t        j                  ||z              S )z/Return the string length of the shortened UUID.   )r&   r(   r)   r%   r'   )r    rV   factors      r   encoded_lengthzShortUUID.encoded_length|   s:    #$//!::499Vi/011r   rE   )F)NN)   )__name__
__module____qualname__r   r7   r!   propertyr%   r+   r0   r1   r4   boolr8   r,   rM   rO   r   rZ    r   r   r   r   *   s    $# $$ $ A A A
K388 
K# 
K# 
KCS C$ C388 C"*# *8C= *TW *&NXc] Nc N'c '	XS 	XT 	X2 2S 2r   r   rE   )__doc__r&   rF   r,   r0   typingr   r   r%   r7   r   r   objectr   _global_instancer4   r8   rM   rO   r   ra   r   r   <module>rf      s          @D9/7}&
# 
c 
s 
U2 U2r ; 		 	 		 	 		 	 ,,,,r   