o
    i6                     @   sL  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d ZG dd deZn+e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rddl'Z'e'(  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                  O   s>   | dd}| dd}| dd }t| i |||d d S )Nsep end
file)r   r   r   )getprint3argskwargsr   r   r    r   q/var/www/snowflake_co_dev_github/snow_flake_back_end_deploy/env/lib/python3.10/site-packages/phonenumbers/util.pyprnt.   s   r   c                   @      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       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      t t| ddS Nhexval   unichrintgroupmr   r   r   <lambda>L       zu.<locals>.<lambda>c                 S   r   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   s    )resub_U16_REunicode_U32_RE	_UNAME_RE)susr   r   r   uE   s   r6   c                  O   sV   | dd}| dd}| dd }|d u rt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   r*   zprnt.<locals>.<listcomp>)r	   sysstdoutr   joinr   r   r   r   r   S   s   $c                   @   r   )r   r   c                 C   s   t | dS )Nzutf-8)r1   encoder   r   r   r   r   ]   s   r   Nr   r   r   r   r   r   [   r    r   -~+*0/;xX%c                 C   s   | du rdS d}g }| D ]Q}t |}|dkr>|dk r>|dkr)|d || q|dkr8|d || q|| qd}|d	krQ|d
 |d|  q|d |d|  qdd| d }|rod| d 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%08xr?   zu())ordappendr=   )r4   seen_unicoderesultsccccnresultr   r   r   rpro   s0   



rW   c                 C   s   | du rdS t | S )z:Force the argument to be a Unicode string, preserving NoneN)unicod)r4   r   r   r   force_unicode   s   rY   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| || d S td)N_mutableCan't modify immutable instance)r[   object__setattr__	TypeError)r   r+   valuer   r   r   r^      s   zImmutableMixin.__setattr__c                 C   s   | j rt| | d S td)Nr\   )r[   r]   __delattr__r_   )r   r+   r   r   r   ra      s   zImmutableMixin.__delattr__N)r   r   r   r   r[   r^   ra   r   r   r   r   rZ      s
    rZ   c                    s    fdd}|S )zBDecorator for methods that are allowed to modify immutable objectsc                    s4   | j }d| _ z | g|R i |W || _ S || _ w )NT)r[   )r   __args__kwargsold_mutablefuncr   r   wrapper   s
   z mutating_method.<locals>.wrapperr   )rf   rg   r   re   r   mutating_method   s   rh   __main__))r   r;   version_infobuiltins__dict__r
   r7   rX   r6   r%   to_longr   r]   r   r1   r,   r.   compiler3   r0   r2   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_PERCENTrW   rY   rZ   rh   r   doctesttestmodr   r   r   r   <module>   sP    "




!