U
    nh6                     @   sJ  d Z ddlZejdkrNddlZejd ZeZeZe	Z
dd ZG dd deZnVeZddlZddlZed	Zed
ZedZdd ZeZ
dd ZG dd deZedZedZedZedZedZedZedZedZedZedZedZ edZ!dd Z"dd Z#G d d! d!eZ$d"d# Z%e&d$krFddl'Z'e'(  dS )%u)  Python 2.x/3.x compatibility utilities.

This module defines a collection of functions that allow the same Python
source code to be used in both Python 2.x and Python 3.x.

 - prnt() prints its arguments to a file, with given separator and ending.
 - to_long() creates a (long) integer object from its input parameter.
 - u() allows string literals involving non-ASCII characters to be
   used in both Python 2.x / 3.x, e.g. u("ā is a-with-macron")
 - unicod() forces its argument to a Unicode string.
 - rpr() generates a representation of a string that can be parsed in either
   Python 2.x or 3.x, assuming use of the u() function above.

>>> from .util import prnt, u, rpr
>>> prnt("hello")
hello
>>> prnt("hello", "world")
hello world
>>> prnt("hello", "world", sep=":")
hello:world
>>> prnt("hello", "world", sep=":", end='!\n')
hello:world!
>>> u('ā') == u('ā')
True
>>> u('ā') == u('ā')
True
>>> a_macron = u('ā')
>>> rpr(a_macron)
"u('\\u0101')"
>>> rpr(u('abc')) == "'abc'"  # In Python 2, LHS is Unicode but RHS is string
True
>>> rpr("'")
"'\\''"
    N)   r   printc                  O   s:   | dd}| dd}| dd }t| |||d d S )Nsep end
file)r   r   r   )getprint3argskwargsr   r   r    r   Y/var/www/html/peyman_registration/venvv2/lib/python3.8/site-packages/phonenumbers/util.pyprnt.   s    r   c                   @   s   e Zd ZdZdd ZdS )UnicodeMixinEMixin class to define a __str__ method in terms of __unicode__ methodc                 C   s   |   S )N)__unicode__selfr   r   r   __str__6   s    UnicodeMixin.__str__N__name__
__module____qualname____doc__r   r   r   r   r   r   4   s   r   z\\N\{(?P<name>[^}]+)\}z\\u(?P<hexval>[0-9a-fA-F]{4})z\\U(?P<hexval>[0-9a-fA-F]{8})c                 C   s>   t tdd t| }t tdd |}t tdd |}|S )a  Generate Unicode string from a string input, encoding Unicode characters.

        This is expected to work in the same way as u'<string>' would work in Python
        2.x (although it is not completely robust as it is based on a simple set of
        regexps).
        c                 S   s   t t| ddS NZhexval   unichrintgroupmr   r   r   <lambda>L       zu.<locals>.<lambda>c                 S   s   t t| ddS r   r   r#   r   r   r   r%   M   r&   c                 S   s   t | dS )Nname)unicodedatalookupr"   r#   r   r   r   r%   N   r&   )resub_U16_REunicode_U32_RE	_UNAME_RE)susr   r   r   uE   s    r2   c                  O   sV   | dd}| dd}| dd }|d kr2tj}t|? |dd | D | f d S )Nr   r   r   r   r   c                 S   s   g | ]}t |qS r   )str).0argr   r   r   
<listcomp>Y   s     zprnt.<locals>.<listcomp>)r	   sysstdoutr   joinr   r   r   r   r   S   s    c                   @   s   e Zd ZdZdd ZdS )r   r   c                 C   s   t | dS )Nzutf-8)r-   encoder   r   r   r   r   ]   s    r   Nr   r   r   r   r   r   [   s    r   -~+*0/;xX%c                 C   s   | dkrdS d}g }| D ]}t |}|dkr||dk r||dkrR|d || q|dkrp|d || q|| qd}|d	kr|d
 |d|  q|d |d|  qdd| d }|rd| d S |S dS )zCreate a representation of a Unicode string that can be used in both
    Python 2 and Python 3k, allowing for use of the u() functionNNoneF       '\Ti  z\uz%04xz\Uz%08xr;   zu())ordappendr9   )r0   Zseen_unicoderesultsccZccnresultr   r   r   rpro   s0    



rQ   c                 C   s   | dkrdS t | S dS )z:Force the argument to be a Unicode string, preserving NoneN)unicod)r0   r   r   r   force_unicode   s    rS   c                   @   s$   e Zd ZdZdZdd Zdd ZdS )ImmutableMixinz3Mixin class to make objects of subclasses immutableFc                 C   s*   | j s|dkrt| || ntdd S )N_mutableCan't modify immutable instance)rU   object__setattr__	TypeError)r   r'   valuer   r   r   rX      s    zImmutableMixin.__setattr__c                 C   s    | j rt| | ntdd S )NrV   )rU   rW   __delattr__rY   )r   r'   r   r   r   r[      s    zImmutableMixin.__delattr__N)r   r   r   r   rU   rX   r[   r   r   r   r   rT      s   rT   c                    s    fdd}|S )zBDecorator for methods that are allowed to modify immutable objectsc                    s.   | j }d| _ z | f||W S || _ X d S )NT)rU   )r   Z__argsZ__kwargsZold_mutablefuncr   r   wrapper   s
    z mutating_method.<locals>.wrapperr   )r]   r^   r   r\   r   mutating_method   s    r_   __main__))r   r7   version_infobuiltins__dict__r
   r3   rR   r2   r!   to_longr   rW   r   r-   r(   r*   compiler/   r,   r.   longZU_EMPTY_STRINGZU_SPACEZU_DASHZU_TILDEZU_PLUSZU_STARZU_ZEROZU_SLASHZU_SEMICOLONZ	U_X_LOWERZ	U_X_UPPERZ	U_PERCENTrQ   rS   rT   r_   r   doctesttestmodr   r   r   r   <module>   sL   "




!
