
    Eqg6                        d Z ddlZej        dk    r)ddlZej        d         ZeZeZe	Z
d Z G d de          ZnPeZddlZddlZ ej        d          Z ej        d	          Z ej        d
          Zd ZeZ
d Z G 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 Z"d Z# G d de          Z$d Z%e&dk    rddl'Z' e'j(                     dS 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                      |                     dd          }|                     dd          }|                     dd           }t          | i |||d d S )Nsep end
file)r   r   r
   )getprint3argskwargsr   r   r
   s        C/var/www/html/env/lib/python3.11/site-packages/phonenumbers/util.pyprntr   .   s^    jj$$jj%%zz&$''?C>>?????    c                       e Zd ZdZd ZdS )UnicodeMixinEMixin class to define a __str__ method in terms of __unicode__ methodc                 *    |                                  S )N)__unicode__selfs    r   __str__zUnicodeMixin.__str__6   s    ##%%%r   N__name__
__module____qualname____doc__r    r   r   r   r   4   s)        SS	& 	& 	& 	& 	&r   r   z\\N\{(?P<name>[^}]+)\}z\\u(?P<hexval>[0-9a-fA-F]{4})z\\U(?P<hexval>[0-9a-fA-F]{8})c                     t          j        t          d t          |                     }t          j        t          d |          }t          j        t
          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                 b    t          t          |                     d          d                    S Nhexval   unichrintgroupms    r   <lambda>zu.<locals>.<lambda>L   $    vc!''(2C2CR.H.H'I'I r   c                 b    t          t          |                     d          d                    S r#   r&   r*   s    r   r,   zu.<locals>.<lambda>M   r-   r   c                 P    t          j        |                     d                    S )Nname)unicodedatalookupr)   r*   s    r   r,   zu.<locals>.<lambda>N   s    );AGGFOO)L)L r   )resub_U16_REunicode_U32_RE	_UNAME_RE)suss     r   ur;   E   sU     VGII7ST::VVVGII2NNVILLbQQ	r   c                      |                     dd          }|                     dd          }|                     dd           }|t          j        }t          |z	  |                    d | D                       |z   f d S )Nr   r   r   r	   r
   c                 ,    g | ]}t          |          S r    )str).0args     r   
<listcomp>zprnt.<locals>.<listcomp>Y   s     : : :cS : : :r   )r   sysstdoutr   joinr   s        r   r   r   S   s|    jj$$jj%%zz&$''<:Dsxx : :T : : :;;cABBBBr   c                       e Zd ZdZd ZdS )r   r   c                 F    t          |                               d          S )Nzutf-8)r6   encoder   s    r   r   zUnicodeMixin.__str__]   s    4==''000r   Nr   r    r   r   r   r   [   s)        SS	1 	1 	1 	1 	1r    r   -~+*0/;xX%c                 V   | dS d}g }| D ]}t          |          }|dk    r~|dk     rx|dk    r+|                    d           |                    |           N|dk    r+|                    d           |                    |           |                    |           d}|d	k    r.|                    d
           |                    d|z             |                    d           |                    d|z             dd                    |          z   dz   }|rd|z   dz   S |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%08xrH   zu())ordappendrD   )r9   seen_unicoderesultsccccnresults         r   rprra   o   sS    	yvLG - -"gg"99sSyyt$$$r""""tt$$$r""""r""""Lf}}u%%%v|,,,,u%%%v|,,,,2777###c)F f}s""r   c                 (    | dS t          |           S )z:Force the argument to be a Unicode string, preserving NoneN)unicod)r9   s    r   force_unicoderd      s    ytayyr   c                   "    e Zd ZdZdZd Zd ZdS )ImmutableMixinz3Mixin class to make objects of subclasses immutableFc                 v    | j         s|dk    rt                              | ||           d S t          d          )N_mutableCan't modify immutable instance)rh   object__setattr__	TypeError)r   r0   values      r   rk   zImmutableMixin.__setattr__   sC    = 	?DJ..tT511111=>>>r   c                 h    | j         rt                              | |           d S t          d          )Nri   )rh   rj   __delattr__rl   )r   r0   s     r   ro   zImmutableMixin.__delattr__   s7    = 	?tT*****=>>>r   N)r   r   r   r   rh   rk   ro   r    r   r   rf   rf      s=        ==H? ? ?? ? ? ? ?r   rf   c                       fd}|S )zBDecorator for methods that are allowed to modify immutable objectsc                 `    | j         }d| _         	  | g|R i ||| _         S # || _         w xY w)NT)rh   )r   __args__kwargsold_mutablefuncs       r   wrapperz mutating_method.<locals>.wrapper   sO    m	(42v22222'DMMKDM''''s   $ 	-r    )ru   rv   s   ` r   mutating_methodrw      s#    ( ( ( ( ( Nr   __main__))r   rB   version_infobuiltins__dict__r   r>   rc   r;   r(   to_longr   rj   r   r6   r1   r3   compiler8   r5   r7   longU_EMPTY_STRINGU_SPACEU_DASHU_TILDEU_PLUSU_STARU_ZEROU_SLASHU_SEMICOLON	U_X_LOWER	U_X_UPPER	U_PERCENTra   rd   rf   rw   r   doctesttestmodr    r   r   <module>r      s_  ! !D 


 vOOOw'FFAG@ @ @& & & & &v & & & & FIII
455Ibj9::Gbj9::G
 
 
 GC C C1 1 1 1 1v 1 1 1 
&++	
&++			
&++fSkkF3KK	F3KK	F3KK	  B  ? ? ? ? ?V ? ? ?"
 
 
 zNNNGO r   