
    Th6                     B   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nSe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'jP                          yy) 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                      |j                  dd      }|j                  dd      }|j                  dd       }t        | i |||d y )Nsep end
file)r   r   r
   )getprint3)argskwargsr   r   r
   s        Q/opt/server/standalone/crm/venv/lib/python3.12/site-packages/phonenumbers/util.pyprntr   .   sF    jj$jj%zz&$'?C>?    c                       e Zd ZdZd Zy)UnicodeMixinEMixin class to define a __str__ method in terms of __unicode__ methodc                 "    | j                         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	&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                 J    t        t        | j                  d      d            S Nhexval   unichrintgroupms    r   <lambda>zu.<locals>.<lambda>L       vc!''(2CR.H'I r   c                 J    t        t        | j                  d      d            S r"   r%   r)   s    r   r+   zu.<locals>.<lambda>M   r,   r   c                 J    t        j                  | j                  d            S )Nname)unicodedatalookupr(   r)   s    r   r+   zu.<locals>.<lambda>N   s    ););AGGFO)L r   )resub_U16_REunicode_U32_RE	_UNAME_RE)suss     r   ur:   E   sG     VVGI7ST:VVVGI2NVVILbQ	r   c            	         |j                  dd      }|j                  dd      }|j                  dd       }|t        j                  }t        |z	  |j	                  | D cg c]  }t        |       c}      |z   f y c c}w )Nr   r   r   r	   r
   )r   sysstdoutr   joinstr)r   r   r   r   r
   args         r   r   r   S   sl    jj$jj%zz&$'<::DsxxT :cS :;cAB :s    A>
c                       e Zd ZdZd Zy)r   r   c                 6    t        |       j                  d      S )Nzutf-8)r5   encoder   s    r   r   zUnicodeMixin.__str__]   s    4=''00r   Nr   r   r   r   r   r   [   s
    S	1r    r   -~+*0/;xX%c                    | yd}g }| D ]  }t        |      }|dk\  rg|dk  rb|dk(  r#|j                  d       |j                  |       @|dk(  r#|j                  d       |j                  |       h|j                  |       zd}|dk  r&|j                  d	       |j                  d
|z         |j                  d       |j                  d|z          ddj                  |      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() functionNoneF       '\Ti  z\uz%04xz\Uz%08xrD   zu())ordappendr>   )r8   seen_unicoderesultsccccnresults         r   rprr]   o   s     	yLG -"g"9sSyt$r"tt$r"r"Lf}u%v|,u%v|,%-& 2777##c)Ff}s""r   c                     | yt        |       S )z:Force the argument to be a Unicode string, preserving NoneN)unicod)r8   s    r   force_unicoder`      s    yayr   c                        e Zd ZdZdZd Zd Zy)ImmutableMixinz3Mixin class to make objects of subclasses immutableFc                 j    | j                   s|dk(  rt        j                  | ||       y t        d      )N_mutableCan't modify immutable instance)rd   object__setattr__	TypeError)r   r/   values      r   rg   zImmutableMixin.__setattr__   s.    ==DJ.tT51=>>r   c                 ^    | j                   rt        j                  | |       y t        d      )Nre   )rd   rf   __delattr__rh   )r   r/   s     r   rk   zImmutableMixin.__delattr__   s%    ==tT*=>>r   N)r   r   r   r   rd   rg   rk   r   r   r   rb   rb      s    =H??r   rb   c                       fd}|S )zBDecorator for methods that are allowed to modify immutable objectsc                 j    | j                   }d| _         	  | g|i ||| _         S # || _         w xY w)NT)rd   )r   __args__kwargsold_mutablefuncs       r   wrapperz mutating_method.<locals>.wrapper   s9    mm	(2v22'DMKDMs   ) 	2r   )rq   rr   s   ` r   mutating_methodrs      s    ( Nr   __main__))r   r<   version_infobuiltins__dict__r   r?   r_   r:   r'   to_longr   rf   r   r5   r0   r2   compiler7   r4   r6   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_PERCENTr]   r`   rb   rs   r   doctesttestmodr   r   r   <module>r      sZ  !D  vw'FFAG@&v & F

45Ibjj9:Gbjj9:G
 GC1v 1 
+	
+			
+Sk3K	3K	3K	B?V ?"
 zGOO r   