
    4Ysh.              
          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	m
Z
 ddlmZmZmZ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 dd
lmZ ddlmZ ddlmZ g dZ G d de      Z  G d de
      Z! G d dejD                  e      Z" G d de"      Z# G d de"      Z$ddez  iZ% G d de"      Z& G d de"      Z'	 	 	 	 	 	 d!deee(e)e*eeef   f      fdZ+d  Z,y)"a=  
Parser plugin interface.

This module defines the parser plugin interface and contains other
related parser support code.

The module is mainly useful for those wanting to write a parser that
can plugin to rdflib. If you are wanting to invoke a parser you likely
want to do so through the Graph class parse method.

    N)BytesIO
TextIOBaseTextIOWrapperStringIOBufferedIOBase)AnyDictOptionalUnion)Request)url2pathname)urlopen)	HTTPError)	xmlreader)__version__)URIRef)	Namespace)ParserInputSourceStringInputSourceURLInputSourceFileInputSourcePythonInputSourcec                       e Zd ZdZd Zd Zy)r    c                      y Nr   selfs    m/var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/parser.py__init__zParser.__init__-           c                      y r   r   )r   sourcesinks      r    parsezParser.parse0   r"   r#   N)__name__
__module____qualname__	__slots__r!   r'   r   r#   r    r   r   *   s    Ir#   r   c                   H     e Zd ZdZd	def fdZd Zd Zd Zd Z	d Z
 xZS )
BytesIOWrapper)wrappedencodedencodingr.   c                 T    t         t        |           || _        || _        d | _        y r   )superr-   r!   r.   r0   r/   )r   r.   r0   	__class__s      r    r!   zBytesIOWrapper.__init__7   s%    nd,. r#   c                     | j                   B t        j                  | j                        | j                        \  }}t        |      | _          | j                   j                  |i |S r   )r/   codecs
getencoderr0   r.   r   read)r   argskwargsbblens        r    r7   zBytesIOWrapper.read=   sV    <<6f''6t||DGAt"1:DL t||  $1&11r#   c                     | j                   ? t        j                  | j                        | j                        }t        |      | _          | j                   j                  |i |S r   )r/   r5   r6   r0   r.   r   read1)r   r8   r9   r:   s       r    r=   zBytesIOWrapper.read1C   sR    <<0!!$--0>A"1:DL!t||!!42622r#   c                     t               r   NotImplementedErrorr   r8   r9   s      r    readintozBytesIOWrapper.readintoI       !##r#   c                     t               r   r?   rA   s      r    	readinto1zBytesIOWrapper.readinto1L   rC   r#   c                     t               r   r?   rA   s      r    writezBytesIOWrapper.writeO   rC   r#   )utf-8)r(   r)   r*   r+   strr!   r7   r=   rB   rE   rG   __classcell__r3   s   @r    r-   r-   4   s-    2I 23$$$r#   r-   c                       e Zd ZdZddZd Zy)r   
    TODO:
    Nc                 b    t         j                  j                  | |       d | _        d| _        y )N	system_idF)r   r   r!   content_type
auto_closer   rP   s     r    r!   zInputSource.__init__X   s*    &&ty&A r#   c                     | j                         }|rt        |d      r	 |j                          | j	                         }|rt        |d      r	 |j                          y y y # t        $ r Y =w xY w# t        $ r Y y w xY w)Nclose)getCharacterStreamhasattrrU   	ExceptiongetByteStream)r   cfs      r    rU   zInputSource.close]   s    ##%G$	  G$	 %1    s#   A" A1 "	A.-A.1	A=<A=r   )r(   r)   r*   __doc__r!   rU   r   r#   r    r   r   S   s     
r#   r   c                   6    e Zd ZdZd	dZd Zd Zd Zd Zd Z	y)
r   a  
    Constructs an RDFLib Parser InputSource from a Python data structure,
    for example, loaded from JSON with json.load or json.loads:

    >>> import json
    >>> as_string = """{
    ...   "@context" : {"ex" : "http://example.com/ns#"},
    ...   "@graph": [{"@type": "ex:item", "@id": "#example"}]
    ... }"""
    >>> as_python = json.loads(as_string)
    >>> source = create_input_source(data=as_python)
    >>> isinstance(source, PythonInputSource)
    True
    Nc                 J    d | _         d| _        d | _        || _        || _        y )NF)rQ   rR   	public_idrP   data)r   r`   rP   s      r    r!   zPythonInputSource.__init__|   s&     "	r#   c                     | j                   S r   r_   r   s    r    getPublicIdzPythonInputSource.getPublicId       ~~r#   c                     || _         y r   rb   )r   r_   s     r    setPublicIdzPythonInputSource.setPublicId   	    "r#   c                     | j                   S r   rO   r   s    r    getSystemIdzPythonInputSource.getSystemId   rd   r#   c                     || _         y r   rO   rS   s     r    setSystemIdzPythonInputSource.setSystemId   rg   r#   c                     d | _         y r   )r`   r   s    r    rU   zPythonInputSource.close   s	    	r#   r   )
r(   r)   r*   r\   r!   rc   rf   ri   rk   rU   r   r#   r    r   r   l   s%    ##r#   r   c                   $     e Zd ZdZd fd	Z xZS )r   zO
    Constructs an RDFLib Parser InputSource from a Python String or Bytes
    c                    t         t        |   |       t        |t              rKt        |      }| j                  |       | j                  |       t        ||      }| j                  |       y t        |      }| j                  |       t        ||      }| j                  |       | j                  |j                         y r   )r2   r   r!   
isinstancerI   r   setCharacterStreamsetEncodingr-   setByteStreamr   r   r0   )r   valuer0   rP   streamb_streamc_streamr3   s          r    r!   zStringInputSource.__init__   s    /	:eS!e_F##F+X&%eX6Hx(U^Fv&$VX6H##H-X../r#   )rH   N)r(   r)   r*   r\   r!   rJ   rK   s   @r    r   r      s    0 0r#   r   z
User-agentz1rdflib-%s (http://rdflib.net/; eikeon@eikeon.com)c                   *     e Zd ZdZd fd	Zd Z xZS )r   rM   c                 h   t         t        |   |       || _        t	        t
              }|dk(  rd|d<   n1|dk(  rd|d<   n&|dk(  rd|d<   n|dk(  rd	|d<   n|d
k(  rd|d<   nd|d<   t        |d |      }dt        ffd |      }|j                         | _        | j                  | j                         |j                         j                  d      | _        | j                  $| j                  j                  dd      d   | _        | j                  |       |j                         | _        y )Nzapplication/rdf+xmlzapplication/rdf+xml, */*;q=0.1Acceptn3ztext/n3, */*;q=0.1turtlez+text/turtle,application/x-turtle, */*;q=0.1ntztext/plain, */*;q=0.1zjson-ldz6application/ld+json, application/json;q=0.9, */*;q=0.1zLapplication/rdf+xml,text/rdf+n3;q=0.9,application/xhtml+xml;q=0.5, */*;q=0.1reqc                     	 t        |       S # t        $ rB}|j                  dk(  r-|j                  j	                  d      | _         |       cY d }~S  d }~ww xY w)Ni4  Location)r   r   codeheadersgetfull_url)r}   ex_urlopens     r    r   z)URLInputSource.__init__.<locals>._urlopen   sP    s|# 	
 77c>#%::>>*#=CL#C=(	s    
 	A6AAAAzcontent-type;   r   )r2   r   r!   urldictr   r   geturlrf   infor   rQ   splitrr   response_info)r   rP   format	myheadersr}   filer   r3   s         @r    r!   zURLInputSource.__init__   s:   nd,Y7 M	**"BIht^"6Ihx"OIht^"9Ihy  I 
; h
 iy1	' 	 };;=" IIKOON;( $ 1 1 7 7Q ? BD4 !YY[r#   c                     | j                   S r   )r   r   s    r    __repr__zURLInputSource.__repr__   s    xxr#   )NN)r(   r)   r*   r\   r!   r   rJ   rK   s   @r    r   r      s    1)fr#   r   c                   $     e Zd Z fdZd Z xZS )r   c                 B   t         j                  j                         j                         }t	        t        j                  |j
                        j                         j                         |      }t        t        | '  |       || _
        t        |t              rK| j                  |       | j                  |j                         	 |j                   }| j#                  |       y | j#                  |       y # t$        t&        f$ r | j#                  |       Y y w xY w)Nbase)pathlibPathcwdas_urir   nameabsoluter2   r   r!   r   ro   r   rp   rq   r0   bufferrr   AttributeErrorLookupError)r   r   r   rP   r:   r3   s        r    r!   zFileInputSource.__init__   s    ||!((*7<<		2;;=DDFTR	ot-i8	dJ'##D)T]]+)KK""1% t$ #K0 )""4()s   C; ; DDc                 ,    t        | j                        S r   )reprr   r   s    r    r   zFileInputSource.__repr__   s    DIIr#   )r(   r)   r*   r!   r   rJ   rK   s   @r    r   r      s    %$r#   r   r`   c           	      <   t        t        d | |||g            }t        |      dk7  rt        d      d}| Yt	        | t
              r| }nEt	        | t              r| }n1t	        | t        j                        rt        |       }n
t	        | t              r| }nt        | d      rt	        | t              s| }t               }t        | d      rK|j                  |        |j                  | j                         	 |j                  }	|j!                  |	       n|j!                  |       |t&        j(                  u r|j+                  d       nCt        |d      r7|j+                  |j,                         nt/        d	t1        |       d
| d      d}
d}|t3        ||||      \  }
}}}|t5        |      }|^t	        |t6              rt9        |      }d}n@t	        |t        t        t:        f      rt=        |      }d}nt?        dt1        |             |t/        d      |xj@                  |z  c_         ||jC                  |       |S |jE                         |jC                  |
xs d       |S # t"        t$        f$ r |j!                  |        Y ow xY w)zR
    Return an appropriate InputSource instance for the given
    parameters.
    c                 
    | d uS r   r   )vs    r    <lambda>z%create_input_source.<locals>.<lambda>  s
    atm r#   r   z;exactly one of source, location, file or data must be givenNr7   r0   zfile:///dev/stdinr   zUnexpected type 'z' for source ''F)r   r   input_sourcelocationTz(parse data can only str, or bytes. not: zcould not create InputSource )#listfilterlen
ValueErrorro   r   rI   r   PurePathbytesrW   r   rp   rq   r0   r   rr   r   r   sysstdinrk   r   rX   type"_create_input_source_from_locationr   r   r   	bytearrayr   RuntimeErrorrR   rf   rc   )r%   publicIDr   r   r`   r   non_empty_argumentsr   r[   r:   absolute_locationrR   s               r    create_input_sourcer      s    #XtT*	
 1$I
 	
 Lfk*!L&#&!FG$4$45v;FE*(FI1N*}6:. 33F; ,,V__=; KK$2215 !..q1		> ,,-@AQ' ,,QVV4>B6lFS  J /%	
	
 &t,dD!,T2LJsE956,T2LJ!I$t*VWW677:-$$X.  %%'/$$%6%<"=i +K8 ;$226:;s   <I7 7 JJc                    t         j                  j                  |      r1t        j                  |      j                         j                         }t        j                  j                         j                         }t        ||      }|j                  d      r(t        |j                  dd            }t        |d      } nt        ||      }d}||| |fS )Nr   zfile:////rbT)ospathexistsr   r   r   r   r   r   
startswithr   replaceopenr   )r   r   r   r   r   r   filenamerR   s           r    r   r   f  s     
ww~~h<<)224;;=<<$$&Dxd3##J/ 1 9 9*c JKHd#%&7@J j$<<r#   )NNNNNN)-r\   r5   r   r   r   ior   r   r   r   r   typingr   r	   r
   r   urllib.requestr   r   r   urllib.errorr   xml.saxr   rdflibr   rdflib.termr   rdflib.namespacer   __all__objectr   r-   r   r   r   r   r   r   rI   r   r   r   r   r   r#   r    <module>r      s   
  	  
 K K - - " ' " "    &V $^ $>)'' 2$ $N0 0, ES
9[ 9xk 0 	CGc
 5eYS#X>?
@cL=r#   