o
    i;Z                    @   sX  d dl 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mZmZmZmZmZmZmZ d dlmZmZmZmZmZmZ d dlmZmZ d dlmZm Z  d dl!m"Z"m#Z#m$Z$m%Z% d d	l&m'Z' d d
l(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZO d dlPmQZQ dZRejSjTZUeejVG dd de
jZWeejVdd eejVdd eejVdd eejVdd eejVdd eejXG dd deZYdd ZZd d! Z[eej\ej]d"d# Z^eej]d$d% Z_eejVd&d' Z`eejVd(d) Zad*d+ Zbed,d- Zced.d/ Zded0d1 Zeed2d3 Zfed>d4d5Zged6d7d8d9 Zhd:d; Zied<d= Zjed>d? Zked@dA Zled6d7dBdC ZmedDdE ZnedFdG ZoedHdI Zped6d7dJdK ZqedLdM ZredNdO ZseetdPdQ ZueejvdRdS ZweejxdTdU ZyeejzdVdW Z{eej|dXdY Z}eej~dZd[ Zeejd\d] Zeejd^d_ Zd`da Zdbdc Zeddde Zedfdg Zedhdi Zedjdk Zdldm ZeeeZeeeZeejVdnd?dodpZeejVdqd?drdsZeejVdtd?dudvZeejVdwd?dxdyZeejVdzd{d| ZeejVd}d?d~dZeejVddd Zedd ZeejVdd?ddZeejVdd?ddZeejVdd@ddZeejVddAddZdd Zeee8Zeee9ZeejVddAddZeejVddBddZdd ZeejVded6 eejVded dd ZeeeAZeee@ZeejVddCddZedd ZeejVddd ZeejVddd Zedd Zedd Zdd Zdd ZeejVddDddZeejVddDddZeejVddDddZedEddZedd ZeddĄ ZeddƄ Zed6d7ddȄ Zeddʄ Zeejdd̄ Zeejeejdd΄ ZeddЄ Zeejdd҄ ZeejddԄ ZeejVdՃdFddׄZddل ZeejVdڃeeMeK edd܄ ZeejVd݃ee2e dd߄ Zedd܄ ZeeeEeFeZeee?e>eDZeejVddd ZeejVddd ZeejVddd ZeejVddd ZeejVddd ZȐdEddZeejVdee8 eejVdeeL eejVdeeN eejVdeeO eejVdee7d6 dd Zedd Zedd Zdd Zeed6ZeedZdd  Zeee/Zeee0ZeejVddd ZeejVddd Zedd Zed	d
 ZeejVddd Zedd Zedd ZeejVddd Zedd Zedd ZeejVddd Zedd Zedd ZeejVd d!d" Zeed#d$ Zed%d& Zd'eR Zed(d) Zeed*d+ ZeejVd,d-d. ZeejVd/d0d1 Zeejd,d2d3 Zeejd/d4d5 Zeejd/eejd,d6d7 Zed8ejVd9d: Zed;ejXeejd<d= ZdS (G      N)IntTypeConstant)is_nonelike)
modelsregister_modelmake_attribute_wrapperunboxboxNativeValueoverloadoverload_method	intrinsicregister_jitable)lower_constant
lower_castlower_builtiniternext_implimpl_ret_new_refRefType)register_defaultStructModel)typescgutils)PY_UNICODE_1BYTE_KINDPY_UNICODE_2BYTE_KINDPY_UNICODE_4BYTE_KINDPY_UNICODE_WCHAR_KIND)	c_helpers)
_Py_hash_t)memcpy_region)TypingError)!_Py_TOUPPER_Py_TOLOWER_Py_UCS4_Py_ISALNUM_PyUnicode_ToUpperFull_PyUnicode_ToLowerFull_PyUnicode_ToFoldedFull_PyUnicode_ToTitleFull_PyUnicode_IsPrintable_PyUnicode_IsSpace_Py_ISSPACE_PyUnicode_IsXidStart_PyUnicode_IsXidContinue_PyUnicode_IsCased_PyUnicode_IsCaseIgnorable_PyUnicode_IsUppercase_PyUnicode_IsLowercase_PyUnicode_IsLineBreak_Py_ISLINEBREAK_Py_ISLINEFEED_Py_ISCARRIAGERETURN_PyUnicode_IsTitlecase_Py_ISLOWER_Py_ISUPPER_Py_TAB_Py_LINEFEED_Py_CARRIAGE_RETURN	_Py_SPACE_PyUnicode_IsAlpha_PyUnicode_IsNumeric_Py_ISALPHA_PyUnicode_IsDigit_PyUnicode_IsDecimalDigit)slicing c                   @   s   e Zd Zdd ZdS )UnicodeModelc              	   C   sV   dt jfdt jfdt jfdt jfdtfdt t jfdt jfg}tj	
| ||| d S )Ndatalengthkindis_asciihashmeminfoparent)r   voidptrintpint32uint32r   ZMemInfoPointerZpyobjectr   r   __init__selfZdmmZfe_typemembers rT   d/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/cpython/unicode.pyrP   O   s   
zUnicodeModel.__init__N)__name__
__module____qualname__rP   rT   rT   rT   rU   rD   M   s    rD   rE   _datarF   _lengthrG   _kindrH   	_is_asciirI   _hashc                       s   e Zd Z fddZ  ZS )UnicodeIteratorModelc                    s2   dt t jfd|jfg}tt| ||| d S )NindexrE   )r   ZEphemeralPointeruintprE   superr^   rP   rQ   	__class__rT   rU   rP   f   s   zUnicodeIteratorModel.__init__)rV   rW   rX   rP   __classcell__rT   rT   rb   rU   r^   d   s    r^   c                 C   s   ddl m}m}m}m}m}m}m}m}m	}	 t
d }
|||||||||||}||
}| }| }| }| }|| |	||	||	||	|}|du rStd|j}|j}|j}|d t| }|| |}t|||||jfS )ztGet string data from a python string for use at compile-time to embed
    the string data into the LLVM module.
    r   )		CFUNCTYPEc_void_pc_intc_uint	c_ssize_tc_ubyte	py_objectPOINTERbyrefZextract_unicodeNz1cannot extract unicode data from the given string   )ctypesre   rf   rg   rh   ri   rj   rk   rl   rm   r   
ValueErrorvalue_kind_to_byte_widthZfrom_addressbytes)objre   rf   rg   rh   ri   rj   rk   rl   rm   Zextract_unicode_fnprotofnrF   rG   rH   hashvrE   nbytesoutrT   rT   rU   compile_time_get_string_datan   s&   , rz   c                 C   sz   t |\}}}}}|j}	| |	|}
t|| |}|
|_|j||_|j||_|j	||_	|j
d|_
| S )zf
    Get string data by `compile_time_get_string_data()` and return a
    unicode_type LLVM value
    )rz   moduleZinsert_const_bytesr   create_struct_proxyrE   rF   typerG   rH   rI   	_getvalue)contextbuildertypZliteral_stringZ	databytesrF   rG   rH   rw   modgvuni_strrT   rT   rU   make_string_from_constant   s   r   c                 C   s   t | |||jS N)r   Zliteral_value)r   r   ZfromtyZtotyvalrT   rT   rU   cast_from_literal   s   
r   c                 C   s   t | |||S r   )r   )r   r   r   ZpyvalrT   rT   rU   constant_unicode      r   c                 C   s   |j |\}}}}}}t| |j|j}	||	_||	_||	_||	_	||	_
|j |||	_||	_t|j|j  }
t|	 |
dS )zE
    Convert a unicode str object to a native unicode structure.
    )is_error)pyapiZstring_as_string_size_and_kindr   r}   r   r   rE   rF   rG   rH   rI   Znrt_meminfo_new_from_pyobjectrJ   rK   Zis_not_nullZerr_occurredr
   r   )r   rt   cokrE   rF   rG   rH   rw   r   r   rT   rT   rU   unbox_unicode_str   s   
r   c                 C   sR   t | |j|j|d}|j|j|j|j}|j	| |jj
|j| | |S )z@
    Convert a native unicode structure to a unicode string
    rq   )r   r}   r   r   r   Zstring_from_kind_and_datarG   rE   rF   Zobject_hashnrtZdecref)r   r   r   r   resrT   rT   rU   box_unicode_str   s   r   c                        fdd}|S )Nc                    s@   |\}}| |t  }||||g}||tdS N    )bitcastr   
as_pointerloadgepZzext)r   r   	signatureargsrE   idxptrchbitsizerT   rU   codegen   s   z#make_deref_codegen.<locals>.codegenrT   r   r   rT   r   rU   make_deref_codegen   s   r   c                 C      t t jt j}|tdfS N   r   rO   rL   rM   r   	typingctxrE   offsetsigrT   rT   rU   deref_uint8      r   c                 C   r   N   r   r   rT   rT   rU   deref_uint16   r   r   c                 C   r   r   r   r   rT   rT   rU   deref_uint32   r   r   c                 C   s(   dd }t t jt jt jt j}||fS )zmake empty string with data buffer of size alloc_bytes.

    Must set length and kind values for string after it is returned
    c              	   S   s   |\}}}}t tj}|| |}	||||t|jd}
| j	||
|	_
||	_||	_||	_| td|	_| j||	j
|	_t |	jj|	_|	 S )Nrn   r{   )r   r}   r   unicode_typemuladdr   r~   r   Zmeminfo_allocrJ   rG   rH   rF   get_constantr   rI   Zmeminfo_datarE   get_null_valuerK   r   )r   r   r   r   Zkind_valZchar_bytes_valZ
length_valZis_ascii_valZuni_str_ctorr   Z
nbytes_valrT   rT   rU   details   s    

z_malloc_string.<locals>.details)r   r   rN   rM   rO   )r   rG   Z
char_bytesrF   rH   r   r   rT   rT   rU   _malloc_string   s   r   c                 C   s,   t | }t| |||}t||td |S Nr   )rr   r   _set_code_pointnprO   )rG   rF   rH   
char_widthsrT   rT   rU   _empty_string  s   r   F)Z_nrtc                 C   sF   | j tkrt| j|S | j tkrt| j|S | j tkr!t| j|S dS r   )r[   r   r   rY   r   r   r   r   )airT   rT   rU   _get_code_point  s   


r   c                    r   )Nc                    sT   |\}}} dk r| |t }||t  }|||||g |  S r   )truncr   r   r   storer   Zget_dummy_value)r   r   r   r   rE   r   r   r   r   rT   rU   r   .  s   
z!make_set_codegen.<locals>.codegenrT   r   rT   r   rU   make_set_codegen-  s   r   c                 C       t t jt jt j}|tdfS r   r   voidrL   Zint64rO   r   r   rE   r   r   r   rT   rT   rU   	set_uint89     r   c                 C   r   r   r   r   rT   rT   rU   
set_uint16?  r   r   c                 C   r   r   r   r   rT   rT   rU   
set_uint32E  r   r   c                 C   s\   | j tkrt| j|| d S | j tkrt| j|| d S | j tkr*t| j|| d S td)Nz4Unexpected unicode representation in _set_code_point)	r[   r   r   rY   r   r   r   r   AssertionError)r   r   r   rT   rT   rU   r   K  s   


r   c                 C   sP   | t ks|t krtd| tkr|S | tkr|tkr|S | S | tkr$| S td)N!PY_UNICODE_WCHAR_KIND unsupportedz/Unexpected unicode representation in _pick_kind)r   r   r   r   r   )Zkind1Zkind2rT   rT   rU   
_pick_kind^  s   r   c                 C   s$   | dkr|dkrt dS t dS Nrn   r   )r   rO   )Z	is_ascii1Z	is_ascii2rT   rT   rU   _pick_asciip  s   

r   c                 C   s<   | t krdS | tkrdS | tkrdS | tkrtdtd)Nrn         r   z'Unexpected unicode encoding encountered)r   r   r   r   r   )rG   rT   rT   rU   rr   w  s   rr   c                 C   sz   |dkrdS || | j krdS || |j krdS t|D ]}t| || }t||| }||k r3 dS ||kr: dS qdS )Nr   r{   rn   )rZ   ranger   )r   Za_offsetbZb_offsetnr   Za_chrZb_chrrT   rT   rU   _cmp_region  s   r   c                 C   s4   | dk rt S | dk rtS d}| |krd}t|tS )zK
    Compute the minimum unicode kind needed to hold a given codepoint
       i   rC   z;Invalid codepoint. Found value greater than Unicode maximum)r   r   rp   r   )cpZMAX_UNICODEmsgrT   rT   rU   _codepoint_to_kind  s   r   c                 C   s   | dk S )z;
    Returns true if a codepoint is in the ASCII range
       rT   )r   rT   rT   rU   _codepoint_is_ascii  s   r   c                 C      t | tjrdd }|S d S )Nc                 S      | j S r   )rZ   r   rT   rT   rU   len_impl     zunicode_len.<locals>.len_impl
isinstancer   UnicodeType)r   r   rT   rT   rU   unicode_len     r   c                 C   s   | j r|j sd S t| tjr| j}n| }t|tjr|j}n|}tjtjtjf}t||}t||}|r<|r<dd }|S ||A rFdd }|S d S )Nc                 S   sd   | d u }|d u }|s|r|r|rdS dS t | } t |}t| t|kr&dS t| d|dt| dkS )NTFr   )strlenr   )r   r   Za_noneZb_nonerT   rT   rU   eq_impl  s   zunicode_eq.<locals>.eq_implc                 S      dS NFrT   r   r   rT   rT   rU   r        )is_internalr   r   Optionalr~   r   StringLiteralUnicodeCharSeq)r   r   Zcheck_aZcheck_baccept	a_unicode	b_unicoder   rT   rT   rU   
unicode_eq  s$   

r   c                 C   s`   | j r|j sd S tjtjtjf}t| |}t||}|r$|r$dd }|S ||A r.dd }|S d S )Nc                 S   s
   | |k S r   rT   r   rT   rT   rU   ne_impl     
zunicode_ne.<locals>.ne_implc                 S   r   )NTrT   r   rT   rT   rU   r     r   zunicode_ne.<locals>.eq_impl)r   r   r   r   r   r   )r   r   r   r   r   r   r   rT   rT   rU   
unicode_ne  s   

r   c                 C   @   t | tjtjf}t |tjtjf}|r|rdd }|S d S d S )Nc                 S   sJ   t t| t|}t| d|d|}|dkrdS |dkr#t| t|k S dS )Nr   r{   TFminr   r   r   r   ZminlenZeqcoderT   rT   rU   lt_impl     zunicode_lt.<locals>.lt_implr   r   r   r   )r   r   r   r   r   rT   rT   rU   
unicode_lt     r  c                 C   r   )Nc                 S   sJ   t t| t|}t| d|d|}|dkrdS |dkr#t| t|kS dS )Nr   rn   TFr   r   rT   rT   rU   gt_impl  r  zunicode_gt.<locals>.gt_implr  )r   r   r   r   r  rT   rT   rU   
unicode_gt  r  r  c                 C   r   )Nc                 S   s
   | |k S r   rT   r   rT   rT   rU   le_impl  r   zunicode_le.<locals>.le_implr  )r   r   r   r   r  rT   rT   rU   
unicode_le     r  c                 C   r   )Nc                 S   s
   | |k  S r   rT   r   rT   rT   rU   ge_impl&  r   zunicode_ge.<locals>.ge_implr  )r   r   r   r   r
  rT   rT   rU   
unicode_ge!  r	  r  c                 C   s,   t | tjrt |tjrdd }|S d S d S )Nc                 S   s   t | |dkS Nr{   )_findr   rT   rT   rU   contains_impl.  r   z'unicode_contains.<locals>.contains_implr   )r   r   r  rT   rT   rU   unicode_contains+  s   r  c                 C   sb   | }t | tjr| j}n	t | tjr| j}tjtjf}|dur-t ||s/td	||| dS dS )zCheck object belongs to one of specific types
    ty: type
        Type of the object
    name: str
        Name of the object
    N"{}" must be {}, not {})
r   r   Omittedrq   r   r~   IntegerNoneTyper    format)tynamethetyacceptedrT   rT   rU   unicode_idx_check_type4  s   r  c                 C   s(   t | tjsd|tj| }t|dS )z$Check object belongs to unicode typer  N)r   r   r   r  r    )r  r  r   rT   rT   rU   unicode_sub_check_typeH  s   r  c                 C   s   | d|t d @ > O } | S Nrn   _BLOOM_WIDTHmaskr   rT   rT   rU   
_bloom_addQ  s   r   c                 C   s   | d|t d @ > @ S r  r  r  rT   rT   rU   _bloom_checkW  s   r!  c                 C   sX  t |}|dkr
|S |d  }}t||}td}t||}	t|D ]}
t||
}t|	|}	||kr9||
 d }q#|}
|
|| krt| ||
 }||krd}||k rlt| |
| }t||}||krdn|d7 }||k sS||krr|
S t| ||
 d }t|	|dkr|
|7 }
n|
|7 }
nt| ||
 d }t|	|dkr|
|7 }
|
d7 }
|
|| ksBdS )zLeft finder.r   rn   r{   )r   r   r   rM   r   r   r!  )rE   substrstartendmgapmlastlastzeror  r   r   jhaystack_ch	needle_chrT   rT   rU   _default_find]  sJ   







r-  c                 C   sX  t |}|dkr
|S |d  }}t|d}td|}|}	|	dkr:t||	}
t||
}|
|kr2|	d }|	d8 }	|	dks || }	|	|krt| |	}
|
|kr|}|dkrjt| |	| }t||}||krbn|d8 }|dksQ|dkrp|	S t| |	d }
|	|krt||
dkr|	|8 }	n|	|8 }	nt| |	d }
|	|krt||
dkr|	|8 }	|	d8 }	|	|ksBdS )zRight finder.r   rn   r{   )r   r   r   r!  )rE   r"  r#  r$  r%  skipr'  Zmfirstr  r   r   r*  r+  r,  rT   rT   rU   _default_rfind  sL   







r/  c                       d fdd	}|S )z%Generate finder either left or right.Nc                    sV   t | }t |}|d u rd}|d u r|}t|||\}}|| |k r$dS  | |||S )Nr   r{   )r   _adjust_indices)rE   r"  r#  r$  rF   
sub_length	find_funcrT   rU   impl  s   zgenerate_finder.<locals>.implNNrT   )r4  r5  rT   r3  rU   generate_finder  s   r7  findc                 C   <   t |tjrddd}|S t|d t|d t|d tS )zImplements str.find()Nc                 S      |  t|S r   )r8  r   rE   r"  r#  r$  rT   rT   rU   	find_impl     zunicode_find.<locals>.find_implr#  r$  r"  r6  )r   r   r   r  r  r  )rE   r"  r#  r$  r<  rT   rT   rU   unicode_find     



r>  rfindc                 C   r9  )zImplements str.rfind()Nc                 S   r:  r   )r@  r   r;  rT   rT   rU   
rfind_impl  r=  z!unicode_rfind.<locals>.rfind_implr#  r$  r"  r6  )r   r   r   r  r  _rfind)rE   r"  r#  r$  rA  rT   rT   rU   unicode_rfind  r?  rC  rindexc                 C   ,   t |d t |d t|d ddd}|S )zImplements str.rindex()r#  r$  subNc                 S   "   |  |||}|dk rtd|S Nr   zsubstring not found)r@  rp   r   rF  r#  r$  resultrT   rT   rU   rindex_impl     z#unicode_rindex.<locals>.rindex_implr6  r  r  )r   rF  r#  r$  rK  rT   rT   rU   unicode_rindex  
   



rN  r_   c                 C   rE  )zImplements str.index()r#  r$  rF  Nc                 S   rG  rH  )r8  rp   rI  rT   rT   rU   
index_impl  rL  z!unicode_index.<locals>.index_implr6  rM  )r   rF  r#  r$  rP  rT   rT   rU   unicode_index  rO  rQ  	partitionc                 C   j   |}t |tjr|j}n	t |tjr|j}tjtjf}|dur/t ||s/dd||}t	|dd }|S )zImplements str.partition()Nr  sepc                 S   s   t |}t| jd| j}t|}| j|jk st| |k r!| ||fS |dkr)td| |}|dk r7| ||fS | d| || || t|  fS Nr   empty separator)r   r   r[   r\   r   rp   r8  rE   rT  Z	empty_str
sep_lengthposrT   rT   rU   r5  '     


"zunicode_partition.<locals>.impl
r   r   r  rq   r   r~   r   r   r  r    rE   rT  r  r  r   r5  rT   rT   rU   unicode_partition     r]  countc                 C   s@   t | t | t|tjrddd}|S d}t|t|)Nc                 S   s   d}t | }t |}t||d}t|||}|| dk s ||kr"dS | || } t | }d|}}|dkr9|d S || |kr\| |||  |krR|d7 }||7 }n|d7 }|| |ks?|S Nr   rn   )r   _normalize_slice_idx_count)srcrF  r#  r$  r_  Zsrc_lenZsub_lenrT   rT   rU   
count_implB  s&   

z!unicode_count.<locals>.count_implz+The substring must be a UnicodeType, not {}r6  )_count_args_types_checkr   r   r   r    r  r~   )rb  rF  r#  r$  rc  	error_msgrT   rT   rU   unicode_count;  s   
rf  
rpartitionc                 C   rS  )zImplements str.rpartition()Nr  rT  c                 S   s   t |}t| jd| j}t|}| j|jk st| |k r!||| fS |dkr)td| |}|dk r7||| fS | d| || || t|  fS rU  )r   r   r[   r\   r   rp   r@  rW  rT   rT   rU   r5  p  rZ  z unicode_rpartition.<locals>.implr[  r\  rT   rT   rU   unicode_rpartition`  r^  rh  c                 C   sL   || kr| }|dk r|| 7 }|dk rd}|dk r"|| 7 }|dk r"d}||fS r   rT   )rF   r#  r$  rT   rT   rU   r1    s   r1  
startswithc                 C   s   t |st|tjstdt |st|tjstdt|tjr0t|jtjr0d
dd}|S t|tjr=d
dd}|S t|tjrJd
dd}|S td	)Nz:When specified, the arg 'start' must be an Integer or Nonez8When specified, the arg 'end' must be an Integer or Nonec                 S   s"   |D ]}|  |||r dS qdS NTF)ri  )r   prefixr#  r$  itemrT   rT   rU   startswith_tuple_impl  s
   z1unicode_startswith.<locals>.startswith_tuple_implc                 S      |  t|||S r   )ri  r   )r   rk  r#  r$  rT   rT   rU   startswith_char_seq_impl     z4unicode_startswith.<locals>.startswith_char_seq_implc                 S   sv   t | t |}}|d u rd}|d u r|}t|||\}}|| |k r%dS |dkr+dS | || }t|d|d|dkS Nr   FTr   r1  r   )r   rk  r#  r$  rF   Zprefix_lengthZs_slicerT   rT   rU   startswith_unicode_impl  s   z3unicode_startswith.<locals>.startswith_unicode_implz9The arg 'prefix' should be a string or a tuple of stringsr6  )	r   r   r   r  r    UniTupledtyper   r   )r   rk  r#  r$  rm  ro  rs  rT   rT   rU   unicode_startswith  s,   


rv  endswithc                 C   s   |d u st |tjtjtjfstd|d u s&t |tjtjtjfs&tdt |tjtjfr6ddd}|S t |tjrCddd}|S t |tj	rPddd}|S d S )Nz!The arg must be a Integer or Nonec                 S   s&   |D ]}|  |||du r dS qdS rj  )rw  )r   r"  r#  r$  rl  rT   rT   rU   endswith_impl  s
   z'unicode_endswith.<locals>.endswith_implc                 S   s   t | }t |}|d u rd}|d u r|}t|||\}}|| |k r$dS |dkr*dS | || } t | | }t| ||d|dkS rq  rr  )r   r"  r#  r$  rF   r2  r   rT   rT   rU   rx    s   c                 S   rn  r   )rw  r   )r   r"  r#  r$  rT   rT   rU   rx    rp  r6  )
r   r   r  r  r  r    Tuplert  r   r   )r   r"  r#  r$  rx  rT   rT   rU   unicode_endswith  s(   


rz  
expandtabsr   c                 C   sd   |}t |tjr|j}n	t |tjr|j}tjtf}|dur+t ||s+td	||ddd}|S )zImplements str.expandtabs()Nz"tabsize" must be {}, not {}r   c                 S   s`  t | }d }}d}t|D ]F}t| |}|tkr9d}|dkr8|||  }|tj| kr0td||7 }||7 }q|tjd krDtd|d7 }|d7 }|ttfv rTd}q|sY| S t	| j
|| j}	d }}t|D ]D}t| |}|tkr|dkr|||  }||7 }t||| D ]}
t|	|
t q||7 }qi|d7 }t|	|| |d7 }|ttfv rd}qi|	S )Nr   FTznew string is too longrn   )r   r   r   r9   sysmaxsizeOverflowErrorr:   r;   r   r[   r\   r   r<   )rE   tabsizerF   r*  Zline_posfoundr   
code_pointincrr   r   rT   rT   rU   expandtabs_impl  sT   

z+unicode_expandtabs.<locals>.expandtabs_implr   )
r   r   r  rq   r   r~   r  intr    r  )rE   r  r  r  r  rT   rT   rU   unicode_expandtabs  s   


.r  splitr{   c                 C   s   |dkst |tjtjtjfsd S t |tjrd	dd}|S t |tjr+d	dd}|S |d u s=t |tjs=t|ddd u rDd	dd}|S d S )
Nr{   c                 S   s   | j t||dS )N)maxsplit)r  r   )r   rT  r  rT   rT   rU   
split_implE  rp  z!unicode_split.<locals>.split_implc           
      S   s  t | }t |}|dkrtdg }d}d}|dkr?|dkr?t|d}t|D ]}t| ||kr=|| ||  |d }q'n<d}	||k r{|dksM|	|k r{t| ||d|dkrk|| ||  ||7 }|}|	d7 }	n|d7 }||k r{|dksM|	|k sM||kr|| |d   |S )Nr   rV  rn   r{   )r   rp   r   r   appendr   )
r   rT  r  a_lensep_lenpartsr(  r   Zsep_code_pointsplit_countrT   rT   rU   r  J  s:   

	rq   Fc                 S   s   t | }g }d}d}d}d}t|D ]1}t| |}	t|	}
|r'|
r"q|}d}q|
s*q|| ||  d}|d7 }|dkrC||krC nq||krS|sS|| |d   |S )Nr   TFrn   r{   )r   r   r   r*   r  )r   rT  r  r  r  r(  r   r  Zin_whitespace_blockr  Zis_whitespacerT   rT   rU   split_whitespace_implo  s2   
z,unicode_split.<locals>.split_whitespace_implr  )	r   r   r  r  ZIntegerLiteralr   r   r  getattr)r   rT  r  r  r  rT   rT   rU   unicode_split=  s"   

"
 r  c                    s   d fdd	}|S )z@Generate whitespace rsplit func based on either ascii or unicodeNr{   c                    s  |dk rt j}g }t| d }|dkr_|dkr)t| |} |s!n|d8 }|dks|dk r.n1|}|d8 }|dkrJt| |} |rBn|d8 }|dks8|| |d |d   |d8 }|dks|dkr|dkryt| |} |sqn|d8 }|dksg|dkr|| d|d   |d d d S Nr   rn   r{   )r|  r}  r   r   r  )rE   rT  r  rJ  r   r  r*  isspace_funcrT   rU   rsplit_whitespace_impl  sD   


z?generate_rsplit_whitespace_impl.<locals>.rsplit_whitespace_implr  rT   )r  r  rT   r  rU   generate_rsplit_whitespace_impl  s   &r  rsplitc                 C   sh   dd }||dt jt jt jf ||dt jtf |du s&t|t jt jfr-ddd}|S dd	d
}|S )zImplements str.unicode_rsplit()c                 S   sV   | }t | tjr| j}n	t | tjr| j}|dur't ||s)td||| dS dS )z.Check object belongs to one of specified typesNr  )r   r   r  rq   r   r~   r    r  )r  r  r  r  rT   rT   rU   _unicode_rsplit_check_type  s   z2unicode_rsplit.<locals>._unicode_rsplit_check_typerT  r  Nr{   c                 S   s   | j r	t| ||S t| ||S r   )r\   ascii_rsplit_whitespace_implunicode_rsplit_whitespace_impl)rE   rT  r  rT   rT   rU   r    s   z.unicode_rsplit.<locals>.rsplit_whitespace_implc                 S   s   t |}| j|jk st| t|k r| gS dd }|dk r tj}t|}|dkr,td|dkr6|| ||S g }t| }|dkrb| j|d|d}|dk rMn|| || |  |}|d8 }|dks@|| d|  |d d d S )Nc                 S   s   g }t |d}t| d  }}|dkrC|dkrCt | |}||kr7|| |d |d   |d  }}|d8 }|d8 }|dkrC|dks|dkrR|| d|d   |d d d S r  )r   r   r  )rE   r   r  rJ  Zch_code_pointr   r*  Zdata_code_pointrT   rT   rU   _rsplit_char  s   

z9unicode_rsplit.<locals>.rsplit_impl.<locals>._rsplit_charr   rV  rn   )r#  r$  r{   )r   r[   r   r|  r}  rp   r@  r  )rE   rT  r  r  rX  rJ  r*  rY  rT   rT   rU   rsplit_impl  s.   z#unicode_rsplit.<locals>.rsplit_implr  )r   r   r   r  r  r  r   r  )rE   rT  r  r  r  r  rT   rT   rU   unicode_rsplit  s   


/r  center c                 C   s^   t |tjs
tdt |tjrddd}|S |dks(t |tjtjfs(tdddd}|S )NThe width must be an Integerr  c                 S      |  |t|S r   )r  r   stringwidthfillcharrT   rT   rU   center_impl     z#unicode_center.<locals>.center_impl"The fillchar must be a UnicodeTypec           	      S   s|   t | }t |}|dkrtd||kr| S || }|d ||@ d@  }|| }|| }||kr6||  | S ||  ||  S )Nrn   5The fill character must be exactly one character longr   r   rp   )	r  r  r  str_lenfillchar_lenZ	allmarginZlmarginZrmarginZl_stringrT   rT   rU   r  %  s   r  r   r   r  r    r   r  r   )r  r  r  r  rT   rT   rU   unicode_center  s   

r  c                    r0  )Nr  c                    st   t |tjs
tdt |tjr  rd
dd}|S d
dd}|S |dks1t |tjtjfs1tdd
 fdd		}|S )Nr  r  c                 S   r  r   )ljustr   r  rT   rT   rU   
ljust_implD  r  z<gen_unicode_Xjust.<locals>.unicode_Xjust.<locals>.ljust_implc                 S   r  r   )rjustr   r  rT   rT   rU   
rjust_implH  r  z<gen_unicode_Xjust.<locals>.unicode_Xjust.<locals>.rjust_implr  c                    sL   t | }t |}|dkrtd||kr| S |||  } r"| | S ||  S )Nrn   r  r  )r  r  r  r  r  newstrSTRING_FIRSTrT   rU   r5  P  s   z6gen_unicode_Xjust.<locals>.unicode_Xjust.<locals>.implr  r  )r  r  r  r  r  r5  r  rT   rU   unicode_Xjust>  s   

z(gen_unicode_Xjust.<locals>.unicode_Xjustr  rT   )r  r  rT   r  rU   gen_unicode_Xjust=  s   %r  r  r  Tc                    r   )zDGenerate splitlines performer based on ascii or unicode line breaks.c           
         s   t | }g }d }}||k r_||k r$t| |} |rn|d7 }||k s|}||k rP|d |k rHt| |}t| |d }	t|rHt|	rH|d7 }|d7 }|rP|}|| ||  |}||k s|S r`  )r   r   r5   r4   r  )
rE   keependsrF   rJ  r   r*  r  eolZcur_cpZnext_cpis_line_break_funcrT   rU   r5  l  s0   

z&generate_splitlines_func.<locals>.implrT   )r  r5  rT   r  rU   generate_splitlines_funcj  s   r  
splitlinesc                 C   sl   |}t |tjr|j}n	t |tjr|j}tjttjt	f}|dur/t ||s/t
dd||ddd}|S )zImplements str.splitlines()Nr  r  Fc                 S   s   | j rt| |S t| |S r   )r\   _ascii_splitlines_unicode_splitlines)rE   r  rT   rT   rU   splitlines_impl  s   

z+unicode_splitlines.<locals>.splitlines_implF)r   r   r  rq   r   r~   r  r  Booleanboolr    r  )rE   r  r  r  r  rT   rT   rU   unicode_splitlines  s   
r  c                 C   s   t |}|dkr
dS t | }|d | }| j}| j}|D ]}|t |7 }t||j}t||j}qt|||}|d }	t|d|	dt |	 t |	}
td|D ]"}t||
| d| |
|7 }
|| }	t||
|	dt |	 |
t |	7 }
qN|S )Nr    rn   )r   r[   r\   r   r   r   _strncpyr   )rT  r  Z	parts_lenr  rF   rG   rH   prJ  part
dst_offsetr   rT   rT   rU   	join_list  s,   r  joinc                 C   sz   t |tjr#t |jtjrdd }|S t |jtjr dd }|S 	 d S t |tjr/dd }|S t |tjr;dd }|S d S )Nc                 S   
   t | |S r   r  )rT  r  rT   rT   rU   join_list_impl  r   z$unicode_join.<locals>.join_list_implc                 S   s   dd |D }t | |S )Nc                 S   s   g | ]}t |qS rT   r   .0r  rT   rT   rU   
<listcomp>      z8unicode_join.<locals>.join_list_impl.<locals>.<listcomp>r  )rT  r  _partsrT   rT   rU   r       
c                 S   s   dd |D }|  |S )Nc                 S   s   g | ]}|qS rT   rT   r  rT   rT   rU   r    s    z8unicode_join.<locals>.join_iter_impl.<locals>.<listcomp>)r  rT  r  Z
parts_listrT   rT   rU   join_iter_impl  r  z$unicode_join.<locals>.join_iter_implc                    s$    fddt t D }t| |S )Nc                    s   g | ]} | qS rT   rT   )r  r   r  rT   rU   r    r  z7unicode_join.<locals>.join_str_impl.<locals>.<listcomp>)r   r   r  r  rT   r  rU   join_str_impl  s   
z#unicode_join.<locals>.join_str_impl)r   r   Listru  r   r   ZIterableType)rT  r  r  r  r  rT   rT   rU   unicode_join  s   r  zfillc                 C   s    t |tjs
tddd }|S )Nz<width> must be an Integerc                 S   s\   t | }||kr
| S |r| d nd}d||  }|dv r(|| | dd   }|S ||  }|S )Nr   r  0)+-rn   r   )r  r  r  
first_charpaddingr  rT   rT   rU   
zfill_impl  s   z!unicode_zfill.<locals>.zfill_impl)r   r   r  r    )r  r  r  rT   rT   rU   unicode_zfill  s   r  c                 C   s`   t | }d}|d urt|D ]}| | |vr|  S q|S t|D ]}t| | s-|  S q!|S r   r   r   r*   r  charsr  r   rT   rT   rU   unicode_strip_left_bound  s   r  c                 C   s|   t | }d}|d ur$t|d ddD ]}| | |vr!|d7 } |S q|S t|d ddD ]}t| | s;|d7 } |S q,|S r  r  r  rT   rT   rU   unicode_strip_right_bound  s"   	r  c                 C   @   t | tjr	| j} | d u st | tjtjtjfstdd S d S )Nz%The arg must be a UnicodeType or None)r   r   r   r~   r  r   r  r    )r  rT   rT   rU   unicode_strip_types_check'     r  c                 C   r  )Nz,The slice indices must be an Integer or None)r   r   r   r~   r  r  r  r    )argrT   rT   rU   rd  0  r  rd  lstripc                 C   0   t |tjrddd}|S t| ddd}|S )Nc                 S   r:  r   )r  r   r  r  rT   rT   rU   lstrip_impl=  r=  z#unicode_lstrip.<locals>.lstrip_implc                 S   s   | t | |d  S r   )r  r  rT   rT   rU   r  C  rp  r   r   r   r   r  )r  r  r  rT   rT   rU   unicode_lstrip9     

r  rstripc                 C   r  )Nc                 S   r:  r   )r  r   r  rT   rT   rU   rstrip_implL  r=  z#unicode_rstrip.<locals>.rstrip_implc                 S   s   | d t | | S r   )r  r  rT   rT   rU   r  R  rp  r   r  )r  r  r  rT   rT   rU   unicode_rstripH  r  r  stripc                 C   r  )Nc                 S   r:  r   )r  r   r  rT   rT   rU   
strip_impl[  r=  z!unicode_strip.<locals>.strip_implc                 S   s    t | |}t| |}| || S r   )r  r  )r  r  ZlbrbrT   rT   rU   r  a  s   

r   r  )r  r  r  rT   rT   rU   unicode_stripW  s   

r  c                 C   s@   | du r
|rdS |S | dk r| |7 } | dk s| |krt d| S )a%  
    Parameters
    ----------
    idx : int or None
        the index
    length : int
        the string length
    is_start : bool; optional with defaults to True
        Is it the *start* or the *stop* of the slice?

    Returns
    -------
    norm_idx : int
        normalized index
    Nr   zstring index out of range)
IndexError)r   rF   Zis_startrT   rT   rU   normalize_str_idxl  s   r  c                 C   s:   | du r|S | |   kr|k r| | S  | dk rdS | S )a%  
    Used for unicode_count

    If arg < -slice_len, returns 0 (prevents circle)

    If arg is within slice, e.g -slice_len <= arg < slice_len
    returns its real index via arg % slice_len

    If arg > slice_len, returns arg (in this case count must
    return 0 if it is start index)
    Nr   rT   )r  Z	slice_lendefaultrT   rT   rU   ra    s   ra  c                 C   s   |||}dd }||fS )zFix slice object.
    c           	      S   sF   |j \}}|\}}| |||}t| ||| t||| | S r   )r   make_helperrB   Zguard_invalid_sliceZ	fix_slicer   )	r   r   r   r   	slicetypeZ
lengthtypesliceobjrF   slicerT   rT   rU   r     s   
z!_normalize_slice.<locals>.codegenrT   )r   r  rF   r   r   rT   rT   rU   _normalize_slice  s   
r  c                 C   s   t |}dd }||fS )z2Compute the span from the given slice object.
    c                 S   s,   |j \}|\}| |||}t||}|S r   )r   r   rB   Zget_slice_length)r   r   r   r   r  r  r  Zresult_sizerT   rT   rU   r     s
   z_slice_span.<locals>.codegen)r   rM   )r   r  r   r   rT   rT   rU   _slice_span  s   
r  c           
      C   sv   |j | j kr%t|j }|| }|| }|| }t| j||j||dd d S t|D ]}	t| ||	 t|||	  q)d S )Nrn   )align)r[   rr   r   rY   r   r   r   )
dstr  rb  Z
src_offsetr   
byte_widthZsrc_byte_offsetZdst_byte_offsetrx   r   rT   rT   rU   r    s   


r  c                 C   s2   |t jksJ dd }t t jt jt j}||fS )z_Create a slice of a unicode string using a view of its data to avoid
    extra allocation.
    c                 S   s   |\}}}t tj| ||d}t tj| |}|j|_|j|_|j|_||_| t	d|_
| jt}	|	| jtjfi }
| |	|
}|||jf}|||}||j|g|_t |jj|_| jrq| j||jd | | S )Nr   r{   r   )r   r}   r   r   rJ   rG   rH   rF   r   r   rI   typing_contextresolve_value_typerr   get_call_typerN   get_functionr   r   rE   r   rK   r~   
enable_nrtr   increfr   r   )r   r   r   r   rb  r#  rF   Zin_strZview_strZbw_typZbw_sigZbw_implr  r   rT   rT   rU   r     s8   
z$_get_str_slice_view.<locals>.codegen)r   r   rM   )r   Zsrc_tZstart_tZlength_tr   r   rT   rT   rU   _get_str_slice_view  s   r  c                 C   sD   t | tjrt |tjrdd }|S t |tjr dd }|S d S d S )Nc                 S   sZ   t |t| }t| |}t|}|| jkrt| |dS t|}t|d|}t|d| |S r   )	r  r   r   r   r[   r  r   r   r   )r   r   r   rG   rH   retrT   rT   rU   getitem_char  s   

z%unicode_getitem.<locals>.getitem_charc                 S   s   t |t| }t|}t| |j}t|}t|}t|j|j |j	|jD ]}t| |}|t|M }t|}||kr?t
||}q%|jdkrQ|| jkrQt| |j|S t|||}	|j}
t|D ]}t|	|t| |
 |
|j7 }
q^|	S r  )r  r   r  r   r#  r   r   r   stepstopr   r[   r  r   r   )r   r   Z	slice_idxspanr   rG   rH   r   new_kindr  currT   rT   rU   getitem_slice  s,   

z&unicode_getitem.<locals>.getitem_slice)r   r   r   r  Z	SliceType)r   r   r  r  rT   rT   rU   unicode_getitem  s   $r  c                 C   sP   t | tjrt |tjrdd }|S t | tjr$t |tjr&dd }|S d S d S )Nc                 S   s   | j |j  }t| j|j}t| j|j}t|||}tt| D ]}t||t	| | q tt|D ]}t|t| | t	|| q2|S r   )
rZ   r   r[   r   r\   r   r   r   r   r   )r   r   
new_lengthr  Z	new_asciirJ  r   r*  rT   rT   rU   concat_impl7  s   z#unicode_concat.<locals>.concat_implc                 S   s   | t | S r   r  r   rT   rT   rU   r  D     )r   r   r   r   )r   r   r  rT   rT   rU   unicode_concat3  s   
r  c                 C   s   | dks|dk r
dS |dkr| S | j | }| j}t||| j}t| }t|d| d| |}d| |krEt|||d| |d9 }d| |ks3d| |ks[|| }t||||| | |S d S )Nr  rn   r   r   )rZ   r[   r   r\   r   r  )Zstr_argZmult_argr  r  rJ  Zlen_aZ	copy_sizerestrT   rT   rU   _repeat_implI  s&   
r  c                 C   sP   t | tjrt |tjrdd }|S t | tjr$t |tjr&dd }|S d S d S )Nc                 S   r  r   r  r   rT   rT   rU   wrapg  r   zunicode_repeat.<locals>.wrapc                 S   s
   t || S r   r  r   rT   rT   rU   r   k  r   )r   r   r   r  )r   r   r   rT   rT   rU   unicode_repeatd  s   r!  c                 C   r   )Nc                 S   s   t | dkS r   r  r   rT   rT   rU   r5  s  r  zunicode_not.<locals>.implr   r   r5  rT   rT   rU   unicode_notp  r   r$  replacec                 C   s   |}t |tjr|j}n	t |tjr|j}t |ttjfs$td	|t |tj
tjfs4td	|t |tj
sAtd	|ddd}|S )NzGUnsupported parameters. The parameters must be Integer. Given count: {}z+The object must be a UnicodeType. Given: {}r{   c           	      S   s   |dkr| S |dkr]t | }|dkr||| | S |g}tt||}t|D ]#}|||  |d |kr>|| q)|d||d d   q)|t|krX|| d|S | ||}||}|S )Nr   r  r{   rn   )listr  r   r   r   r  r  )	r   old_strnew_strr_  ZscharsZsplit_resultZ	min_countr   rJ  rT   rT   rU   r5    s&   


zunicode_replace.<locals>.implr{   )r   r   r  rq   r   r~   r  r  r    r  r   r  )r   r'  r(  r_  r  r5  rT   rT   rU   unicode_replacex  s&   
r*  c                        fdd}|S )Nc                        fdd}|S )Nc                    s   t | }|dkr
dS |dkrt| d}| jr |S |S | jr4t|D ]}t| |} |s3 dS q%t|D ]}t| |}|sF dS q8dS )Nr   Frn   T)r   r   r\   r   )rE   rF   r  r   
ascii_funcunicode_funcrT   rU   r5    s(   


z.gen_isAlX.<locals>.unicode_isAlX.<locals>.implrT   rE   r5  r-  rT   rU   unicode_isAlX  s   z gen_isAlX.<locals>.unicode_isAlXrT   )r.  r/  r1  rT   r-  rU   	gen_isAlX  s   r2  isalphac                 C   s   t | pt| S r   )r>   r=   xrT   rT   rU   <lambda>  s   r6  isalnumc                    s    fdd}|S )Nc                    sp   t | }|dkrt| dS |dkrdS d}t|D ]}t| |} |s*|r- dS |s5|r5d}q|S Nrn   r   FTr   r   r   )r   lcasedr   r  is_loweris_titleis_upperrT   rU   r5    s   
z_is_upper.<locals>.implrT   )r=  r?  r>  r5  rT   r<  rU   	_is_upper  s   r@  c                 C   r   r   rT   r4  rT   rT   rU   r6        isupperc                 C      dd }|S )z
    Implements .isupper()
    c                 S   s   | j rt| S t| S r   )r\   _ascii_is_upper_unicode_is_upperr"  rT   rT   rU   r5    s   zunicode_isupper.<locals>.implrT   r#  rT   rT   rU   unicode_isupper  s   rF  isasciic                 C   rC  )z Implements UnicodeType.isascii()c                 S   r   r   )r\   rE   rT   rT   rU   r5    r   zunicode_isascii.<locals>.implrT   r0  rT   rT   rU   unicode_isascii  s   rI  istitlec                 C   rC  )z
    Implements UnicodeType.istitle()
    The algorithm is an approximate translation from CPython:
    https://github.com/python/cpython/blob/1d4b6ba19466aba0eb91c4ba01ba509acf18c723/Objects/unicodeobject.c#L11829-L11885 # noqa: E501
    c                 S   s   t | }|dkrt| d}t|pt|S |dkrdS d}d}t|D ])}t| |}t|s2t|r<|r7 dS d}d}q#t|rJ|sE dS d}d}q#d}q#|S r8  )r   r   r0   r6   r   r1   )rE   rF   charr;  previous_is_casedr   rT   rT   rU   r5    s,   

zunicode_istitle.<locals>.implrT   r0  rT   rT   rU   unicode_istitle  s   rM  islowerc                 C   rC  )aP  
    impl is an approximate translation of:
    https://github.com/python/cpython/blob/201c8f79450628241574fba940e08107178dc3a5/Objects/unicodeobject.c#L11900-L11933    # noqa: E501
    mixed with:
    https://github.com/python/cpython/blob/201c8f79450628241574fba940e08107178dc3a5/Objects/bytes_methods.c#L131-L156    # noqa: E501
    c                 S   sp   t | }|dkrtt| dS |dkrdS d}t|D ]}t| |}t|s*t|r- dS |s5t|r5d}q|S r8  )r   r1   r   r   r0   r6   )rE   rF   r;  r   r   rT   rT   rU   r5  :  s   
zunicode_islower.<locals>.implrT   r0  rT   rT   rU   unicode_islower1  s   	rO  isidentifierc                 C   rC  )z%Implements UnicodeType.isidentifier()c                 S   s^   t | }|dkr
dS t| d}t|s|dkrdS td|D ]}t| |}t|s, dS qdS )Nr   F_   rn   T)r   r   r,   r   r-   )rE   rF   Zfirst_cpr   r  rT   rT   rU   r5  Q  s   

z"unicode_isidentifier.<locals>.implrT   r0  rT   rT   rU   unicode_isidentifierM  s   rR  c                    r+  )Nc                    r,  )Nc                    sX   t | }|dkr t| dS r|dkrdS t|D ]}t| |} |s) dS qdS r8  r9  )rE   rF   r   r  _PyUnicode_IS_funcempty_is_falserT   rU   r5  g  s   
z*gen_isX.<locals>.unicode_isX.<locals>.implrT   r0  rS  rT   rU   unicode_isXf  s   zgen_isX.<locals>.unicode_isXrT   )rT  rU  rV  rT   rS  rU   gen_isXe  s   rW  isspace	isnumericisdigit	isdecimalisprintablec                    r+  )z)Generate common case operation performer.c           	         s   t | }|dkrt| j|| jS | jr!t| j|d} | | |S ttd| | j}dg}| |||}|d }t|}t||t|}t|D ]}t||t	|| qH|S )Nr   rn      )
r   r   r[   r\   r   r   r   r   r   r   )	rE   rF   r   tmpmaxcharsZ	newlengthmaxcharZnewkindr   r-  rT   rU   r5    s    
zcase_operation.<locals>.implrT   )r.  r/  r5  rT   r-  rU   case_operation  s   ra  c                 C   s   d}|d }|dkrt | |}t|sn|d8 }|dks
|dko#t|}|rI|d }||k r@t | |}t|s8n|d7 }||k s.||kpHt| }|rMdS dS )zEThis is a translation of the function that handles the capital sigma.r   rn   i  i  )r   r/   r.   )rE   rF   r   r   r*  Zfinal_sigmarT   rT   rU   _handle_capital_sigma  s&   

rb  c                 C   s&   | dkrt ||||d< dS t| |S )z>This is a translation of the function that lowers a character.i  r   rn   )rb  r&   )r  rE   rF   r   mappedrT   rT   rU   _lower_ucs4  s   
rd  c                    r   )Nc           
         s   d}t |D ]:}tjdtd}t| |} rt|| |||}nt||}|d | D ]}	t|d |	|d< t|||	 |d7 }q*q|S Nr   r]  ru  rn   )	r   r   zerosr#   r   rd  r%   maxr   )
rE   rF   r   r_  kr   rc  r  n_resr%  lowerrT   rU   _do_upper_or_lower  s   


z7_gen_unicode_upper_or_lower.<locals>._do_upper_or_lowerrT   )rl  rm  rT   rk  rU   _gen_unicode_upper_or_lower  s   rn  c                    r   )Nc                    s0   t t| D ]}t| |}t|| | qd S r   )r   r   r   r   rE   r   r   r  funcrT   rU   _ascii_upper_or_lower  s   
z8_gen_ascii_upper_or_lower.<locals>._ascii_upper_or_lowerrT   )rq  rr  rT   rp  rU   _gen_ascii_upper_or_lower  s   rs  rl  c                 C   
   t ttS )zImplements .lower())ra  _ascii_lower_unicode_lowerrH  rT   rT   rU   unicode_lower     
rw  upperc                 C   rt  )zImplements .upper())ra  _ascii_upper_unicode_upperrH  rT   rT   rU   unicode_upper  rx  r|  c                 C   s~   d}t jdtd}t|D ]/}|d t| |}t||}|d | D ]}	|d }
t|
|	|d< t|||	 |d7 }q$q|S re  )	r   rg  r#   r   fillr   r'   rh  r   )rE   rF   r   r_  ri  rc  r   r  rj  r%  r`  rT   rT   rU   _unicode_casefold 	  s   



r~  c                 C   s0   t t| D ]}t| |}t||t| qd S r   )r   r   r   r   r"   ro  rT   rT   rU   _ascii_casefold	  s   
r  casefoldc                 C   rt  )zImplements str.casefold())ra  r  r~  rH  rT   rT   rU   unicode_casefold	  rx  r  c                 C   s   d}d}t jdtd}t| d}t||}|d | D ]}	t||	}t|||	 |d7 }qtd|D ],}
|d t| |
}t	|| ||
|}|d | D ]}	t||	}t|||	 |d7 }qLq2||d< |S re  )
r   rg  r#   r   r(   rh  r   r   r}  rd  )rE   rF   r   r_  ri  r`  rc  r  rj  r%  r   rT   rT   rU   _unicode_capitalize	  s(   







r  c                 C   sL   t | d}t|dt| tdt| D ]}t | |}t||t| qd S r`  )r   r   r!   r   r   r"   )rE   r   r  r   rT   rT   rU   _ascii_capitalize9	  s   

r  
capitalizec                 C   rt  r   )ra  r  r  rH  rT   rT   rU   unicode_capitalizeC	     
r  c                 C   s   d}d}t jdtd}t|D ]A}|d t| |}|r&t|| |||}	ntt||}	|d|	 D ]}
|\}t||
|d< t	|||
 |d7 }q3t
t|}q|S )zCThis is a translation of the function that titles a unicode string.r   Fr]  rf  Nrn   )r   emptyr#   r   r}  r   rd  r(   rh  r   r.   )rE   rF   r   r_  ri  Zprevious_casedrc  r   r  rj  r%  r`  rT   rT   rU   _unicode_titleI	  s    


r  c                 C   sh   d}t t| D ])}t| |}t|r|st|}d}nt|r)|r&t|}d}nd}t||| qdS )z" Does .title() on an ASCII string FTN)r   r   r   r7   r!   r8   r"   r   )rE   r   rL  r   r  rT   rT   rU   _ascii_title`	  s   
r  titlec                 C   rt  )zImplements str.title())ra  r  r  rH  rT   rT   rU   unicode_titlet	  s   
r  c                 C   sN   t t| D ]}t| |}t|rt|}nt|rt|}t||| qd S r   )r   r   r   r8   r"   r7   r!   r   ro  rT   rT   rU   _ascii_swapcase|	  s   

r  c                 C   s   d}d}t jdtd}t|D ]A}|d t| |}t|r(t|| |||}	nt|r2t	||}	nd}	||d< |d |	 D ]}
t
||
}t|||
 |d7 }q>q||d< |S re  )r   r  r#   r   r}  r   r0   rd  r1   r%   rh  r   )rE   rF   r   r_  ri  r`  rc  r   r  rj  r%  rT   rT   rU   _unicode_swapcase	  s&   



r  swapcasec                 C   rt  r   )ra  r  r  rH  rT   rT   rU   unicode_swapcase	  r  r  c                 C   r   )Nc                 S   s"   t | }|dkrtdt| dS )Nrn   zord() expected a characterr   )r   	TypeErrorr   )r   lcrT   rT   rU   r5  	  s   
zol_ord.<locals>.implr   )r   r5  rT   rT   rU   ol_ord	  s   r  c                 C   s4   | t ksJ t| }t|d|tk}t|d|  |S r   )_MAX_UNICODEr   r   r   r   )r   rG   r  rT   rT   rU   _unicode_char	  s
   r  zchr() arg not in range(0x%hx)c                 C   s$   | dk s| t krtttt| S r   )r  rp   _out_of_range_msgr  r#   )ZordinalrT   rT   rU   _PyUnicode_FromOrdinal	  s   r  c                 C   r   )Nc                 S   s   t | S r   )r  )r   rT   rT   rU   r5  	  s   zol_chr.<locals>.impl)r   r   r  )r   r5  rT   rT   rU   ol_chr	  r   r  __str__c                 C      dd S )Nc                 S   s   | S r   rT   r   rT   rT   rU   r6  	  rA  zunicode_str.<locals>.<lambda>rT   r   rT   rT   rU   unicode_str	     r  __repr__c                 C   r  )Nc                 S   s   d|  d S )N'rT   r   rT   rT   rU   r6  	      zunicode_repr.<locals>.<lambda>rT   r   rT   rT   rU   unicode_repr	  s   r  c                    s   | d  fdd}|S )N
   c           	         s   d}| dk r|  } d}| dkrdS |d t tt|  }t}t|}t|||d}|r6t|dtd |d }| dkrYt	|  \} }td| }t||| |d8 }| dks>|S )NFr   Tr  rn   r  )
r  r   floorlog10r   rr   r   r   orddivmod)	r   flagrF   rG   r   r   r   digitr   tenrT   rU   r5  	  s(   zinteger_str.<locals>.implrT   )r   r5  rT   r  rU   integer_str	  s   r  c                 C   r  )Nc                 S   s   |   S r   )r  r   rT   rT   rU   r6  	  s    zinteger_repr.<locals>.<lambda>rT   r  rT   rT   rU   integer_repr	  r  r  c                 C   r  )Nc                 S   s   | rdS dS )NTrueFalserT   r   rT   rT   rU   r6  
  r  zboolean_str.<locals>.<lambda>rT   r  rT   rT   rU   boolean_str
  s   r  Zgetiterc           
      C   sp   |j \}|\}| ||j}| tjd}t||}||_||_	| j
r,| j||| | }	t| ||j|	S r   )r   r   return_typer   r   r`   r   Zalloca_once_valuer_   rE   r  r   r  r   r   )
r   r   r   r   r  rE   iterobjr)  Zindexptrr   rT   rT   rU   getiter_unicode
  s   r  Ziternextc                 C   s  |j \}|\}| j}|tj}||tjtjfi }	| 	||	}
|t
}||tjfi }| 	||}| j|||d}|||jf}||j}|d||}|| ||# |
||j|f}|| t||}|||j W d    d S 1 sw   Y  d S )Nr   <)r   r	  r
  operatorgetitemr  r   r   r`   r  r   r   rE   r   r_   Zicmp_unsignedZ	set_validZif_thenZyield_r   Zincrement_indexr   )r   r   r   r   rJ  ZitertyiterZtyctxZfntyZgetitem_sigZgetitem_implZlen_sigr   r  Zstrlenr_   Zis_validZgotitemZnindexrT   rT   rU   iternext_unicode%
  s,   


"r  )r   r6  r  r  r  r  r   )Tr)  )r|  r  numpyr   Zllvmlite.irr   r   Znumba.core.cgutilsr   Znumba.core.extendingr   r   r   r   r	   r
   r   r   r   r   Znumba.core.imputilsr   r   r   r   r   r   Znumba.core.datamodelr   r   Z
numba.corer   r   Znumba.core.pythonapir   r   r   r   Znumba._helperlibr   Znumba.cpython.hashingr   Znumba.core.unsafe.bytesr   Znumba.core.errorsr    Znumba.cpython.unicode_supportr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   Znumba.cpythonrB   r  rM   Zbitwidthr  r   rD   ZUnicodeIteratorTyper^   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rr   r   r   r   r   r   eqr   ner   ltr  gtr  ler  ger  containsr  r  r  r   r!  r-  r/  r7  r  rB  r>  rC  rN  rQ  r]  rf  rh  r1  rv  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rd  r  r  r  r  ra  r  r  r  r  r  r  r   iaddr  r  r   r!  not_r$  r*  r2  Z_unicode_is_alnumr@  Z_always_falserD  rE  rF  rI  rM  rO  rR  rW  ra  rb  rd  rn  r{  rv  rs  rz  ru  rw  r|  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  chrr  r  r  r  r  r  r  r  r  ZNEWr  rT   rT   rT   rU   <module>   sB   0 	






















&



	
	
	


.
0






#
$
$


4
1
@T,

Q%)#







	
	






%
<



1!






%




	

	
	
	