3
d              9   @   s  d Z ddlm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yddl	m
Z
 W n ek
r
   yddlj
jZ
W n ek
r   yddlj
jZ
W nb ek
r   yddlZ
W n@ ek
r   yddljZ
W n ek
r   edY nX Y nX Y nX Y nX Y nX y
e
jZW n* ek
r@   ddlj
jZdd	 ZY nX d!ddZejrrdd Zdd ZeZdd Zndd ZeZeZdd ZejdZ dd Z!dZ"yej#d W n e$k
r   dZ"Y nX e"rdd Z!dd Z%dd Z&ydd l'm(Z(m)Z) W n   dd l*m(Z(m)Z) Y nX dS )"zn
Utility functions and objects to ease Python 2/3 compatibility,
and different versions of support libraries.
    )absolute_import)division)print_functionN)etreez1Failed to import ElementTree from any known placec             C   s   | t j|< d S )N)etreenative_namespace_map)prefixuri r
   //tmp/pip-build-7vycvbft/rdflib/rdflib/compat.pyetree_register_namespace-   s    r   utf-8c             C   s   t | tjr| j|S | S )N)
isinstancesix	text_typeencode)sencr
   r
   r   
cast_bytes1   s    
r   c             C   s   t jd| S )Nascii)codecs	getreader)streamr
   r
   r   r   ;   s    r   c              O   s   t | ddi|S )Nmoderb)open)argskwargsr
   r
   r   bopen>   s    r   c             C   s   | dk rdS | dkrdS dS )Nr      r
   )nr
   r
   r   signC   s
    r"   c             C   s   | S )Nr
   )r   r
   r
   r   r   N   s    c             C   s
   t | dS )Nr   )cmp)r!   r
   r
   r   r"   U   s    z%(\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})c             C   s   t jdd | S )Nc             S   s   t jt| jddd  dS )Nr         )r   unichrintgroup)mr
   r
   r   <lambda>\   s    z _unicodeExpand.<locals>.<lambda>)r_unicodeEscapesub)r   r
   r
   r   _unicodeExpand[   s    r-   Fi Tc             C   sD   yt jdd | S  tk
r>   tjd|   t jdd | S X d S )Nc             S   s   t jt| jddd  dS )Nr   r$   r%   )r   r&   r'   r(   )r)   r
   r
   r   r*   i   s    z _unicodeExpand.<locals>.<lambda>zEncountered a unicode char > 0xFFFF in a narrow python build. Trying to degrade gracefully, but this can cause problems later when working with the string:
%sc             S   s   t j| jddS )Nr   Zunicode_escape)r   decoder(   )r)   r
   r
   r   r*   p   s    )r+   r,   
ValueErrorwarningswarn)r   r
   r
   r   r-   f   s    c             C   sv   t js| jd} n`| jdd} | jdd} | jdd} | jdd	} | jd
d} | jdd} | jdd} | jdd} | S )z8
    s is byte-string - replace \ escapes in string
    zstring-escapez\t	z\n
z\rz\bz\fz\""z\''z\\\)r   PY3r.   replace)r   r
   r
   r   decodeStringEscapes   s    r<   c             C   s   t js | jdjd} t| } nh| jdd} | jdd} | jdd} | jd	d
} | jdd} | jdd} | jdd} | jdd} t| } | S )zQ
    s is a unicode string
    replace ``\n`` and ``\u00AC`` unicode escapes
    zutf-8zstring-escapez\tr2   z\nr3   z\rr4   z\br5   z\fr6   z\"r7   z\'r8   z\\r9   )r   r:   r   r.   r-   r;   )r   r
   r
   r   decodeUnicodeEscape   s    
r=   )MappingMutableMapping)r   )+__doc__
__future__r   r   r   rer   r0   r   lxmlr   ImportErrorxml.etree.cElementTreecElementTreexml.etree.ElementTreeElementTreeZelementtree.ElementTree	Exceptionregister_namespacer   AttributeErrorr   r   r:   r   r   r'   	long_typer"   r   longcompiler+   r-   Znarrow_buildr&   r/   r<   r=   collections.abcr>   r?   collectionsr
   r
   r
   r   <module>   sl   $




