U
    
HaC                     @   sX  d dl mZmZmZ d dlmZ zd dlmZ W n  ek
rP   d dl	mZ Y nX d dl
mZmZ erzd dlm  mZ n>zd dlm  mZ W n& ek
r   d dlm  mZ Y nX dddd	d
dgZz,edZeeesedZeeestW n ek
r   dZY nX dZG dd deZG dd deZdd Zdd	 Zdd
 Zdd Z dS )    )absolute_importdivisionunicode_literals)
ModuleType)Mapping)	text_typePY3Ndefault_etreeMethodDispatcherisSurrogatePairsurrogatePairToCodepointmoduleFactoryFactorysupports_lone_surrogatesz"\uD800"z	u"\uD800"FTc                   @   s,   e Zd ZdZd
ddZdd Zddd	ZdS )r
   ap  Dict with 2 special properties:

    On initiation, keys that are lists, sets or tuples are converted to
    multiple keys so accessing any one of the items in the original
    list-like object returns the matching value

    md = MethodDispatcher({("foo", "bar"):"baz"})
    md["foo"] == "baz"

    A default value which can be set through the default attribute.
     c                 C   sv   g }|D ]B\}}t |ttttfr<|D ]}|||f q&q|||f qt| | t| t|kslt	d | _
d S N)
isinstancelisttuple	frozensetsetappenddict__init__lenAssertionErrordefault)selfitems_dictEntriesnamevalueitemr   r   ?/tmp/pip-unpacked-wheel-tx790h60/pip/_vendor/html5lib/_utils.pyr   9   s    zMethodDispatcher.__init__c                 C   s   t | || jS r   )r   getr   r   keyr   r   r"   __getitem__E   s    zMethodDispatcher.__getitem__Nc                 C   s
   t || S r   )BoundMethodDispatcher)r   instanceownerr   r   r"   __get__H   s    zMethodDispatcher.__get__)r   )N)__name__
__module____qualname____doc__r   r&   r*   r   r   r   r"   r
   ,   s   
c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )r'   zAWraps a MethodDispatcher, binding its return values to `instance`c                 C   s   || _ || _d S r   )r(   
dispatcher)r   r(   r/   r   r   r"   r   N   s    zBoundMethodDispatcher.__init__c                 C   s   | j | | jS r   )r/   r*   r(   r$   r   r   r"   r&   R   s    z!BoundMethodDispatcher.__getitem__c                 C   s   || j kr| | S |S d S r   r/   )r   r%   r   r   r   r"   r#   W   s    
zBoundMethodDispatcher.getc                 C   s
   t | jS r   )iterr/   r   r   r   r"   __iter__]   s    zBoundMethodDispatcher.__iter__c                 C   s
   t | jS r   )r   r/   r2   r   r   r"   __len__`   s    zBoundMethodDispatcher.__len__c                 C   s
   || j kS r   r0   r$   r   r   r"   __contains__c   s    z"BoundMethodDispatcher.__contains__N)
r+   r,   r-   r.   r   r&   r#   r3   r4   r5   r   r   r   r"   r'   L   s   r'   c                 C   sL   t | dkoJt| d dkoJt| d dkoJt| d dkoJt| d dkS )N   r      i        i  )r   ord)datar   r   r"   r   j   s    c                 C   s,   dt | d d d  t | d d  }|S )Ni   r   r7   i   r8   r9   )r:   )r;   char_valr   r   r"   r   p   s    c                    s   i  fdd}|S )Nc                    s   t tjtdrd| j }n
d| j }t| }z| | | W S  tk
r   t|} | f||}|j| dkri |< d| kri | |< d| | kri | | |< || | |< | Y S X d S )N z_%s_factorys   _%s_factoryr   argskwargs)	r   r   r+   typer   r   KeyError__dict__update)
baseModuler>   r?   r   kwargs_tuplemodobjsfactorymoduleCacher   r"   moduleFactory|   s$    
z+moduleFactoryFactory.<locals>.moduleFactoryr   )rI   rK   r   rH   r"   r   y   s    c                    s   i   fdd}|S )Nc                     s2   t | t | f}| kr*| | |<  | S r   )r   r   )r>   r?   r%   cachefuncr   r"   wrapped   s    zmemoize.<locals>.wrappedr   )rN   rO   r   rL   r"   memoize   s    rP   )!
__future__r   r   r   typesr   collections.abcr   ImportErrorcollectionsZpip._vendor.sixr   r   xml.etree.ElementTreeetreeElementTreer	   xml.etree.cElementTreecElementTree__all__eval_xr   r   	Exceptionr   r   r
   r'   r   r   r   rP   r   r   r   r"   <module>   s>    

 	