o
    hK                     @   sx   d Z dZdZedd ZdZedd ZdZedd d	 Zedd ZG d
d de	Z
defddZdefddZdS )zeConvert strings to numbers and numbers to strings.

Gustavo Picon
https://tabo.pe/projects/numconv/

z2.1.1zU0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~N    ABCDEFGHIJKLMNOPQRSTUVWXYZ234567    z@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/>   z-_c                   @   s.   e Zd ZdZdefddZdd Zdd Zd	S )
NumConvae  Class to create converter objects.

        :param radix: The base that will be used in the conversions.
           The default value is 10 for decimal conversions.
        :param alphabet: A string that will be used as a encoding alphabet.
           The length of the alphabet can be longer than the radix. In this
           case the alphabet will be internally truncated.

           The default value is :data:`numconv.BASE85`

        :raise TypeError: when *radix* isn't an integer
        :raise ValueError: when *radix* is invalid
        :raise ValueError: when *alphabet* has duplicated characters
    
   c                 C   s   t ||kr
tdd|  krt|ks n tdt|f || _|| _tt| jtt| j| _	t| j	t| jkrFtd| jf dS )z'basic validation and cached_map storagezradix must be an integer   zradix must be >= 2 and <= %dz"duplicate characters found in '%s'N)
int	TypeErrorlen
ValueErrorradixalphabetdictziprange
cached_map)selfr   r    r   Q/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/treebeard/numconv.py__init__*   s   zNumConv.__init__c                 C   s   t ||kr
td|dk rtd| j| j}}|dv r9|d|  td|  kr9dddd| |  S d	}	 |||  | }||k rK	 |S || }q<)
a  Converts an integer into a string.

        :param num: A numeric value to be converted to another base as a
                    string.

        :rtype: string

        :raise TypeError: when *num* isn't an integer
        :raise ValueError: when *num* isn't positive
        znumber must be an integer    znumber must be positive)   r   r   Nz%oz%dz%x )r   r	   r   r   r   lowerBASE85upper)r   numr   r   retr   r   r   int2str8   s     zNumConv.int2strc                 C   s   | j | j}}|dkr |d|  td|  kr t||S d}|d| }|D ]}||vr8td||f || | j|  }q*|S )a  Converts a string into an integer.

        If possible, the built-in python conversion will be used for speed
        purposes.

        :param num: A string that will be converted to an integer.

        :rtype: integer

        :raise ValueError: when *num* is invalid
        $   Nr   z3invalid literal for radix2int() with radix %d: '%s')r   r   r   r   r   r   r   )r   r   r   r   r   	lalphabetcharr   r   r   str2intS   s   (
zNumConv.str2intN)__name__
__module____qualname____doc__r   r   r   r"   r   r   r   r   r      s
    r   r   c                 C      t ||| S )zChelper function for quick base conversions from integers to strings)r   r   r   r   r   r   r   r   r   l      r   c                 C   r'   )zChelper function for quick base conversions from strings to integers)r   r"   r(   r   r   r   r"   q   r)   r"   )r&   __version__r   BASE16BASE32	BASE32HEXBASE64	BASE64URLBASE62objectr   r   r"   r   r   r   r   <module>   s    R