B
    s\                 @   sn  d Z ddlmZ ddlmZ ddlZddlZddlZddlZddl	Z	ej
eZejdkZejdkZejdkZerddlmZ ddlZdd	lmZmZ eZeZeZeZn4ddlmZ ddlZdd	l mZmZ e!ZeZe"Ze#Zd
Z$dZ%e	&dZ'e(dZ)e(dZ*e(dZ+e(dZ,dd Z-dd Z.dd Z/G dd de0Z1d$ddZ2d%ddZ3dd Z4G d d! d!e5Z6d"d# Z7dS )&zUtility.    )unicode_literals)wrapsN)   r   )r      )r      )	lru_cache)HashableMappingi   i   z(?:\r\n|(?!\r\n)[\n\r])|$azAZc             C   sR   g }xB| D ]:}t |}|t|  kr.tkr>n nt|d n| q
W d|S )zLower.     )ordappendUC_AUC_Zchrjoin)string
new_stringco r   -lib/python3.7/site-packages/soupsieve/util.pylower-   s
    
2r   c             C   sR   g }xB| D ]:}t |}|t|  kr.tkr>n nt|d n| q
W d|S )zLower.r   r   )r   r   LC_ALC_Zr   r   )r   r   r   r   r   r   r   upper7   s
    
2r   c             C   s0   yt | S  tk
r*   td| dS X dS )z8Allow getting Unicode character on narrow python builds.izutf-32N)unichar
ValueErrorstructZpackdecode)r    r   r   r   uchrA   s    r%   c                   s"   e Zd ZdZd fdd	Z  ZS )SelectorSyntaxErrorzSyntax error in a CSS selector.Nc                s^   d| _ d| _d| _|dk	rJ|dk	rJt||\| _| _ | _d|| j | j}tt| | dS )zInitialize.Nz{}
  line {}:
{})linecolcontextget_pattern_contextformatsuperr&   __init__)selfmsgpatternindex)	__class__r   r   r-   M   s    zSelectorSyntaxError.__init__)NN)__name__
__module____qualname____doc__r-   __classcell__r   r   )r2   r   r&   J   s   r&      c                s    fdd}|S )z
    Raise a `DeprecationWarning` when wrapped function/method is called.

    Borrowed from https://stackoverflow.com/a/48632082/866026
    c                s   t   fdd}|S )Nc                 s$   t jd jtd  | |S )Nz'{}' is deprecated. {})category
stacklevel)warningswarnr+   r3   DeprecationWarning)argskwargs)funcmessager:   r   r   _funcd   s
    z-deprecated.<locals>._decorator.<locals>._func)r   )r@   rB   )rA   r:   )r@   r   
_decoratorc   s    zdeprecated.<locals>._decoratorr   )rA   r:   rC   r   )rA   r:   r   
deprecated\   s    
rD   c             C   s   t j| t|d dS )zWarn deprecated.)r9   r:   N)r;   r<   r=   )rA   r:   r   r   r   warn_deprecatedp   s    rE   c             C   s.  d}d}d}g }d}xt | D ]}| ||d }t|dsdt|sdd}	d}
|| d }nR||  kr~|dk rn n,d}	||dkrdndd }
|| d }nd}	d}
t|r|d	 |d
|	| |
dk	r|d	 |d||
  d  |}|d7 }|d}q"W d|||fS )zGet the pattern context.r      r   z--> r   z    N
z{}{} ^)	RE_PATTERN_LINE_SPLITfinditerstartlengroupendr   r+   r   )r0   r1   ZlastZcurrent_liner(   textr'   mZlinetextindentoffsetr   r   r   r*   z   s6    


r*   c               @   s   e Zd ZdZdS )QuirksWarningzWarning for quirks mode.N)r3   r4   r5   r6   r   r   r   r   rU      s   rU   c             C   s   ddl }ddl}ttjd jd f}| }d}d}	d}
x4|D ],}trR|j	|sdtsf|d 	|rfP |}q>W |rtr||jn|d }	tr|j
n|d }
t||dd \}}tdd|  d d	| d
 d d|| t|	|
 dS )zWarn quirks.r   Nbs4rF   r8   z
CSS selector pattern:
z    {}
z]    This behavior is only allowed temporarily for Beautiful Soup's transition to Soup Sieve.
z,    In order to confrom to the CSS spec, {}
zR    It is strongly recommended the selector be altered to conform to the CSS spec z<as an exception will be raised for this case in the future.
zpattern line {}:
{})	tracebackrV   MODULEsysmodules__path__extract_stackPY35filename
startswithlinenor*   r;   warn_explicitr+   rU   )rA   Z	recommendr0   r1   rW   rV   pathstbZpreviousr^   r`   entryr)   r'   r   r   r   warn_quirks   s*    
""re   )r8   )r8   )8r6   Z
__future__r   	functoolsr   r;   rY   r#   osrepathdirname__file__rX   version_infoZPY3r]   ZPY37r   copyregZcollections.abcr   r	   strZustrbytesZbstrr   r!   r   Zbackports.functools_lru_cacheZcopy_regcollectionsZunicodeZunichrZ
basestringZ_QUIRKSDEBUGcompilerK   r   r   r   r   r   r   r   r%   SyntaxErrorr&   rD   rE   r*   UserWarningrU   re   r   r   r   r   <module>   sT   





	


(