o
    i                     @  s  d dl mZ d dlZd dlmZmZmZmZmZm	Z	m
Z
 er#d dlZnz
d dlZes,J W n ey:   d dlZY nw d dlmZmZ d dlmZmZ d dlmZmZmZ d dlmZmZmZmZmZmZ dddZdZ dddZ!dddZ"d ddZ#g dZ$dS )!    )annotationsN)IOTYPE_CHECKINGAnyOptionalTextIOTupleUnion)
TextIOBaseTextIOWrapper)normpathsep)urljoinurlsplit
urlunsplit)BytesIOWrapperInputSourcePythonInputSourceStringInputSourceURLInputSourcecreate_input_sourcesourceMOptional[Union[IO[bytes], TextIO, InputSource, str, bytes, pathlib.PurePath]]returnOptional[Any]c                 C  s   t | tr| jS t | trt|  S t| dd} |  }z t |t	r'|j
}t |tr/|}nt|dd}t|W |  S |  w )Nzjson-ld)formatzutf-8)encoding)
isinstancer   datar   jsonloadgetCharacterStreamr   getByteStreamr   wrappedr
   r   close)r   stream
use_stream r'   \/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/rdflib/plugins/shared/jsonld/util.pysource_to_json    s   




r)   )#/:iristrTuple[str, Optional[str]]c                 C  sH   t D ]}| |}|dkr| d |d  | |d d  f  S q| d fS )N   )VOCAB_DELIMSrfind)r-   delimatr'   r'   r(   	split_iri>   s   
$r6   baseurlc                 C  s   d|v r|S t t| |}t|d }tdkrd|t}|d dr/|ds/|d7 }t|dd |f |dd  }|drN|dsN|d7 }|S )a  
    >>> norm_url('http://example.org/', '/one')
    'http://example.org/one'
    >>> norm_url('http://example.org/', '/one#')
    'http://example.org/one#'
    >>> norm_url('http://example.org/one', 'two')
    'http://example.org/two'
    >>> norm_url('http://example.org/one/', 'two')
    'http://example.org/one/two'
    >>> norm_url('http://example.org/', 'http://example.net/one')
    'http://example.net/one'
    >>> norm_url('http://example.org/', 'http://example.org//one')
    'http://example.org//one'
    z://   r+   r      Nr*   )r   r   r   r   joinsplitendswithr   )r7   r8   partspathresultr'   r'   r(   norm_urlF   s   "rA   r   Optional[str]c                 C  s   | j dkr?z| j}W n
 ty   Y dS w |D ])}d|v r>|d|d}}|dkr>|dkr>t| j||d |   S qdS dS )aJ  
    Please note that JSON-LD documents served with the application/ld+json media type
    MUST have all context information, including references to external contexts,
    within the body of the document. Contexts linked via a
    http://www.w3.org/ns/json-ld#context HTTP Link Header MUST be
    ignored for such documents.
    zapplication/ld+jsonNz+ rel="http://www.w3.org/ns/json-ld#context"<>r0   r1   )content_typelinksAttributeErrorindexr   r8   )r   rF   linkijr'   r'   r(   context_from_urlinputsourced   s   

rL   )r   r)   r6   rA   rL   )r   r   r   r   )r-   r.   r   r/   )r7   r.   r8   r.   r   r.   )r   r   r   rB   )%
__future__r   pathlibtypingr   r   r   r   r   r   r	   r   ImportError
simplejsonior
   r   	posixpathr   r   urllib.parser   r   r   rdflib.parserr   r   r   r   r   r   r)   r2   r6   rA   rL   __all__r'   r'   r'   r(   <module>   s*   $
 




