
    4Ysh<                     t   U d Z ddlZddlmZ g dZddlZddlZddlZddlZ	ddl
mZmZm
Z
m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 dd	lmZmZ dd
lmZmZ ddl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' ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ e)rddl0m1Z1m2Z2m3Z3m4Z4m5Z5  ejl                  e7      Z8dZ9dZ:i Z;e+e<df   e=d<   dZ>d Z? ed      Z@de<fdZAd ZB G d deC      ZD G d d eDe<      ZE G d! d"eE      ZF G d# d$eF      ZG G d% d&eG      ZHd' ZId( ZJ G d) deE      ZK G d* d+eE      ZLd, ZMd- ZNd. ZOd/ ZPd0 ZQd1ZRd2ZS eFeSd3z         ZT eFeSd4z         ZU eFeRd5z         ZV eFeRd6z         ZW eFeRd7z         ZX eFeRd8z         ZY eFeRd9z         ZZ eFeRd:z         Z[ eFeRd;z         Z\ eFeRd<z         Z] eFeRd=z         Z^ eFeRd>z         Z_ eFeRd?z         Z` eFeRd@z         Za eFeRdAz         Zb eFeRdBz         Zc eFdC      Zd eFeRdDz         Ze eFeRdEz         Zf eFeRdFz         Zg eFeRdGz         Zhe\e[eZ eFeRd8z          eFeRdHz          eFeRdIz          eFeRdJz          eFeRdKz          eFeRdLz          eFeRdMz          eFeRdNz          eFeRdOz          eFeRdPz          eFeRdQz          eFeRdRz          eFeRdSz         fZie\e]eZe[edfZj eFeRd8z         eZe[fZke
dT edU e	j                  j                  j                  dV iZoeVeTeU eFeRd6z          eFeRd7z         fZpdW ZqdX Zre<dYfesdeZffetdZ e]ffeude\ffe!de\ffe'd[ e[ffe
d\ e^ffed] e_ffed^ e`ffed_ eaffed` ebffe	j                  j                  j                  eOeTffe	j                  j                  j                  eOeUffededffgZweegfda feehfdb fe<effefexeffefe<eefefexeefefgZyi dd eFeRd?z         e eFeRd>z         e eFeRdFz         e eFeRdGz         e eFeRd=z         e eFeRd@z         e eFeRdAz         e eFeRdBz         e eFeRdEz         eP eFeRd5z         d eFeRd6z         d eFeRd7z         d eFeRdcz         d eFeRd<z         eQ eFeRd:z         e' eFeRd;z         e!i  eFeRdMz         eu eFeRdJz         e! eFeRdLz         eu eFeRdKz         eu eFeRdIz         e! eFeRdRz         e! eFeRdNz         eu eFeRdOz         eu eFeRdQz         e! eFeRdHz         eu eFeRdSz         eu eFeRdPz         eu eFeRd8z         es eFeRd9z         es eFeRdDz         e eFeRddz         deTeMeUeNiZzi Z{e{j                  ez       de Z}df Z~dg Z	 drdhZ G di djeE      Z eeu      Ze+e/eD   euf   e=dk<   ej                  eKdledmeFdneLdoi       dp Ze7dqk(  rddlZ ej
                          yy)sa  
This module defines the different types of terms. Terms are the kinds of
objects that can appear in a quoted/asserted triple. This includes those
that are core to RDF:

* :class:`Blank Nodes <rdflib.term.BNode>`
* :class:`URI References <rdflib.term.URIRef>`
* :class:`Literals <rdflib.term.Literal>` (which consist of a literal value,datatype and language tag)

Those that extend the RDF model into N3:

* :class:`Formulae <rdflib.graph.QuotedGraph>`
* :class:`Universal Quantifications (Variables) <rdflib.term.Variable>`

And those that are primarily for matching against 'Nodes' in the
underlying Graph:

* REGEX Expressions
* Date Ranges
* Numerical Ranges

    N)Fraction)bindNode
IdentifierURIRefBNodeLiteralVariable)datetimedatetime	timedelta)subcompile)defaultdict)
parse_time
parse_dateparse_datetimeDurationparse_durationduration_isoformat)	b64decode	b64encode)hexlify	unhexlify)	long_type)	urldefrag)urljoin)urlparse)Decimal)TYPE_CHECKINGAnyDictCallableOptionalUnionType   )AlternativePathInvPathNegatedPathSequencePathPathz/.well-known/genid/z/.well-known/genid/rdflib/r   skolemsz
<>" {}|\^`c                 &    t         D ]  }|| v s y y)NFT)_invalid_uri_chars)urics     k/var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/term.py_is_valid_urir4   P   s      8     z^[a-zA-Z]+(?:-[a-zA-Z0-9]+)*$tagc                 >    t        t        j                  |             S N)bool_lang_tag_regexmatch)r6   s    r3   _is_valid_langtagr<   Z   s    %%c*++r5   c                     t        | t              rt        | d      d}}nt        | }}	  ||       y# t        $ r Y yw xY w)z[
    Verify that the provided value can be converted into a Python
    unicode object.
    decodeutf-8FT)
isinstancebytesgetattrstrUnicodeError)valuecoding_funcparams      r3   _is_valid_unicoderH   ^   sM    
 %$UH5wU %UE   s   2 	>>c                       e Zd ZdZdZy)r   z
    A Node in the Graph.
     N)__name__
__module____qualname____doc__	__slots__rJ   r5   r3   r   r   p   s     Ir5   r   c                   p    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd ZddefdZej"                  Zy)r   zg
    See http://www.w3.org/2002/07/rdf-identifer-terminology/
    regarding choice of terminology.
    rJ   c                 .    t         j                  | |      S r8   )rC   __new__clsrE   s     r3   rR   zIdentifier.__new__   s    {{3&&r5   c                 $    | j                  |      S )zNA "semantic"/interpreted equality function,
        by default, same as __eq____eq__selfothers     r3   eqzIdentifier.eq        {{5!!r5   c                 $    | j                  |      S )zOA "semantic"/interpreted not equal function,
        by default, same as __ne__)__ne__rX   s     r3   neqzIdentifier.neq   r\   r5   c                 &    | j                  |       S r8   rV   rX   s     r3   r^   zIdentifier.__ne__   s    ;;u%%%r5   c                 `    t        |       t        |      k(  rt        |       t        |      k(  S y)a  
        Equality for Nodes.

        >>> BNode("foo")==None
        False
        >>> BNode("foo")==URIRef("foo")
        False
        >>> URIRef("foo")==BNode("foo")
        False
        >>> BNode("foo")!=URIRef("foo")
        True
        >>> URIRef("foo")!=BNode("foo")
        True
        >>> Variable('a')!=URIRef('a')
        True
        >>> Variable('a')!=Variable('a')
        False
        F)typerC   rX   s     r3   rW   zIdentifier.__eq__   s*    ( :e$t9E
**r5   c                     |yt        |       t        |      k(  rt        |       t        |      kD  S t        |t              r%t        t        |          t        t        |         kD  S t
        S )a  
        This implements ordering for Nodes,

        This tries to implement this:
        http://www.w3.org/TR/sparql11-query/#modOrderBy

        Variables are not included in the SPARQL list, but
        they are greater than BNodes and smaller than everything else

        Trb   rC   r@   r   	_ORDERINGNotImplementedrX   s     r3   __gt__zIdentifier.__gt__   s\     =$Z4;&t9s5z))t$T$Z(9T%[+AAAr5   c                     |yt        |       t        |      k(  rt        |       t        |      k  S t        |t              r%t        t        |          t        t        |         k  S t
        S NFrd   rX   s     r3   __lt__zIdentifier.__lt__   sZ    =$Z4;&t9s5z))t$T$Z(9T%[+AAAr5   c                 4    | j                  |      }|ry| |k(  S NT)rj   rY   rZ   rs      r3   __le__zIdentifier.__le__        KKu}r5   c                 4    | j                  |      }|ry| |k(  S rl   )rg   rm   s      r3   __ge__zIdentifier.__ge__   rp   r5   returnc                 H    t        |       j                  t        |            S r8   )rC   
startswith)rY   prefixstartends       r3   ru   zIdentifier.startswith   s    4y##CK00r5   N)..)rK   rL   rM   rN   rO   rR   r[   r_   r^   rW   rg   rj   ro   rr   r9   ru   rC   __hash__rJ   r5   r3   r   r   x   sR    
 I'"
"
&2(1 1 ||Hr5   r   c                        e Zd ZU dZdZed ed   gdf   ed<   ed gdf   ed<   ed gdf   ed	<   ed ed   gd
f   ed<   ddede	e   fdZ
d ZddefdZd Zd Zd Z fdZd Zd Zd Zd Z xZS )r   zT
    RDF URI Reference: http://www.w3.org/TR/rdf-concepts/#section-Graph-URIref
    rJ   )r   r-   r)   __or__r*   
__invert__r+   __neg__r,   __truediv__rE   basec                 :   |7|j                  d      }t        ||d      }|r|j                  d      s|dz  }t        |      st        j	                  d|z         	 t
        j                  | |      }|S # t        $ r t
        j                  | |d      }Y |S w xY w)N#r(   )allow_fragmentszG%s does not look like a valid URI, trying to serialize this will break.r?   )endswithr   r4   loggerwarningrC   rR   UnicodeDecodeError)rT   rE   r   ends_in_hashrts        r3   rR   zURIRef.__new__   s     >>#.LD%;E~~c*SLEU#NNY
	2S%(B 	 " 	2S%1B		2s   A6 6 BBc                     t        |       S r8   rC   rY   s    r3   toPythonzURIRef.toPython       4yr5   rs   c                 d    t        |       st        d| z        |r|j                  |       S d| z  S )a  
        This will do a limited check for valid URIs,
        essentially just making sure that the string includes no illegal
        characters (``<, >, ", {, }, |, \, `, ^``)

        :param namespace_manager: if not None, will be used to make up
             a prefixed name
        zn"%s" does not look like a valid URI, I cannot serialize this as N3/Turtle. Perhaps you wanted to urlencode it?<%s>)r4   	ExceptionnormalizeUrirY   namespace_managers     r3   n3z	URIRef.n3   sG     T" A 
 $11$77D= r5   c                 @    d| v rt        |       \  }}t        |      S | S )Nr   )r   r   )rY   urlfrags      r3   defragzURIRef.defrag  s%    $;!$IC#;Kr5   c                 &    t         t        |       ffS r8   )r   rC   r   s    r3   
__reduce__zURIRef.__reduce__  s    T%%r5   c                     t        |       fS r8   r   r   s    r3   __getnewargs__zURIRef.__getnewargs__      D	|r5   c                     | j                   t        u rd}n| j                   j                  }|dt        t        |          dS )Nzrdflib.term.URIRef())	__class__r   rK   super__repr__rY   clsNamer   s     r3   r   zURIRef.__repr__"  s8    >>V#*Gnn--G&fd(D(FGGr5   c                 <    | j                  t        |       |z         S r8   r   rC   rX   s     r3   __add__zURIRef.__add__*      ~~c$i%/00r5   c                 <    | j                  |t        |       z         S r8   r   rX   s     r3   __radd__zURIRef.__radd__-  s    ~~ec$i/00r5   c                 <    | j                  t        |       |z        S r8   r   rX   s     r3   __mod__zURIRef.__mod__0  r   r5   c                    t        | t              r4t        d| z        }t        |j                  t        t              d       S t        | t              r+d| z  }|t        v r	t        |   S t               }|t        |<   |S t        d| z        )a  Create a Blank Node from a skolem URI, in accordance
        with http://www.w3.org/TR/rdf11-concepts/#section-skolemization.
        This function accepts only rdflib type skolemization, to provide
        a round-tripping within the system.

        .. versionadded:: 4.0
        %sNrE   z<%s> is not a skolem URI)
r@   RDFLibGenidr   r   pathlenrdflib_skolem_genidGenidr.   r   )rY   
parsed_uribnode_idretvals       r3   de_skolemizezURIRef.de_skolemize3  s     dK(!$+.Jzs3F/G/IJKKe$d{H7"x(($*!6=>>r5   r8   )rK   rL   rM   rN   rO   r$   r&   __annotations__rC   r%   rR   r   r   r   r   r   r   r   r   r   r   __classcell__r   s   @r3   r   r      s     Ih&6 78:KKLL(Y.//xj-/008U+;%<=~MNNC x} (!C !*&H111?r5   r   c                        e Zd ZdZed        Zy)r   rJ   c                     t        | t              st        |       } t        |       }|j                  j	                  t
              }|dk7  ryy)Nr   FT)r@   rC   r   r   rfindskolem_genidr1   r   gen_ids      r3   _is_external_skolemzGenid._is_external_skolemM  s?    #s#c(Cc]
&&|4Q;r5   N)rK   rL   rM   rO   staticmethodr   rJ   r5   r3   r   r   J  s    I r5   r   c                        e Zd ZdZed        Zy)r   rJ   c                     t        | t              st        |       } t        |       }|j                  dk7  s|j                  dk7  s|j
                  dk7  ry|j                  j                  t              }|dk7  ryy)N Fr   T)	r@   rC   r   paramsqueryfragmentr   r   r   r   s      r3   _is_rdflib_skolemzRDFLibGenid._is_rdflib_skolem[  sm    #s#c(Cc]
#2%""b(&&':;Q;r5   N)rK   rL   rM   rO   r   r   rJ   r5   r3   r   r   X  s    I r5   r   c                       y)NNrJ   rJ   r5   r3   
_unique_idr   l  s     r5   c                      ddl m fd} | S )zA
    Generates UUID4-based but ncname-compliant identifiers.
    r   uuid4c                  &             j                   S r8   )hexr   s   r3   
_generatorz,_serial_number_generator.<locals>._generator  s    w{{r5   )uuidr   )r   r   s    @r3   _serial_number_generatorr   y  s      r5   c                   ^    e Zd ZdZdZd e        e       fdZd ZddZ	d Z
d Zd	 Zdd
Zy)r   zM
    Blank Node: http://www.w3.org/TR/rdf-concepts/#section-blank-nodes

    rJ   Nc                 P    | |       }||}n	 t         j                  | |      S )zE
        # only store implementations should pass in a value
        )r   rR   )rT   rE   _sn_gen_prefixnode_ids        r3   rR   zBNode.__new__  s6     = iG%w/E  !!#u--r5   c                     t        |       S r8   r   r   s    r3   r   zBNode.toPython  r   r5   c                     d| z  S )Nz_:%srJ   r   s     r3   r   zBNode.n3  s    }r5   c                     t        |       fS r8   r   r   s    r3   r   zBNode.__getnewargs__  r   r5   c                 &    t         t        |       ffS r8   )r   rC   r   s    r3   r   zBNode.__reduce__  s    D	|$$r5   c                 z    | j                   t        u rd}n| j                   j                  }|dt        |       dS )Nzrdflib.term.BNodez('z'))r   r   rK   rC   )rY   r   s     r3   r   zBNode.__repr__  s1    >>U")Gnn--G!(#d)44r5   c                 b    |d}|t         }|t        |       }t        t        ||            S )zCreate a URIRef "skolem" representation of the BNode, in accordance
        with http://www.w3.org/TR/rdf11-concepts/#section-skolemization

        .. versionadded:: 4.0
        zhttp://rdlib.net/)r   rC   r   r   )rY   	authoritybasepathskolems       r3   	skolemizezBNode.skolemize  s:     +I*H#SY/79f566r5   r8   NN)rK   rL   rM   rN   rO   r   r   rR   r   r   r   r   r   r   rJ   r5   r3   r   r     s@    
 I !9!;Z\.*%57r5   c            
       .    e Zd ZU dZeed<   dZ	 	 	 d%dedee   dee   dee	   fdZ
d	 Zed
        Zedee   fd       Zed        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d&d Z"d'd!Z#d" Z$ fd#Z%d$ Z& xZ'S )(r	   ai
  
    RDF Literal: http://www.w3.org/TR/rdf-concepts/#section-Graph-Literal

    The lexical value of the literal is the unicode object.
    The interpreted, datatyped value is available from .value

    Language tags must be valid according to :rfc:5646

    For valid XSD datatypes, the lexical form is optionally normalized
    at construction time. Default behaviour is set by rdflib.NORMALIZE_LITERALS
    and can be overridden by the normalize parameter to __new__

    Equality and hashing of Literals are done based on the lexical form, i.e.:

    >>> from rdflib.namespace import XSD

    >>> Literal('01') != Literal('1')  # clear - strings differ
    True

    but with data-type they get normalized:

    >>> Literal('01', datatype=XSD.integer) != Literal('1', datatype=XSD.integer)
    False

    unless disabled:

    >>> Literal('01', datatype=XSD.integer, normalize=False) != Literal('1', datatype=XSD.integer)
    True


    Value based comparison is possible:

    >>> Literal('01', datatype=XSD.integer).eq(Literal('1', datatype=XSD.float))
    True

    The eq method also provides limited support for basic python types:

    >>> Literal(1).eq(1) # fine - int compatible with xsd:integer
    True
    >>> Literal('a').eq('b') # fine - str compatible with plain-lit
    False
    >>> Literal('a', datatype=XSD.string).eq('a') # fine - str compatible with xsd:string
    True
    >>> Literal('a').eq(1) # not fine, int incompatible with plain-lit
    NotImplemented

    Greater-than/less-than ordering comparisons are also done in value
    space, when compatible datatypes are used.  Incompatible datatypes
    are ordered by DT, or by lang-tag.  For other nodes the ordering
    is None < BNode < URIRef < Literal

    Any comparison with non-rdflib Node are "NotImplemented"
    In PY3 this is an error.

    >>> from rdflib import Literal, XSD
    >>> lit2006 = Literal('2006-01-01',datatype=XSD.date)
    >>> lit2006.toPython()
    datetime.date(2006, 1, 1)
    >>> lit2006 < Literal('2007-01-01',datatype=XSD.date)
    True
    >>> Literal(datetime.utcnow()).datatype
    rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#dateTime')
    >>> Literal(1) > Literal(2) # by value
    False
    >>> Literal(1) > Literal(2.0) # by value
    False
    >>> Literal('1') > Literal(1) # by DT
    True
    >>> Literal('1') < Literal('1') # by lexical form
    False
    >>> Literal('a', lang='en') > Literal('a', lang='fr') # by lang-tag
    False
    >>> Literal(1) > URIRef('foo') # by node-type
    True

    The > < operators will eat this NotImplemented and throw a TypeError (py3k):

    >>> Literal(1).__gt__(2.0)
    NotImplemented


    _value)	_language	_datatyper   lexical_or_valuelangdatatype	normalizec                 Z   |dk(  rd }||nt         j                  }||t        d      |t        |      st	        d|z        |rt        |      }d }t        |t              r8|xs |j                  }|rt        ||      }n|j                  }|j                  }nnt        |t              st        |t              r/t        ||      }|@|r>t        ||      \  }}|-t        |      r"|}n|}t        ||      \  }}|xs |}||}|rd }t        |t              r|j!                  d      }|t"        t$        fv rt'        |      }|t$        fv rt)        |      }	 t        j+                  | |      }||_        ||_        ||_        |S # t,        $ r t        j+                  | |d      }Y 9w xY w)Nr   zmA Literal can only have one of lang or datatype, per http://www.w3.org/TR/rdf-concepts/#section-Graph-Literalz!'%s' is not a valid language tag!r?   )rdflibNORMALIZE_LITERALS	TypeErrorr<   
ValueErrorr   r@   r	   language_castLexicalToPythonr   rE   rC   rA   _castPythonToLiteralrH   r>   _XSD_NORMALISED_STRING
_XSD_TOKEN_normalise_XSD_STRING_strip_and_collapse_whitespacerR   r   r   r   r   )	rT   r   r   r   r   rE   r   r   insts	            r3   rR   zLiteral.__new__  s    2:D!*!6IF<U<U	 4O 
 $5d$;@4GHHh'H&0 4+44D,-=xH+44(..(#.*=Mu2U ))98DE Y$8$I!	%*;F*C'-$ %E 45Ex PFI,9H!#) &./66w?.
;;45EF
}$=>NO	?KK-=>D ! " 	?;;s$4g>D	?s   F  F*)F*c                 v    | j                   ,t        | j                   | j                  | j                        S | S )a<  
        Returns a new literal with a normalised lexical representation
        of this literal
        >>> from rdflib import XSD
        >>> Literal("01", datatype=XSD.integer, normalize=False).normalize()
        rdflib.term.Literal(u'1', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))

        Illegal lexical forms for the datatype given are simply passed on
        >>> Literal("a", datatype=XSD.integer, normalize=False)
        rdflib.term.Literal(u'a', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))

        )r   r   )rE   r	   r   r   r   s    r3   r   zLiteral.normalizei  s.     ::!4::DMMRRKr5   c                     | j                   S r8   )r   r   s    r3   rE   zLiteral.value|  s    {{r5   rs   c                     | j                   S r8   )r   r   s    r3   r   zLiteral.language      ~~r5   c                     | j                   S r8   )r   r   s    r3   r   zLiteral.datatype  r   r5   c                 R    t         t        |       | j                  | j                  ffS r8   )r	   rC   r   r   r   s    r3   r   zLiteral.__reduce__  s%    Yt}}5
 	
r5   c                 H    d t        | j                  | j                        fS )N)r   r   )dictr   r   r   s    r3   __getstate__zLiteral.__getstate__  s    dDMMDMMJKKr5   c                 6    |\  }}|d   | _         |d   | _        y )Nr   r   )r   r   )rY   arg_ds       r3   __setstate__zLiteral.__setstate__  s!    1::r5   c                 0   || S t        |t              st        |      }| j                  |j                  k(  rAt        | j                         |j                         z   | j                  | j                        S | j                  t
        v r|j                  t
        v rvt        t        dt        t        | j                               t        |j                               z   d      z  j                  d      j                  d            t              S 	 t        j                  | |      }| j                  t        v r| j                  }nt        }t        || j                  |      S # t        $ r$ t        | j                        t        |      z   }Y iw xY w)z
        >>> Literal(1) + 1
        rdflib.term.Literal(u'2', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))
        >>> Literal("1") + "1"
        rdflib.term.Literal(u'11')
        )r   z%f   0.)r@   r	   r   r   r   _NUMERIC_LITERAL_TYPESr    roundrstrip_XSD_DECIMALrC   r   r   rE   _STRING_LITERAL_TYPES_XSD_STRING)rY   valsnew_datatypes       r3   r   zLiteral.__add__  sI    ;K #w'#,C ==CLL(#,,.0$--$--  MM33 66 873<<>;R RTVWX VC[VC[ &
 
/KKc*
 }} 55#}}  +1dmmlCC  /

Oc#h./s   E( (*FFc                 `    | j                   t        | j                         S t        |       dk7  S )zc
        Is the Literal "True"
        This is used for if statements, bool(literal), etc.
        r   )rE   r9   r   r   s    r3   __bool__zLiteral.__bool__  s+    
 ::!

##4yA~r5   c                     t        | j                  t        t        t        f      r#t        | j                  j                               S t        dt        |       z        )a  
        >>> (- Literal(1))
        rdflib.term.Literal(u'-1', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))
        >>> (- Literal(10.5))
        rdflib.term.Literal(u'-10.5', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#double'))
        >>> from rdflib.namespace import XSD
        >>> (- Literal("1", datatype=XSD.integer))
        rdflib.term.Literal(u'-1', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))

        >>> (- Literal("1"))
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: Not a number; rdflib.term.Literal(u'1')
        >>>
        Not a number; %s)	r@   rE   intr   floatr	   r}   r   reprr   s    r3   r}   zLiteral.__neg__  sF    " djj3	5"9:4::--/00.d;<<r5   c                     t        | j                  t        t        t        f      r#t        | j                  j                               S t        dt        |       z        )a  
        >>> (+ Literal(1))
        rdflib.term.Literal(u'1', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))
        >>> (+ Literal(-1))
        rdflib.term.Literal(u'-1', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))
        >>> from rdflib.namespace import XSD
        >>> (+ Literal("-1", datatype=XSD.integer))
        rdflib.term.Literal(u'-1', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))

        >>> (+ Literal("1"))
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: Not a number; rdflib.term.Literal(u'1')
        r  )	r@   rE   r  r   r  r	   __pos__r   r  r   s    r3   r  zLiteral.__pos__  sF     djj3	5"9:4::--/00.d;<<r5   c                     t        | j                  t        t        t        f      r#t        | j                  j                               S t        dt        |       z        )a  
        >>> abs(Literal(-1))
        rdflib.term.Literal(u'1', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))

        >>> from rdflib.namespace import XSD
        >>> abs( Literal("-1", datatype=XSD.integer))
        rdflib.term.Literal(u'1', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))

        >>> abs(Literal("1"))
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: Not a number; rdflib.term.Literal(u'1')
        r  )	r@   rE   r  r   r  r	   __abs__r   r  r   s    r3   r!  zLiteral.__abs__  sF     djj3	5"9:4::--/00.d;<<r5   c                     t        | j                  t        t        t        f      r#t        | j                  j                               S t        dt        |       z        )a%  
        >>> ~(Literal(-1))
        rdflib.term.Literal(u'0', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))

        >>> from rdflib.namespace import XSD
        >>> ~( Literal("-1", datatype=XSD.integer))
        rdflib.term.Literal(u'0', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))

        Not working:

        >>> ~(Literal("1"))
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: Not a number; rdflib.term.Literal(u'1')
        r  )	r@   rE   r  r   r  r	   r|   r   r  r   s    r3   r|   zLiteral.__invert__  sF      djj3	5"9:4::00233.d;<<r5   c                 *   |yt        |t              r| j                  t        v r+|j                  t        v r| j                  |j                  kD  S | j                  xs t
        }|j                  xs t
        }||k7  rt        j                  rt        S ||kD  S | j                  |j                  k7  r3| j                  sy|j                  sy| j                  |j                  kD  S | j                  |j                  vt        | j                        t        v rAt        t        | j                           } || j                         ||j                        kD  S 	 | j                  |j                  kD  S t        |       t        |      k7  rt        |       t        |      kD  S | j                  |j                  k7  r3| j                  sy|j                  sy| j                  |j                  kD  S yt        |t              ryt        S # t        $ r Y w xY w)a-  

        This implements ordering for Literals,
        the other comparison methods delegate here

        This tries to implement this:
        http://www.w3.org/TR/sparql11-query/#modOrderBy

        In short, Literals with compatible data-types are ordered in value
        space, i.e.
        >>> from rdflib import XSD

        >>> Literal(1) > Literal(2) # int/int
        False
        >>> Literal(2.0) > Literal(1) # double/int
        True
        >>> from decimal import Decimal
        >>> Literal(Decimal("3.3")) > Literal(2.0) # decimal/double
        True
        >>> Literal(Decimal("3.3")) < Literal(4.0) # decimal/double
        True
        >>> Literal('b') > Literal('a') # plain lit/plain lit
        True
        >>> Literal('b') > Literal('a', datatype=XSD.string) # plain lit/xsd:str
        True

        Incompatible datatype mismatches ordered by DT

        >>> Literal(1) > Literal("2") # int>string
        False

        Langtagged literals by lang tag
        >>> Literal("a", lang="en") > Literal("a", lang="fr")
        False
        TF)r@   r	   r   r  rE   r  r   DAWG_LITERAL_COLLATIONrf   r   rb   _TOTAL_ORDER_CASTERSr   rC   r   )rY   rZ   dtselfdtothercasters        r3   rg   zLiteral.__gt__'  s   H =eW% !77NN&<<zzEKK// ]]1kFnn3G 00))!G++}}.}} ==5>>99zz%%++*A

#';;1$tzz2BCF!$**-u{{0CCC::33 4yCJ&4y3u:-- }}.}} ==5>>99t$!!+ ! s   H 	HHc                     |yt        |t              r'	 | j                  |       xr | j                  |       S t        |t              ryt
        S # t        $ r	 t
        cY S w xY wri   )r@   r	   rg   r[   r   rf   r   rX   s     r3   rj   zLiteral.__lt__  sg    =eW%&;;u--Ddggen2DD eT"  &%%&s   %A A$#A$c                 x    | j                  |      }|ry	 | j                  |      S # t        $ r	 t        cY S w xY w)z
        >>> from rdflib.namespace import XSD
        >>> Literal('2007-01-01T10:00:00', datatype=XSD.dateTime
        ...     ) <= Literal('2007-01-01T10:00:00', datatype=XSD.dateTime)
        True
        T)rj   r[   r   rf   rm   s      r3   ro   zLiteral.__le__  s@     KK	"775>! 	"!!	"   ' 99c                 x    | j                  |      }|ry	 | j                  |      S # t        $ r	 t        cY S w xY wrl   )rg   r[   r   rf   rm   s      r3   rr   zLiteral.__ge__  s>    KK	"775>! 	"!!	"r+  c                    t        |t              r| j                  rK|j                  r?| j                  t        vs|j                  t        vr| j                  |j                  k7  ryy| j                  t        k(  r+|j                  s|j                  t        k(  r| j                  sy| j
                  xs dj                         |j
                  xs dj                         k7  ryy)zo
        Helper method to decide which things are meaningful to
        rich-compare with this literal
        Fr   T)r@   r	   r   XSDToPythonr  r   lowerrX   s     r3   _comparable_tozLiteral._comparable_to  s    
 eW%}} MM4~~[8 }}6$  4U^^NNk1$--  MM'R..0U^^5Ir4P4P4RR r5   c                     t         j                  |       }| j                  r&|t        | j                  j	                               z  }| j
                  r|t        | j
                        z  }|S )a  
        >>> from rdflib.namespace import XSD
        >>> a = {Literal('1', datatype=XSD.integer):'one'}
        >>> Literal('1', datatype=XSD.double) in a
        False


        "Called for the key object for dictionary operations,
        and by the built-in function hash(). Should return
        a 32-bit integer usable as a hash value for
        dictionary operations. The only required property
        is that objects which compare equal have the same
        hash value; it is advised to somehow mix together
        (e.g., using exclusive or) the hash values for the
        components of the object that also play a part in
        comparison of objects." -- 3.4.1 Basic customization (Python)

        "Two literals are equal if and only if all of the following hold:
        * The strings of the two lexical forms compare equal, character by
        character.
        * Either both or neither have language tags.
        * The language tags, if any, compare equal.
        * Either both or neither have datatype URIs.
        * The two datatype URIs, if any, compare equal, character by
        character."
        -- 6.5.1 Literal Equality (RDF: Concepts and Abstract Syntax)

        )rC   ry   r   hashr/  r   )rY   ress     r3   ry   zLiteral.__hash__  sT    < ll4 >>4,,.//C>>4''C
r5   c                 <   | |u ry|yt        |t              r| j                  |j                  k(  xri | j                  r| j                  j	                         nd|j                  r|j                  j	                         ndk(  xr t
        j                  | |      S y)a  
        Literals are only equal to other literals.

        "Two literals are equal if and only if all of the following hold:
        * The strings of the two lexical forms compare equal, character by character.
        * Either both or neither have language tags.
        * The language tags, if any, compare equal.
        * Either both or neither have datatype URIs.
        * The two datatype URIs, if any, compare equal, character by character."
        -- 6.5.1 Literal Equality (RDF: Concepts and Abstract Syntax)

        >>> Literal("1", datatype=URIRef("foo")) == Literal("1", datatype=URIRef("foo"))
        True
        >>> Literal("1", datatype=URIRef("foo")) == Literal("1", datatype=URIRef("foo2"))
        False

        >>> Literal("1", datatype=URIRef("foo")) == Literal("2", datatype=URIRef("foo"))
        False
        >>> Literal("1", datatype=URIRef("foo")) == "asdf"
        False
        >>> from rdflib import XSD
        >>> Literal('2007-01-01', datatype=XSD.date) == Literal('2007-01-01', datatype=XSD.date)
        True
        >>> Literal('2007-01-01', datatype=XSD.date) == date(2007, 1, 1)
        False
        >>> Literal("one", lang="en") == Literal("one", lang="en")
        True
        >>> Literal("hast", lang='en') == Literal("hast", lang='de')
        False
        >>> Literal("1", datatype=XSD.integer) == Literal(1)
        True
        >>> Literal("1", datatype=XSD.integer) == Literal("01", datatype=XSD.integer)
        True

        TNF)r@   r	   r   r   r/  rC   rW   rX   s     r3   rW   zLiteral.__eq__  s    H 5==eW%%//1 ,/3~~T^^))+4/4EOO))+DJ, JJtU+	 r5   c                    t        |t              r| j                  t        v rk|j                  t        v rY| j                  %|j                  | j                  |j                  k(  S t
        j                  | |      ryt        d| d|      | j                  xs dj                         |j                  xs dj                         k7  ry| j                  xs t        }|j                  xs t        }|t        k(  r|t        k(  rt
        j                  | |      S ||k7  r6t        j                  r%t        d| j                  d|j                        y| j                  ]|j                  Q| j                  t        t        fv r t        | j                  |j                        S | j                  |j                  k(  S t
        j                  | |      ry| j                  t        k(  ryt        d| d|      t        |t               ryt        |t
              r@| j                  y| j                  t        k(  s| j                  t        |       |k(  S tB        S t        |t"        t$        t&        f      r'| j                  t        v r| j                  |k(  S tB        S t        |t(        t*        t,        f      r2| j                  t.        t0        t2        fv r| j                  |k(  S tB        S t        |t4        t6        f      r2| j                  t8        t:        t<        fv r| j                  |k(  S tB        S t        |t>              r"| j                  t@        k(  r| j                  |k(  S tB        S )aw  
        Compare the value of this literal with something else

        Either, with the value of another literal
        comparisons are then done in literal "value space",
        and according to the rules of XSD subtype-substitution/type-promotion

        OR, with a python object:

        basestring objects can be compared with plain-literals,
        or those with datatype xsd:string

        bool objects with xsd:boolean

        a int, long or float with numeric xsd types

        isodate date,time,datetime objects with xsd:date,xsd:time or xsd:datetime

        Any other operations returns NotImplemented

        TzII cannot know that these two lexical forms do not map to the same value: z and r   Fz4I don't know how to compare literals with datatypes )"r@   r	   r   r  rE   rC   rW   r   r   r/  r  r   r$  _RDF_XMLLITERAL_RDF_HTMLLITERAL_isEqualXMLNoder   r  r   r  r   r   r   _XSD_DATETIME	_XSD_DATE	_XSD_TIMEr   r   _XSD_DURATION_XSD_DAYTIMEDURATION_XSD_YEARMONTHDURATIONr9   _XSD_BOOLEANrf   )rY   rZ   r&  r'  s       r3   r[   z
Literal.eq!  s   , eW% !77NN&<<::)ekk.E::44zz$.##(  #**,1E20L0L0NN]]1kFnn3G$K)?zz$.. 00#==%..: 
 ! zz%%++*A==_6F$GG*4::u{{CCzzU[[00 ::dE*==K/   U$ 
 t$s# }}(}}+t}}/D4yE))& # Y67}} 66zzU**  h56}}	9 EEzzU**  	845}}$&! 
 zzU**
 	 t$}},zzU**r5   c                 &    | j                  |       S r8   )r[   rX   s     r3   r_   zLiteral.neq  s    775>!!r5   c                 ^    |r| j                  |j                        S | j                         S )ae  
        Returns a representation in the N3 format.

        Examples::

            >>> Literal("foo").n3()
            u'"foo"'

        Strings with newlines or triple-quotes::

            >>> Literal("foo\nbar").n3()
            u'"""foo\nbar"""'

            >>> Literal("''\'").n3()
            u'"\'\'\'"'

            >>> Literal('"""').n3()
            u'"\\"\\"\\""'

        Language::

            >>> Literal("hello", lang="en").n3()
            u'"hello"@en'

        Datatypes::

            >>> Literal(1).n3()
            u'"1"^^<http://www.w3.org/2001/XMLSchema#integer>'

            >>> Literal(1.0).n3()
            u'"1.0"^^<http://www.w3.org/2001/XMLSchema#double>'

            >>> Literal(True).n3()
            u'"true"^^<http://www.w3.org/2001/XMLSchema#boolean>'

        Datatype and language isn't allowed (datatype takes precedence)::

            >>> Literal(1, lang="en").n3()
            u'"1"^^<http://www.w3.org/2001/XMLSchema#integer>'

        Custom datatype::

            >>> footype = URIRef("http://example.org/ns#foo")
            >>> Literal("1", datatype=footype).n3()
            u'"1"^^<http://example.org/ns#foo>'

        Passing a namespace-manager will use it to abbreviate datatype URIs:

            >>> from rdflib import Graph
            >>> Literal(1).n3(Graph().namespace_manager)
            u'"1"^^xsd:integer'
        )qname_callback)_literal_n3r   r   s     r3   r   z
Literal.n3  s2    j ##3D3Q3Q#RR##%%r5   c                    |r| j                   t        v r| j                  | j                   t        v rI	 t	        |       }t        j                  |      st        j                  |      r| j                  d|      S 	 | j                   t        k(  rt        dddt	        |       z        S | j                   t        k(  rd| z  }d|vrd|vr	d|vr|d	z  }|S | j                   t        k(  rd| z  j                         S d| z  S | j                         }| j                   }d}|r|r ||      }|sd
|z  }|t        v rj	 t	        |       }t        j                  |      r"|j!                  dd      j!                  dd      }t        j                  |      r|j!                  dd      }| j&                  }|r|d|S |r|d|S d|z  S # t        $ r | j                  d|      cY S w xY w# t        $ r t#        j$                  d| z         Y gw xY w)aj  
        Using plain literal (shorthand) output::
            >>> from rdflib.namespace import XSD

            >>> Literal(1)._literal_n3(use_plain=True)
            u'1'

            >>> Literal(1.0)._literal_n3(use_plain=True)
            u'1e+00'

            >>> Literal(1.0, datatype=XSD.decimal)._literal_n3(use_plain=True)
            u'1.0'

            >>> Literal(1.0, datatype=XSD.float)._literal_n3(use_plain=True)
            u'"1.0"^^<http://www.w3.org/2001/XMLSchema#float>'

            >>> Literal("foo", datatype=XSD.string)._literal_n3(
            ...         use_plain=True)
            u'"foo"^^<http://www.w3.org/2001/XMLSchema#string>'

            >>> Literal(True)._literal_n3(use_plain=True)
            u'true'

            >>> Literal(False)._literal_n3(use_plain=True)
            u'false'

            >>> Literal(1.91)._literal_n3(use_plain=True)
            u'1.91e+00'

            Only limited precision available for floats:
            >>> Literal(0.123456789)._literal_n3(use_plain=True)
            u'1.234568e-01'

            >>> Literal('0.123456789',
            ...     datatype=XSD.decimal)._literal_n3(use_plain=True)
            u'0.123456789'

        Using callback for datatype QNames::

            >>> Literal(1)._literal_n3(
            ...         qname_callback=lambda uri: "xsd:integer")
            u'"1"^^xsd:integer'

        NFz\.?0*eez%er   r  Ez.0r   infINFInfinitynanNaNzSerializing weird numerical %r@z^^)r   _PLAIN_LITERAL_TYPESrE   _NUMERIC_INF_NAN_LITERAL_TYPESr  mathisinfisnanrC  r   _XSD_DOUBLEr   r  r?  r/  _quote_encodereplacewarningswarnr   )	rY   	use_plainrB  vr  encodedr   	quoted_dtr   s	            r3   rC  zLiteral._literal_n3  s   Z *>>zz% ==$BBG!$K::a=DJJqM#'#3#3E>#JJ -: ==K/y#teDk/ABB]]l2tA!|1AT	H]]l2 4K..00$;&$$&==	*84	"X-	99KdAzz!} #*//%"?"G"G&# zz!}")//%"? ==%x00&	22'>!c & G#//~FFGL " K MM"BT"IJKs%   AG 8A)G% G"!G"%!H	H	c                 D   d| v rX| j                  dd      }d| v r|j                  dd      }|d   dk(  r|d   dk7  r|d d dz   dz   }d	|j                  d
d      z  S d| j                  dd      j                  dd      j                  dd      j                  d
d      z  S )N
\z\\z"""z\"\"\""z"""%s"""z\rz"%s"z\nz\")rT  )rY   rY  s     r3   rS  zLiteral._quote_encode7  s     4<ll40G}!//%=r{c!gbkT&9!#2,-3e <<<DLLu5==dFKSSUgdE"# #r5   c                 |   t         t        |          g}| j                  '|j	                  dt        | j                        z         | j                  '|j	                  dt        | j                        z         | j                  t        k(  rd}n| j                  j                  }|ddj                  |      dS )Nzlang=%szdatatype=%szrdflib.term.Literalr   z, r   )
r   r	   r   r   appendr  r   r   rK   join)rY   argsr   r   s      r3   r   zLiteral.__repr__P  s    gt-/0==$KK	D$778==$KKT]](;;<>>W$+Gnn--G&		$88r5   c                 6    | j                   | j                   S | S )zV
        Returns an appropriate python datatype derived from this RDF Literal
        r   r   s    r3   r   zLiteral.toPython\  s    
 ::!::r5   )NNNr8   )FN)(rK   rL   rM   rN   r"   r   rO   r%   rC   r9   rR   r   propertyrE   r   r   r   r  r	  r   r  r}   r  r!  r|   rg   rj   ro   rr   r0  ry   rW   r[   r_   r   rC  rS  r   r   r   r   s   @r3   r	   r	     s+   QGf K4I
 #"&$(LL smL 3-	L
 D>L\&   (3-    
L'
4Dl=,=(=&=*]"~"":$L1fn`"8&tg"R#2
9r5   r	   c                 ~    t         j                  j                  j                  d| z        }|j	                          |S )Nz1<rdflibtoplevelelement>%s</rdflibtoplevelelement>)xmldomminidomparseStringr   )	xmlstringr   s     r3   	_parseXMLrn  f  s5    WW__((;iGF Mr5   c                     	 dd l }|j                  |j                  j                  d            }|j	                  |       }|j                          |S # t        $ r t        d      w xY w)Nr   rj  )treezWHTML5 parser not available. Try installing html5lib <http://code.google.com/p/html5lib>)html5lib
HTMLParsertreebuildersgetTreeBuilderparseFragmentr   ImportError)htmltextrq  parserr   s       r3   
_parseHTMLry  n  sp    
$$(*?*?*N*Nu*U$V%%h/ 
>
 	

s   AA A)c                    t        | t        j                  j                  j                        rIt        j                  j                  j                         }|xj                  | j                  z  c_        |} | j                  d      }|j                  dj                  d            r|dd  }|j                  dj                  d            r|dd }|dj                  d      k(  rd	j                  d      }|S )
Nr?   z&<?xml version="1.0" encoding="utf-8"?>zlatin-1&   z<rdflibtoplevelelement>   iz<rdflibtoplevelelement/>r   )
r@   ri  rj  rk  DocumentFragmentDocument
childNodestoxmlru   encode)xmlnoder  r  s      r3   	_writeXMLr  }  s    '377??;;<GGOO$$&	***gA 	||<CCINObcF||-44Y?@bI&--i88IIi Hr5   c                 X    t        | t              r| j                         } t        |       S r8   )r@   rC   r  r   r   s    r3   
_unhexlifyr    s"    %Ur5   c                     ddg}ddg}| j                         }||v ry||vrt        j                  d| z  t               y)	N1truer  falseTz8Parsing weird boolean, % r does not map to True or False)categoryF)r/  rU  rV  UserWarning)rE   true_accepted_valuesfalse_accepted_values	new_values       r3   _parseBooleanr    sR    = 'NI((--FN 	
 r5   z!http://www.w3.org/2001/XMLSchema#z+http://www.w3.org/1999/02/22-rdf-syntax-ns#
XMLLiteralHTMLstringnormalizedStringtokenr  doubledecimalintegerbooleandateTimer   r   durationdayTimeDurationyearMonthDurationz&http://www.w3.org/2002/07/owl#rationalbase64Binary	hexBinarygYear
gYearMonthbyter  longnegativeIntegernonNegativeIntegernonPositiveIntegerpositiveIntegershortunsignedByteunsignedIntunsignedLongunsignedShortc                 `    | j                   d uxr | j                   j                  |       d u| fS r8   tzinfo	utcoffsetr   s    r3   <lambda>r    s1    D NU\\%;%;E%B$%N r5   c                 `    | j                   d uxr | j                   j                  d       d u| fS r8   r  r   s    r3   r  r    s1    D MU\\%;%;D%A%M r5   c                 "    | j                         S r8   )r  r   s    r3   r  r    s    EKKM r5   c                 .    |r
 ||       |fS |r| |fS | d fS r8   rJ   )objpTypecastFuncdTypes       r3   _py2literalr    s+    }e##	EzDyr5   c                     t         D ]*  \  \  }}}t        | |      s||k(  st        | |||      c S  t        D ]$  \  }\  }}t        | |      st        | |||      c S  | dfS )z
    Casts a tuple of a python type and a special datatype URI to a tuple of the lexical value and a
    datatype URI (or None)
    N)_SpecificPythonToXSDRulesr@   r  _GenericPythonToXSDRules)r  r   r  r  r  s        r3   r   r   
  s    
 %> < c5!ex&7sE8U;;< %= <  %c5!sE8U;;< 9r5   r   c                 4    t        |       j                         S r8   )rC   r/  is    r3   r  r  '  s    c!flln r5   c                 
    | dS )NfrJ   r  s    r3   r  r  *  s
    Aa5 r5   c                 "    | j                         S r8   	isoformatr  s    r3   r  r  +  s    !++- r5   c                 "    | j                         S r8   r  r  s    r3   r  r  ,      akkm r5   c                 "    | j                         S r8   r  r  s    r3   r  r  -  r  r5   c                     t        |       S r8   r   r  s    r3   r  r  .  s    ,Q/ r5   c                     t        |       S r8   r  r  s    r3   r  r  /  s    -a0 r5   c                 B    | j                  d      j                  d      S )Nz%Y   strftimezfillr  s    r3   r  r  :  s    S\\$%7%=%=a%@ r5   c                 B    | j                  d      j                  d      S )Nz%Y-%m   r  r  s    r3   r  r  ;  s    #,,w*?*E*Ea*H r5   r   anyURIc                     t         j                  |d      }|r		  ||       S |	 t        |       S y#  Y yxY w# t        $ r t        | d      cY S w xY w)z~
    Map a lexical form to the value-space for the given datatype
    :returns: a python object for the value or ``None``
    FNr?   )_toPythonMappinggetrC   r   )lexicalr   convFuncs      r3   r   r   m  sl    
  ##He4H	G$$ 
		)w<
 	
 " 	)w((	)s   1 
8 5AAc                     t        | t              r2| j                  dd      j                  dd      j                  dd      S | S )z~
    Replaces 	, 
,  (#x9 (tab), #xA (linefeed), and #xD (carriage return)) with space without any whitespace collapsing
    	 r\  ra  )r@   rC   rT  r   s    r3   r   r     sC     "C(''c2::4EMMdTWXXr5   c                 p    t        | t              r%t        j                  dd| j	                               S | S )Nz +r  )r@   rC   rer   stripr  s    r3   r   r     s0    "C(vvdC!1!7!7!9::r5   c                     |r| t        d      | t        v rt        j                  d| z         ||}|t        | <   |rt        j                  || f|f       yt        j                  ||| ff       y)a  
    register a new datatype<->pythontype binding

    :param constructor: an optional function for converting lexical forms
                        into a Python instances, if not given the pythontype
                        is used directly

    :param lexicalizer: an optional function for converting python objects to
                        lexical form, if not given object.__str__ is used

    :param datatype_specific: makes the lexicalizer function be accessible
                              from the pair (pythontype, datatype) if set to True
                              or from the pythontype otherwise.  False by default
    Nz1No datatype given for a datatype-specific bindingz+datatype '%s' was already bound. Rebinding.)r   r  r   r   r  rc  r  )r   
pythontypeconstructorlexicalizerdatatype_specifics        r3   r   r     s|    " X-KLL##DxOP !,X!((:x*@+)NO ''k85L(MNr5   c                   @     e Zd ZdZdZd Z fdZd ZddZd Z	 xZ
S )	r
   zy
    A Variable - this is used for querying, or in Formula aware
    graphs, where Variables can stored in the graph
    rJ   c                 z    t        |      dk(  rt        d      |d   dk(  r|dd  }t        j                  | |      S )Nr   z7Attempted to create variable with empty string as name!?r(   )r   r   rC   rR   rS   s     r3   rR   zVariable.__new__  s@    u:?UVV8s?!"IE{{3&&r5   c                     | j                   t        u rd}n| j                   j                  }|dt        t        |          dS )Nzrdflib.term.Variabler   r   )r   r
   rK   r   r   r   s     r3   r   zVariable.__repr__  s8    >>X%,Gnn--G&h(F(HIIr5   c                     d| z  S Nz?%srJ   r   s    r3   r   zVariable.toPython      t|r5   c                     d| z  S r  rJ   r   s     r3   r   zVariable.n3  r  r5   c                 &    t         t        |       ffS r8   )r
   rC   r   s    r3   r   zVariable.__reduce__  s    3t9,''r5   r8   )rK   rL   rM   rN   rO   rR   r   r   r   r   r   r   s   @r3   r
   r
     s)    
 I'J(r5   r
   re   
         (   c                 V    ddl m}  fd} y j                  j                  k7  ry j                  |j                  |j                  fv r |       S  j                  |j
                  k(  r j                  j                  k(  r j                  j                  k(  sy j                  j                         D cg c]  }|d   dk7  r| }}j                  j                         D cg c]  }|d   dk7  r| }}t        |      t        |      k7  ry|D ]9  }||v r2 j                  |d   |d         j                  |d   |d         k(  r9 y  |       S  j                  |j                  |j                  |j                  |j                  fv r j                   j                   k(  S  j                  |j"                  k(  r4 j                   j                   k(  xr  j$                  j$                  k(  S  j                  |j&                  k(  r j(                  j(                  k(  S  j                  |j*                  k(  r> j,                  j,                  k(  xr#  j.                  j0                  j2                  k(  S t5        d j                  z        c c}w c c}w )Nr   )r   c                      t        j                        t        j                        k7  ryt        d j                  j                        D ]  \  } }t        | |      r y y)NFc                 
    | |fS r8   rJ   )xys     r3   r  z2_isEqualXMLNode.<locals>.recurse.<locals>.<lambda>  s
    !Q r5   T)r   r  mapr8  )ncocnoderZ   s     r3   recursez _isEqualXMLNode.<locals>.recurse  s]     t3u'7'7#88/%BRBRS 	HR"2r*	 r5   Fzhttp://www.w3.org/2000/xmlns/r(   z,I dont know how to compare XML Node type: %s)xml.dom.minidomr   nodeTypeDOCUMENT_NODEDOCUMENT_FRAGMENT_NODEELEMENT_NODEtagNamenamespaceURI
attributeskeysNSr   getAttributeNS	TEXT_NODECOMMENT_NODECDATA_SECTION_NODENOTATION_NODEdataPROCESSING_INSTRUCTION_NODEtargetENTITY_NODE	nodeValueDOCUMENT_TYPE_NODEpublicIdsystemIdsystemIdr   )r  rZ   r   r  kn_keyso_keyss   ``     r3   r8  r8    sm   $ |u}}}&}}++T-H-HIIy	$++	+ LLEMM)d.?.?5CUCU.U __++-
t66 
 
 %%,,.
t66 
 

 v;#f+% 	AV''!ad3u7K7KAaDRSTURV7WW	 y		 
 yyEJJ&&	$::	:yyEJJ&F4;;%,,+FF	$**	*~~00	$11	1}}.S4==ELLOO3SS FVWWU


s   J!0J&__main__)NNF)rN   r  	fractionsr   __all__loggingrU  rO  r  ri  r   r   r   r   r   r   collectionsr   isodater   r   r   r   r   r   base64r   r   binasciir   r   r   rdflib.compatr   urllib.parser   r   r   r  r    typingr!   r"   r#   r$   r%   r&   r'   pathsr)   r*   r+   r,   r-   	getLoggerrK   r   r   r   r.   rC   r   r0   r4   r:   r<   rH   objectr   r   r   r   r   r   r   r   r	   rn  ry  r  r  r  _XSD_PFX_RDF_PFXr6  r7  r  r   r   
_XSD_FLOATrR  r  _XSD_INTEGERr?  r9  r:  r;  r<  r=  r>  _OWL_RATIONAL_XSD_B64BINARY_XSD_HEXBINARY
_XSD_GYEAR_XSD_GYEARMONTHr  rM  rN  rj  rk  r~  r%  r  r  r   r  r9   r  r}  r  rA   r  r.  r  updater   r   r   r   r
   re   r8  doctesttestmodrJ   r5   r3   <module>r0     s  , 
      4 4  #  ( '  # "   !  L L LPP			8	$$2  c7l	   #  9:,3 ,$6 bs bJj?Z j?ZF % (
	;7J ;7|`j `F
$ /8L01(V+, X()+= => Hw&'
Hw&'
X()h*+h*+h*+x*,-8f$%	8f$%	x*,-h)::; +> >? ?@>12;./Hw&'
L01 
8g
8f
8e
8f
8''(
8**+
8**+
8''(
8g
8n$%
8m#$
8n$%
8o%&! *   8g"   
 	 
 GGOO9   
8(()
8g 6 	,
T; 	$l344
|$%!<01'78	#Y/0	#Y/0/?@02FGHWW__	?;<
 	WW__%%	3C'DEm$%% , J@A
OHI	>G$^g&	>I&^i( $$$
8fz$ 8fz$ 8g
	$
 8l"#Z$ 8j !>$ 8j !>$ 8''(.$ 8))*N$ 8k!"J$ 8h$ 8(()4$ 8g$ 8j !4$ 8i -$  8i '!$" 8i )#$$ 8**+S%$& 8fy'$( 8**+S)$* 8''(#+$, 8ei-$. 8n$%y/$0 8''(#1$2 8g3$4 8m#$i5$6 8fs7$8 8o%&9$: 8n$%s;$< 8g=$> 8h?$@ 8n$%yA$B 8hC$D YE$F jG$L      $. QVO@(z (J $/s#3	4T
C  3 	  %Xr62wC DOXd zGOO r5   