U
    ,dj                    @   sZ  d Z ddlmZ ddlmZ ddlZddlZddl	m
Z
mZ ddlmZ ddlmZmZmZ ddlmZ ed	d
Ze
jZdZdZdZdZG dd deZdd Zedd Zeedd Zedd Zedd Z edd Z!edd Z"edd  Z#ed!d" Z$ed#d$ Z%ed%d& Z&ed'd( Z'ed)d* Z(ed+d, Z)ed-d. Z*ed/d0 Z+ed1d2 Z,ed3d4 Z-ed5d6 Z.ed7d8 Z/ed9d: Z0ed;d< Z1ed=d> Z2ed?d@ Z3edAdB Z4edCdD Z5edEdF Z6G dGdH dHeZ7ej8ddddddddde7j9e7j9e7j9e7j9e7j9dddddddddddddddddde7j9ddddddddddddddde7j:e7j;B e7j:e7j;B e7j:e7j;B e7j:e7j;B e7j:e7j;B e7j:e7j;B e7j:e7j;B e7j:e7j;B e7j:e7j;B e7j:e7j;B ddddddde7j<e7j;B e7j<e7j;B e7j<e7j;B e7j<e7j;B e7j<e7j;B e7j<e7j;B e7j<e7j<e7j<e7j<e7j<e7j<e7j<e7j<e7j<e7j<e7j<e7j<e7j<e7j<e7j<e7j<e7j<e7j<e7j<e7j<dddddde7j=e7j;B e7j=e7j;B e7j=e7j;B e7j=e7j;B e7j=e7j;B e7j=e7j;B e7j=e7j=e7j=e7j=e7j=e7j=e7j=e7j=e7j=e7j=e7j=e7j=e7j=e7j=e7j=e7j=e7j=e7j=e7j=e7j=dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddg ej>dIZ?ej8ddJdKdLdMdNdOdPdQdddRdSddTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddeddfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd ddddddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*g ej@dIZAej8ddJdKdLdMdNdOdPdQdddRdSddTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddeddfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dddddddd+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDddddddd+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd ddddddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*g ej@dIZBG dEdF dFeZCej8ddddddddddeCjDeCjEB eCjDeCjDeCjDeCjFB ddddddddddddddeCjDeCjDeCjDddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddeCjDddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddg ej>dIZGedGdH ZHedIdJ ZIedKdL ZJedMdN ZKedOdP ZLedQdR ZMedSdT ZNedUdV ZOedWdX ZPedYdZ ZQed[d\ ZRed]d^ ZSed_d` ZTdS (a  z
This module contains support functions for more advanced unicode operations.
This is not a public API and is for Numba internal use only. Most of the
functions are relatively straightforward translations of the functions with the
same name in CPython.
    )
namedtuple)IntEnumN)typescgutils)impl_ret_untracked)overload	intrinsicregister_jitable)TypingError
typerecordz%upper lower title decimal digit flags	   
          c                   @   sH   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdS )_PyUnicode_TyperecordMasks               r   @         i   i   i   i   i    i @  N)__name__
__module____qualname__
ALPHA_MASKDECIMAL_MASK
DIGIT_MASK
LOWER_MASKLINEBREAK_MASK
SPACE_MASK
TITLE_MASK
UPPER_MASKXID_START_MASKXID_CONTINUE_MASKPRINTABLE_MASKNUMERIC_MASKCASE_IGNORABLE_MASK
CASED_MASKEXTENDED_CASE_MASK r+   r+   A/tmp/pip-unpacked-wheel-eu7e0c37/numba/cpython/unicode_support.pyr   ;   s   r   c                 C   s   t dd S )Nz(Calling the Python definition is invalid)RuntimeErrorar+   r+   r,   _PyUnicode_gettyperecordM   s    r0   c                 C   sP   t |tjstddd }ttjtjtjtjtjtjgt}|t	}||fS )z~
    Provides the binding to numba_gettyperecord, returns a `typerecord`
    namedtuple of properties from the codepoint.
    zcodepoint must be an integerc              
   S   sJ  |  tj}|  t}|  tj}| }|  tj}| }	|  tj}
|
 }tj	
||||||	|	|g}tj|j|dd}tj||dd}tj||dd}tj||dd}tj||dd}tj||dd}tj||
dd}||||||g}|||d	 g|  g }|D ]}||| q| ||jt|}t| ||j|S )
NZnumba_gettyperecordnameupperlowertitledecimaldigitflagsr   )get_value_typer   void_Py_UCS4intcZ
as_pointerucharushortllvmliteirFunctionTyper   get_or_insert_functionmoduleZalloca_oncecallappendloadZ
make_tuplereturn_typetupler   )contextbuilder	signatureargsZll_void
ll_Py_UCS4ll_intcZll_intc_ptrZll_ucharZll_uchar_ptrZ	ll_ushortZll_ushort_ptrfntyfnr3   r4   r5   r6   r7   r8   byrefbufxresr+   r+   r,   detailsZ   sF    
	 z$_gettyperecord_impl.<locals>.details)

isinstancer   Integerr
   
NamedTupler<   r=   r>   r   r;   )	typingctx	codepointrU   Ztuptysigr+   r+   r,   _gettyperecord_implQ   s    % r\   c                    s@   t | tjr(ddlm   fdd}|S t | tjr<dd S dS )z
    Provides a _PyUnicode_gettyperecord binding, for convenience it will accept
    single character strings and code points.
    r   _get_code_pointc                    s2   t | dkrd}t| | d}tt|}|S )Nr   z.gettyperecord takes a single unicode characterr   )len
ValueErrorr\   r;   )r/   msg
code_pointdatar]   r+   r,   impl   s    
z gettyperecord_impl.<locals>.implc                 S   s   t t| S N)r\   r;   r.   r+   r+   r,   <lambda>       z$gettyperecord_impl.<locals>.<lambda>N)rV   r   ZUnicodeTypeZnumba.cpython.unicoder^   rW   )r/   rd   r+   r]   r,   gettyperecord_impl   s    rh   c                 C   s.   t |tjstddd }ttj}||fS )z
    Accessor function for the _PyUnicode_ExtendedCase array, binds to
    numba_get_PyUnicode_ExtendedCase which wraps the array and does the lookup
    zExpected an indexc                 S   sJ   |  t}|  tj}tj||g}tj|j	|dd}|
||d gS )NZ numba_get_PyUnicode_ExtendedCaser1   r   )r9   r;   r   r<   r?   r@   rA   r   rB   rC   rD   )rI   rJ   rK   rL   rM   rN   rO   rP   r+   r+   r,   rU      s    
 z(_PyUnicode_ExtendedCase.<locals>.details)rV   r   rW   r
   r;   r<   )rY   indexrU   r[   r+   r+   r,   _PyUnicode_ExtendedCase   s
    	
rj   c                 C   s,   t | }|jtj@ r"t|jd@ S | |j S )N  )r0   r8   r   r*   rj   r5   chctyper+   r+   r,   _PyUnicode_ToTitlecase   s    ro   c                 C   s   t | }|jtj@ dkS Nr   )r0   r8   r   r"   rl   r+   r+   r,   _PyUnicode_IsTitlecase   s    rq   c                 C   s   t | }|jtj@ dkS rp   )r0   r8   r   r$   rl   r+   r+   r,   _PyUnicode_IsXidStart   s    rr   c                 C   s   t | }|jtj@ dkS rp   )r0   r8   r   r%   rl   r+   r+   r,   _PyUnicode_IsXidContinue   s    rs   c                 C   s   t | }|jtj@ r|jS dS N)r0   r8   r   r   r6   rl   r+   r+   r,   _PyUnicode_ToDecimalDigit   s    rv   c                 C   s   t | }|jtj@ r|jS dS rt   )r0   r8   r   r   r7   rl   r+   r+   r,   _PyUnicode_ToDigit   s    rw   c                 C   s   t | }|jtj@ dkS rp   )r0   r8   r   r'   rl   r+   r+   r,   _PyUnicode_IsNumeric   s    rx   c                 C   s   t | }|jtj@ dkS rp   )r0   r8   r   r&   rl   r+   r+   r,   _PyUnicode_IsPrintable   s    ry   c                 C   s   t | }|jtj@ dkS rp   )r0   r8   r   r   rl   r+   r+   r,   _PyUnicode_IsLowercase   s    rz   c                 C   s   t | }|jtj@ dkS rp   )r0   r8   r   r#   rl   r+   r+   r,   _PyUnicode_IsUppercase   s    r{   c                 C   s   t | }|jtj@ dkS rp   )r0   r8   r   r    rl   r+   r+   r,   _PyUnicode_IsLineBreak   s    r|   c                 C   s   t d S re   NotImplementedErrorrm   r+   r+   r,   _PyUnicode_ToUppercase  s    r   c                 C   s   t d S re   r}   r   r+   r+   r,   _PyUnicode_ToLowercase  s    r   c                 C   s\   t | }|jtj@ rJ|jd@ }|jd? }t|D ]}t|| ||< q0|S | |j |d< dS Nrk      r   r   )r0   r8   r   r*   r4   rangerj   rm   rT   rn   ri   nir+   r+   r,   _PyUnicode_ToLowerFull  s    

r   c                 C   s\   t | }|jtj@ rJ|jd@ }|jd? }t|D ]}t|| ||< q0|S | |j |d< dS r   )r0   r8   r   r*   r5   r   rj   r   r+   r+   r,   _PyUnicode_ToTitleFull  s    

r   c                 C   s\   t | }|jtj@ rJ|jd@ }|jd? }t|D ]}t|| ||< q0|S | |j |d< dS r   )r0   r8   r   r*   r3   r   rj   r   r+   r+   r,   _PyUnicode_ToUpperFull-  s    

r   c                 C   st   t | }tj}|j|@ rj|jd? d@ rj|jd@ |jd?  }|jd? d@ }t|D ]}t|| ||< qP|S t| |S )N      rk   r   )r0   r   r*   r8   r4   r   rj   r   )rm   rT   rn   Zextended_case_maskri   r   r   r+   r+   r,   _PyUnicode_ToFoldedFull<  s    r   c                 C   s   t | }|jtj@ dkS rp   )r0   r8   r   r)   rl   r+   r+   r,   _PyUnicode_IsCasedJ  s    r   c                 C   s   t | }|jtj@ dkS rp   )r0   r8   r   r(   rl   r+   r+   r,   _PyUnicode_IsCaseIgnorableQ  s    r   c                 C   s   t | dk rdS dS Nr   r   )rw   r   r+   r+   r,   _PyUnicode_IsDigitX  s    r   c                 C   s   t | dk rdS dS r   )rv   r   r+   r+   r,   _PyUnicode_IsDecimalDigit`  s    r   c                 C   s   t | }|jtj@ dkS rp   )r0   r8   r   r!   rl   r+   r+   r,   _PyUnicode_IsSpaceh  s    r   c                 C   s   t | }|jtj@ dkS rp   )r0   r8   r   r   rl   r+   r+   r,   _PyUnicode_IsAlphan  s    r   c                   @   s(   e Zd ZdZdZdZdZdZdZdZ	dS )	_PY_CTFr   r      r   r   r   r   N)
r   r   r   LOWERUPPERALPHADIGITALNUMSPACEXDIGITr+   r+   r+   r,   r   }  s   r   )Zdtyper   r   r   r         r   r               r            r            r                        !   "   #   $   %   &   '   (   )   *   +   ,   -   .   /   0   1   2   3   4   5   6   7   8   9   :   ;   <   =   >   ?   r   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o   p   q   r   s   t   u   v   w   x   y   z   [   \   ]   ^   _   `   {   |   }   ~      r                                                                                                                                                                                                                                                                                                                                                                                                A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   c                   @   s   e Zd ZdZdZdZdS )
_PY_CTF_LBr   r   r   N)r   r   r   
LINE_BREAK	LINE_FEEDCARRIAGE_RETURNr+   r+   r+   r,   r  a  s   r  c                 C   s   t | t d@ S )zk
    Equivalent to the CPython macro `Py_CHARMASK()`, masks off all but the
    lowest 256 bits of ch.
    rs  )r   uint8r   r+   r+   r,   _Py_CHARMASK  s    r  c                 C   s   t t|  S )zw
    Equivalent to the CPython macro `Py_TOUPPER()` converts an ASCII range
    code point to the upper equivalent
    )_Py_ctype_toupperr  r   r+   r+   r,   _Py_TOUPPER  s    r  c                 C   s   t t|  S )zw
    Equivalent to the CPython macro `Py_TOLOWER()` converts an ASCII range
    code point to the lower equivalent
    )_Py_ctype_tolowerr  r   r+   r+   r,   _Py_TOLOWER  s    r  c                 C   s   t t|  tj@ S )z8
    Equivalent to the CPython macro `Py_ISLOWER()`
    )_Py_ctype_tabler  r   r   r   r+   r+   r,   _Py_ISLOWER  s    r  c                 C   s   t t|  tj@ S )z8
    Equivalent to the CPython macro `Py_ISUPPER()`
    )r  r  r   r   r   r+   r+   r,   _Py_ISUPPER  s    r  c                 C   s   t t|  tj@ S )z8
    Equivalent to the CPython macro `Py_ISALPHA()`
    )r  r  r   r   r   r+   r+   r,   _Py_ISALPHA  s    r  c                 C   s   t t|  tj@ S )z8
    Equivalent to the CPython macro `Py_ISDIGIT()`
    )r  r  r   r   r   r+   r+   r,   _Py_ISDIGIT  s    r  c                 C   s   t t|  tj@ S )z9
    Equivalent to the CPython macro `Py_ISXDIGIT()`
    )r  r  r   r   r   r+   r+   r,   _Py_ISXDIGIT  s    r  c                 C   s   t t|  tj@ S )z8
    Equivalent to the CPython macro `Py_ISALNUM()`
    )r  r  r   r   r   r+   r+   r,   _Py_ISALNUM  s    r  c                 C   s   t t|  tj@ S )z8
    Equivalent to the CPython macro `Py_ISSPACE()`
    )r  r  r   r   r   r+   r+   r,   _Py_ISSPACE  s    r  c                 C   s   t t|  tj@ S )z&Check if character is ASCII line break)_Py_ctype_islinebreakr  r  r  r   r+   r+   r,   _Py_ISLINEBREAK  s    r  c                 C   s   t t|  tj@ S )z#Check if character is line feed `
`)r  r  r  r  r   r+   r+   r,   _Py_ISLINEFEED  s    r  c                 C   s   t t|  tj@ S )z)Check if character is carriage return ``)r  r  r  r  r   r+   r+   r,   _Py_ISCARRIAGERETURN  s    r  )U__doc__collectionsr   enumr   Zllvmlite.irr?   ZnumpynpZ
numba.corer   r   Znumba.core.imputilsr   Znumba.core.extendingr   r   r	   Znumba.core.errorsr
   r   Zuint32r;   Z_Py_TABZ_Py_LINEFEEDZ_Py_CARRIAGE_RETURNZ	_Py_SPACEr   r0   r\   rh   rj   ro   rq   rr   rs   rv   rw   rx   ry   rz   r{   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   arrayr   r   r   r   r   r<   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r+   r+   r+   r,   <module>   s  
3














































                                                                                                                          
                                                                                                                                                                                                                                  !&                                                                                                                                                                                                                                !$         

                                                                                                                                                                                                                               


						