o
    V=ñ^7  ã                   @   sH  d dl mZmZmZ d dlmZ zd dlmZ W n ey'   d dl	mZ Y nw d dl
mZmZ er<d dlm  mZ nzd dlm  mZ W n eyY   d dlm  mZ Y nw g d¢ZzedƒZeeeƒssedƒZeeeƒssJ ‚W n ey   d	ZY nw 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 ]!\}}t |ttttfƒr|D ]	}| ||f¡ qq| ||f¡ qt | |¡ t| ƒt|ƒks6J ‚d | _	d S ©N)
Ú
isinstanceÚlistÚtupleÚ	frozensetÚsetÚappendÚdictÚ__init__ÚlenÚdefault)ÚselfÚitemsZ_dictEntriesÚnameÚvalueÚitemr   r   ú1/usr/lib/python3/dist-packages/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   ó   
zMethodDispatcher.__get__)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r$   r(   r   r   r   r    r
   ,   s
    
r
   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 v r	| | S |S r   ©r.   )r   r#   r   r   r   r    r!   W   s   
zBoundMethodDispatcher.getc                 C   ó
   t | jƒS r   )Úiterr.   ©r   r   r   r    Ú__iter__]   r)   zBoundMethodDispatcher.__iter__c                 C   r0   r   )r   r.   r2   r   r   r    Ú__len__`   r)   zBoundMethodDispatcher.__len__c                 C   s
   || j v S r   r/   r"   r   r   r    Ú__contains__c   r)   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o%t| d ƒdko%t| d ƒdko%t| d ƒdko%t| d ƒdkS )Né   r   é Ø  iÿÛ  é   é Ü  iÿß  )r   Úord)Údatar   r   r    r   j   s   ÿÿþþr   c                 C   s,   dt | d ƒd d  t | d ƒd  }|S )Ni   r   r7   i   r8   r9   )r:   )r;   Zchar_valr   r   r    r   p   s   ÿr   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yn   t|ƒ}ˆ | g|¢R i |¤Ž}|j |¡ dˆvrFi ˆ|< dˆ| vrRi ˆ| |< dˆ| | vrbi ˆ| | |< |ˆ| | |< | Y S w )NÚ z_%s_factorys   _%s_factoryr   ÚargsÚkwargs)	r   r   r*   Útyper   r   ÚKeyErrorÚ__dict__Úupdate)Z
baseModuler=   r>   r   Zkwargs_tupleÚmodZobjs©ÚfactoryZmoduleCacher   r    ÚmoduleFactory|   s&   
õz+moduleFactoryFactory.<locals>.moduleFactoryr   )rE   rF   r   rD   r    r   y   s   r   c                    s   i ‰ ‡ ‡fdd„}|S )Nc                     s6   t | ƒt | ¡ ƒf}|ˆ vrˆ| i |¤Žˆ |< ˆ | S r   )r   r   )r=   r>   r#   ©ÚcacheÚfuncr   r    Úwrapped™   s   zmemoize.<locals>.wrappedr   )rI   rJ   r   rG   r    Úmemoize–   s   rK   ) Z
__future__r   r   r   Útypesr   Zcollections.abcr   ÚImportErrorÚcollectionsZsixr   r   Zxml.etree.ElementTreeZetreeZElementTreer	   Zxml.etree.cElementTreeZcElementTreeÚ__all__ÚevalZ_xr   Ú	Exceptionr   r   r
   r%   r   r   r   rK   r   r   r   r    Ú<module>   s@    ÿÿ
€ÿ 	