o
    iD                     @  sX  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
 d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZmZmZ d dlZd dl Zd dl!Zd dl"m#Z# ered d	lm$Z$ g d
Z%ededZ&edZ'dxddZ(dyddZ)dzd{ddZ*d|d!d"Z+	d}d~d'd(Z,			ddd.d/Z-dd1d2Z.dd4d5Z/i d6d6d7d6d8d6d9d9d:d;d<d<d=d=d>d?d@d?dAd?dBdCdCdCdDdDdEdFdGdFdFdFZ0d}ddKdLZ1dddPdQZ2	d}ddYdZZ3d[d\ ddd]fddgdhZ4eddjdkZ5edldmddndkZ5ddmddodkZ5dpZ6	 dqe6 dr Z7	 e7ds Z8	 e6dq Z9	 e7dt Z:	 ddvdwZ;dS )    )annotations)timegm)splitext)altzonegmtime	localtimetimetimezone)TYPE_CHECKINGAnyCallableDictHashableIterableIteratorListOptionalSetTupleTypeVarUnionoverload)quoteurlsplit
urlunsplitN)sign)Graph)list2setfirstuniq	more_thanto_termfrom_n3	date_timeparse_date_timeguess_format
find_rootsget_tree	_coalesce_iri2uri
_HashableT)bound_AnyTseqIterable[_HashableT]returnList[_HashableT]c                   s   t    fdd| D S )zX
    Return a new list without duplicates.
    Preserves the order, unlike set(seq)
    c                   s"   g | ]}| vr  |s|qS  )add).0xseenr1   F/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/rdflib/util.py
<listcomp>S   s   " zlist2set.<locals>.<listcomp>set)r-   r1   r5   r7   r   L   s   r   Iterable[_AnyT]Optional[_AnyT]c                 C  s   | D ]}|  S dS )z_
    return the first element in a python sequence
    for graphs, use graph.value instead
    Nr1   )r-   resultr1   r1   r7   r   V   s   r   sequenceIterable[str]stripintSet[str]c                 C  s   |rt dd | D S t | S )z,removes duplicate strings from the sequence.c                 s  s    | ]}|  V  qd S N)r@   )r3   sr1   r1   r7   	<genexpr>c   s    zuniq.<locals>.<genexpr>r9   )r>   r@   r1   r1   r7   r   `   s   r   Iterable[Any]numberc                 C  s(   d}| D ]}|d7 }||kr dS qdS )z>Returns 1 if sequence has more items than number and 0 if not.r      r1   )r>   rG   iitemr1   r1   r7   r    h   s   r    rD   Optional[str]default Optional[rdflib.term.Identifier]c                 C  s~   | s|S |  dr| drtj| dd S |  dr,| dr,tj| dd S |  dr7tj| S d|  }t|)a  
    Creates and returns an Identifier of type corresponding
    to the pattern of the given positional argument string ``s``:

    '' returns the ``default`` keyword argument value or ``None``

    '<s>' returns ``URIRef(s)`` (i.e. without angle brackets)

    '"s"' returns ``Literal(s)`` (i.e. without doublequotes)

    '_s' returns ``BNode(s)`` (i.e. without leading underscore)

    <>rH   "_zUnrecognised term syntax: '%s')
startswithendswithrdflibtermURIRefLiteralBNode	Exception)rD   rL   msgr1   r1   r7   r!   r   s   
r!   strbackendnsm+Optional[rdflib.namespace.NamespaceManager]&Optional[Union[rdflib.term.Node, str]]c                 C  sn  | s|S |  drtj| dd ddS |  drz|  dr&d}nd}| |d\}}|t|d }d}d}|d	}	|	d
krSt	||	d d |||}n| dr^|dd }|
dd}|
dd}|dd}tj|||S | dks| dkrtj| dkS |  
ddd
ddd
ddd rd|  v rtjj| tjjjdS d| v rtjjt| tjjjdS tjjt| tjjjdS |  drt	| dd }
tj||
S |  drt	| dd }
tj||
S |  drtj| dd S d| v r1|du rtjtj }| dd\}}t| | }tj|| S tj| S )a  
    Creates the Identifier corresponding to the given n3 string.

        >>> from rdflib.term import URIRef, Literal
        >>> from rdflib.namespace import NamespaceManager
        >>> from_n3('<http://ex.com/foo>') == URIRef('http://ex.com/foo')
        True
        >>> from_n3('"foo"@de') == Literal('foo', lang='de')
        True
        >>> from_n3('"""multi\nline\nstring"""@en') == Literal(
        ...     'multi\nline\nstring', lang='en')
        True
        >>> from_n3('42') == Literal(42)
        True
        >>> from_n3(Literal(42).n3()) == Literal(42)
        True
        >>> from_n3('"42"^^xsd:integer') == Literal(42)
        True
        >>> from rdflib import RDFS
        >>> from_n3('rdfs:label') == RDFS['label']
        True
        >>> nsm = NamespaceManager(rdflib.graph.Graph())
        >>> nsm.bind('dbpedia', 'http://dbpedia.org/resource/')
        >>> berlin = URIRef('http://dbpedia.org/resource/Berlin')
        >>> from_n3('dbpedia:Berlin', nsm=nsm) == berlin
        True

    rN   rH   rP   zraw-unicode-escapezunicode-escaperQ   z"""Nz^^r      @z\"z\xz\\xtruefalse. -e)datatype{[z_::)rS   rU   rV   rW   encodedecodersplitlenrfindr"   replacerX   lower	isnumeric	namespaceXSDdoublefloatdecimalrA   integergraphQuotedGraphr   rY   NamespaceManagersplitdict
namespaces	Namespace)rD   rL   r]   r^   quotesvaluerestri   languagedtoffset
identifierprefix	last_partnsr1   r1   r7   r"      sf   "











r"   Fc              	   C  s   | du rt  } |r%t| }|d rtd }ntd }d|d |d f }nt| }d}|\	}}}}}	}
}}}d|||||	|
|f }|S )ah  http://www.w3.org/TR/NOTE-datetime ex: 1997-07-16T19:20:30Z

    >>> date_time(1126482850)
    '2005-09-11T23:54:10Z'

    @@ this will change depending on where it is run
    #>>> date_time(1126482850, local_time_zone=True)
    #'2005-09-11T19:54:10-04:00'

    >>> date_time(1)
    '1970-01-01T00:00:01Z'

    >>> date_time(0)
    '1970-01-01T00:00:00Z'
    N   <   z
-%02d:%02dZz!%0004d-%02d-%02dT%02d:%02d:%02d%s)r   r   r   r	   r   )tlocal_time_zone
time_tupletz_minstzdyearmonthdayhhmmsswdyzrD   r1   r1   r7   r#      s   
r#   valc              
   C  s   d| vr| d7 } |  d\}}|dd |dd }}|r"|dkr+|dd }d}nt|dd }t|d	d
 }t|| |d  d }| }| d\}	}
}| d\}}}tt|	t|
t|t|t|t|dddf	}|| }|S )a  always returns seconds in UTC

    # tests are written like this to make any errors easier to understand
    >>> parse_date_time('2005-09-11T23:54:10Z') - 1126482850.0
    0.0

    >>> parse_date_time('2005-09-11T16:54:10-07:00') - 1126482850.0
    0.0

    >>> parse_date_time('1970-01-01T00:00:01Z') - 1.0
    0.0

    >>> parse_date_time('1970-01-01T00:00:00Z') - 0.0
    0.0
    >>> parse_date_time("2005-09-05T10:42:00") - 1125916920.0
    0.0
    Tz
T00:00:00Zr   r   Nr   rP            r   rg   rl   )r~   rA   r   r   )r   ymdr   hmstz_str	tz_offset
signed_hrsminssecsr   r   r   hourminutesecondr   r1   r1   r7   r$   !  s$   ,r$   xmlrdfowln3ttlturtlenttrixxhtmlrdfahtmlsvgnqnquadstrigjsonzjson-ldjsonldfpathfmapOptional[Dict[str, str]]c                 C  s$   |pt }|t| p||  S )a9  
    Guess RDF serialization based on file suffix. Uses
    ``SUFFIX_FORMAT_MAP`` unless ``fmap`` is provided. Examples:

        >>> guess_format('path/to/file.rdf')
        'xml'
        >>> guess_format('path/to/file.owl')
        'xml'
        >>> guess_format('path/to/file.ttl')
        'turtle'
        >>> guess_format('path/to/file.json')
        'json-ld'
        >>> guess_format('path/to/file.xhtml')
        'rdfa'
        >>> guess_format('path/to/file.svg')
        'rdfa'
        >>> guess_format('path/to/file.xhtml', {'xhtml': 'grddl'})
        'grddl'

    This also works with just the suffixes, with or without leading dot, and
    regardless of letter case::

        >>> guess_format('.rdf')
        'xml'
        >>> guess_format('rdf')
        'xml'
        >>> guess_format('RDF')
        'xml'
    )SUFFIX_FORMAT_MAPget_get_extrs   )r   r   r1   r1   r7   r%   a  s   r%   Trs   boolc                 C  sH   t | d }|dkr| dr| }|r| }|dr"|dd }|S )a)  
    Gets the file extension from a file(path); stripped of leading '.' and in
    lower case. Examples:

        >>> _get_ext("path/to/file.txt")
        'txt'
        >>> _get_ext("OTHER.PDF")
        'pdf'
        >>> _get_ext("noext")
        ''
        >>> _get_ext(".rdf")
        'rdf'
    rP   rf   re   rH   N)r   rS   rs   )r   rs   extr1   r1   r7   r     s   
r   r{   'Graph'prop'rdflib.term.URIRef'roots!Optional[Set['rdflib.term.Node']]Set['rdflib.term.Node']c                 C  sZ   t  }|du r
t  }| |D ]\}}|| ||v r!|| ||vr*|| q|S )a  
    Find the roots in some sort of transitive hierarchy.

    find_roots(graph, rdflib.RDFS.subClassOf)
    will return a set of all roots of the sub-class hierarchy

    Assumes triple of the form (child, prop, parent), i.e. the direction of
    RDFS.subClassOf or SKOS.broader

    N)r:   subject_objectsr2   remove)r{   r   r   	non_rootsr4   r   r1   r1   r7   r&     s   


r&   c                 C  s   | S rC   r1   )r4   r1   r1   r7   <lambda>  s    r   downroot'rdflib.term.Node'mapper2Callable[['rdflib.term.Node'], 'rdflib.term.Node']sortkeyOptional[Callable[[Any], Any]]donedir.Optional[Tuple['rdflib.term.Node', List[Any]]]c              	   C  s   |du rt  }||v rdS || g }|dkr| ||}n| ||}|D ]}	t| |	|||||}
|
r:||
 q'||t||dfS )a  
    Return a nested list/tuple structure representing the tree
    built by the transitive property given, starting from the root given

    i.e.

    get_tree(graph,
       rdflib.URIRef("http://xmlns.com/foaf/0.1/Person"),
       rdflib.RDFS.subClassOf)

    will return the structure for the subClassTree below person.

    dir='down' assumes triple of the form (child, prop, parent),
    i.e. the direction of RDFS.subClassOf or SKOS.broader
    Any other dir traverses in the other direction

    Nr   )key)r:   r2   subjectsobjectsr'   appendsorted)r{   r   r   r   r   r   r   treebranchesbranchr   r1   r1   r7   r'     s   

r'   argsc                 G     d S rC   r1   rL   r   r1   r1   r7   r(     s   r(   .)rL   c                 G  r   rC   r1   r   r1   r1   r7   r(     s   c                 G  s   |D ]
}|dur|  S q| S )a  
    This is a null coalescing function, it will return the first non-`None`
    argument passed to it, otherwise it will return ``default`` which is `None`
    by default.

    For more info regarding the rationale of this function see deferred `PEP 505
    <https://peps.python.org/pep-0505/>`_.

    :param args: Values to consider as candidates to return, the first arg that
        is not `None` will be returned. If no argument is passed this function
        will return None.
    :param default: The default value to return if none of the args are not
        `None`.
    :return: The first ``args`` that is not `None`, otherwise the value of
        ``default`` if there are no ``args`` or if all ``args`` are `None`.
    Nr1   )rL   r   argr1   r1   r7   r(     s
   z!$&'()*+,;=%z:@z/?/iric           
      C  s  t | }|\}}}}}|dvr| S t|td}t|td}t|td}|jr0|jdd}nd}d|v r<d| d}|jrG| d|j }|jrit|jt	d}|j
rbt|j
t	d}| d| }| d	| }t|||||f}	| d
r|	d
s|	d
7 }	|	S )u  
    Prior art:

    * `iri_to_uri from Werkzeug <https://github.com/pallets/werkzeug/blob/92c6380248c7272ee668e1f8bbd80447027ccce2/src/werkzeug/urls.py#L926-L931>`_

    >>> _iri2uri("https://dbpedia.org/resource/Almería")
    'https://dbpedia.org/resource/Almer%C3%ADa'
    )httphttps)safeidnaasciirf   rl   rk   ]rb   #)r   r   _PATH_SAFE_CHARS_QUERY_SAFE_CHARShostnamerm   rn   portusername_USERNAME_SAFE_CHARSpasswordr   rT   )
r   partsschemenetlocpathqueryfragmentauthpass_quotedurir1   r1   r7   r)   9  s0   r)   )r-   r.   r/   r0   )r-   r;   r/   r<   )r   )r>   r?   r@   rA   r/   rB   )r>   rF   rG   rA   r/   rA   rC   )rD   rK   rL   rM   r/   rM   )NNN)
rD   r\   rL   rK   r]   rK   r^   r_   r/   r`   )NF)r   r\   r/   rA   )r   r\   r   r   r/   rK   )T)r   r\   rs   r   r/   r\   )r{   r   r   r   r   r   r/   r   )r{   r   r   r   r   r   r   r   r   r   r   r   r   r\   r/   r   )r   r<   rL   r,   r/   r,   )r   r<   rL   r<   r/   r<   )r   r\   r/   r\   )<
__future__r   calendarr   os.pathr   r   r   r   r   r	   typingr
   r   r   r   r   r   r   r   r   r   r   r   r   r   urllib.parser   r   r   rdflib.graphrU   rdflib.namespacerdflib.termrdflib.compatr   r   __all__r*   r,   r   r   r   r    r!   r"   r#   r$   r   r%   r   r&   r'   r(   _RFC3986_SUBDELIMS_RFC3986_PCHAR_NUr   r   r   r)   r1   r1   r1   r7   <module>   s    @





o
#,	
" 1
