o
    ¯bt  ã                   @   sâ  d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZ dZeed	d
dd ƒdedƒ G dd„ deƒZG dd„ deƒZe	eƒG dd„ dƒƒZe	eƒG dd„ dƒƒZe	eƒG dd„ dƒƒZe	eƒG dd„ dƒƒZG dd„ dƒZG dd„ dƒZee jƒZee jƒZee jƒZee jƒZee j ƒZ!ee j"ƒZ#ee j$ƒZ%ee j&ƒZ'ee j(ƒZ)ee j*ƒZ+ee j,ƒZ-ee j.ƒZ/ee j0ƒZ1ee/e1geeeee!e#e%e'e)e+e-eg d¢ƒgd�Z2ee/geeee!e#e%e'e)e+e-g
d�Z3eƒ Z4dS ) é    N)Úidna)Úchain)Ú	ucd_3_2_0)Ú	InterfaceÚimplementer)ÚVersion)ÚdeprecatedModuleAttributeFÚTwistedé   é   zcrippled is always FalseÚcrippledc                   @   ó   e Zd ZdZdd„ ZdS )ÚILookupTablez1
    Interface for character lookup classes.
    c                 C   ó   dS )z<
        Return whether character is in this table.
        N© ©Úcr   r   úP/usr/lib/python3/dist-packages/twisted/words/protocols/jabber/xmpp_stringprep.pyÚlookup   ó    zILookupTable.lookupN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      ó    r   c                   @   r   )ÚIMappingTablez2
    Interface for character mapping classes.
    c                 C   r   )z/
        Return mapping for character.
        Nr   r   r   r   r   Úmap)   r   zIMappingTable.mapN)r   r   r   r   r   r   r   r   r   r   $   r   r   c                   @   ó   e Zd Zdd„ ZdS )ÚLookupTableFromFunctionc                 C   ó
   || _ d S ©N)r   ©ÚselfÚin_table_functionr   r   r   Ú__init__1   ó   
z LookupTableFromFunction.__init__N©r   r   r   r$   r   r   r   r   r   /   ó    r   c                   @   ó   e Zd Zdd„ Zdd„ ZdS )ÚLookupTablec                 C   r   r    ©Ú_table)r"   Útabler   r   r   r$   7   r%   zLookupTable.__init__c                 C   s
   || j v S r    r*   ©r"   r   r   r   r   r   :   r%   zLookupTable.lookupN)r   r   r   r$   r   r   r   r   r   r)   5   ó    r)   c                   @   r   )ÚMappingTableFromFunctionc                 C   r   r    )r   )r"   Úmap_table_functionr   r   r   r$   @   r%   z!MappingTableFromFunction.__init__Nr&   r   r   r   r   r/   >   r'   r/   c                   @   r(   )ÚEmptyMappingTablec                 C   r   r    ©Ú_in_table_functionr!   r   r   r   r$   F   r%   zEmptyMappingTable.__init__c                 C   s   |   |¡rd S |S r    r2   r-   r   r   r   r   I   s   
zEmptyMappingTable.mapN)r   r   r   r$   r   r   r   r   r   r1   D   r.   r1   c                   @   sH   e Zd Zg dg ddfdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ ZdS )ÚProfileTc                 C   s"   || _ || _|| _|| _|| _d S r    )ÚmappingsÚ	normalizeÚprohibitedsÚdo_check_unassignedsÚdo_check_bidi)r"   r5   r6   r7   Úcheck_unassignedsÚ
check_bidir   r   r   r$   Q   s
   
zProfile.__init__c                 C   sJ   |   |¡}| jrt d|¡}|  |¡ | jr|  |¡ | jr#|  |¡ |S )NÚNFKC)r   r6   ÚunicodedataÚcheck_prohibitedsr8   r:   r9   Úcheck_bidirectionals)r"   ÚstringÚresultr   r   r   Úprepare_   s   



zProfile.preparec                 C   sP   g }|D ]}|}| j D ]}| |¡}||kr nq|d ur"| |¡ qd |¡S )NÚ )r5   r   ÚappendÚjoin)r"   r@   rA   r   Úresult_cÚmappingr   r   r   r   j   s   

ÿ
€
zProfile.mapc                 C   s4   |D ]}| j D ]}| |¡rtdt|ƒ ƒ‚qqd S ©NzInvalid character %s)r7   r   ÚUnicodeErrorÚrepr)r"   r@   r   r,   r   r   r   r>   z   s   

ÿÿÿzProfile.check_prohibitedsc                 C   s(   |D ]}t  |¡rtdt|ƒ ƒ‚qd S )NzUnassigned code point %s)Ú
stringprepÚin_table_a1rI   rJ   ©r"   r@   r   r   r   r   r:   €   ó
   
ÿÿzProfile.check_unassignedsc                 C   sn   d}d}|D ]}t  |¡rd}t  |¡rd}q|r|rtdƒ‚|r3t  |d ¡r/t  |d ¡s5tdƒ‚d S d S )NFTzViolation of BIDI Requirement 2r   éÿÿÿÿzViolation of BIDI Requirement 3)rK   Úin_table_d1Úin_table_d2rI   )r"   r@   Ú
found_LCatÚfound_RandALCatr   r   r   r   r?   …   s"   

€ÿÿýzProfile.check_bidirectionalsN)	r   r   r   r$   rB   r   r>   r:   r?   r   r   r   r   r4   P   s    
úr4   c                	   @   s`   e Zd ZdZdd„ eeddƒeddƒedd	ƒed
dƒeddƒƒD ƒZdd„ Zdd„ Zdd„ Z	dS )ÚNamePrepa²  Implements preparation of internationalized domain names.

    This class implements preparing internationalized domain names using the
    rules defined in RFC 3491, section 4 (Conversion operations).

    We do not perform step 4 since we deal with unicode representations of
    domain names and do not convert from or to ASCII representations using
    punycode encoding. When such a conversion is needed, the C{idna} standard
    library provides the C{ToUnicode()} and C{ToASCII()} functions. Note that
    C{idna} itself assumes UseSTD3ASCIIRules to be false.

    The following steps are performed by C{prepare()}:

      - Split the domain name in labels at the dots (RFC 3490, 3.1)
      - Apply nameprep proper on each label (RFC 3491)
      - Enforce the restrictions on ASCII characters in host names by
        assuming STD3ASCIIRules to be true. (STD 3)
      - Rejoin the labels using the label separator U+002E (full stop).

    c                 C   s   g | ]}t |ƒ‘qS r   )Úchr)Ú.0Únr   r   r   Ú
<listcomp>¯   s    ÿÿzNamePrep.<listcomp>r   é-   é.   é0   é:   éA   é[   éa   é{   é€   c                 C   s\   g }t j |¡}|rt|d ƒdkrd}|d= nd}|D ]
}| |  |¡¡ qd |¡| S )NrO   r   Ú.rC   )r   ÚdotsÚsplitÚlenrD   ÚnamepreprE   )r"   r@   rA   ÚlabelsÚtrailing_dotÚlabelr   r   r   rB   º   s   zNamePrep.preparec                 C   s(   |D ]}|| j v rtdt|ƒ ƒ‚qd S rH   )r7   rI   rJ   rM   r   r   r   r>   Ê   rN   zNamePrep.check_prohibitedsc                 C   s@   t  |¡}|  |¡ |d dkrtdƒ‚|d dkrtdƒ‚|S )Nr   ú-zInvalid leading hyphen-minusrO   zInvalid trailing hyphen-minus)r   rf   r>   rI   )r"   ri   r   r   r   rf   Ï   s   

zNamePrep.nameprepN)
r   r   r   r   r   Úranger7   rB   r>   rf   r   r   r   r   rT   ˜   s    ûþrT   )ú"ú&ú'ú/ú:ú<ú>ú@)r5   r7   )5rK   Ú	encodingsr   Ú	itertoolsr   r=   r   Úzope.interfacer   r   Úincrementalr   Útwisted.python.deprecater   r   r   r   r   r   r)   r/   r1   r4   rT   Úin_table_c11ÚC_11Úin_table_c12ÚC_12Úin_table_c21ÚC_21Úin_table_c22ÚC_22Úin_table_c3ÚC_3Úin_table_c4ÚC_4Úin_table_c5ÚC_5Úin_table_c6ÚC_6Úin_table_c7ÚC_7Úin_table_c8ÚC_8Úin_table_c9ÚC_9Úin_table_b1ÚB_1Úmap_table_b2ÚB_2ÚnodeprepÚresourcepreprf   r   r   r   r   Ú<module>   st   ÿH
A












ôþÿü
