o
    i<                     @  sX  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
mZmZmZ d dlmZ d dlmZ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 eeef Zeded	Z d?ddZ!d@ddZ"edAddZ#edBddZ#dBddZ#dCd"d#Z$e	$dDdEd(d)Z%e	$dDdFd,d)Z%	-dGdHd0d)Z%dId1d2Z&dJd8d9Z'ed:eeeeZ(dKd=d>Z)dS )L    )annotationsN)
AnyDefaultDict	GeneratorIterableMappingSetTupleTypeVarUnionoverload)EBV)	CompValueExpr)FrozenBindings
FrozenDictNotBoundErrorQueryContextSPARQLError)BNode
IdentifierLiteralURIRefVariable_FrozenDictT)boundaIterable[_FrozenDictT]breturnSet[_FrozenDictT]c                   s6   t  }| D ]t fdd|D r| q|S )Nc                 3  s.    | ]} | pt | V  qd S N)
compatible_ebvmerge.0yexprx Z/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/rdflib/plugins/sparql/evalutils.py	<genexpr>&   s   , z_diff.<locals>.<genexpr>)setalladd)r   r   r)   resr+   r(   r,   _diff    s   
r2   #Generator[_FrozenDictT, None, None]c                 #  s,    | D ] t  fdd|D r V  qd S )Nc                 3  s&    | ]}  | p |V  qd S r!   )r"   disjointDomainr%   r*   r+   r,   r-   0   s   $ z_minus.<locals>.<genexpr>)r/   r   r   r+   r5   r,   _minus,   s   r7   Iterable[FrozenBindings])Iterable[Mapping[Identifier, Identifier]]%Generator[FrozenBindings, None, None]c                 C     d S r!   r+   r6   r+   r+   r,   _join4      r<   Iterable[FrozenDict]!Generator[FrozenDict, None, None]c                 C  r;   r!   r+   r6   r+   r+   r,   r<   ;   r=   c                 c  s0    | D ]}|D ]}| |r||V  qqd S r!   )r"   r$   )r   r   r*   r'   r+   r+   r,   r<   B   s   
r)   Union[Literal, Variable, Expr]ctxr   boolc                 C  s   zt | W S  ty   Y nw t| tr'zt | |W S  ty&   Y dS w t| tr2td|  t| trEzt ||  W S    Y dS dS )z
    Return true/false for the given expr
    Either the expr is itself true/false
    or evaluates to something, with the given ctx

    an error is false
    Fz1Weird - filter got a CompValue without evalfn! %r)r   r   
isinstancer   evalr   	Exceptionr   )r)   rA   r+   r+   r,   r#   K   s&   	



r#   .Union[Literal, URIRef]r   raise_not_bound_errorc                 C  r;   r!   r+   r)   rA   rG   r+   r+   r,   _evalh      rI   Union[Variable, Expr]Union[Any, SPARQLError]c                 C  r;   r!   r+   rH   r+   r+   r,   rI   q   rJ   T&Union[Literal, URIRef, Variable, Expr]r   c                 C  s   t | ttfr	| S t | tr| |S t | tr0z||  W S  ty/   |r,td|  Y d S w t | tr;t	d|  t	d| t
| f )NzVariable %s is not boundz0Weird - _eval got a CompValue without evalfn! %rzCannot eval thing: %s (%s))rC   r   r   r   rD   r   KeyErrorr   r   rE   typerH   r+   r+   r,   rI   z   s   




c                 c  s     | D ]
}t ||r|V  qd S r!   )r#   )r   r)   cr+   r+   r,   _filter   s   
rQ   template3Iterable[Tuple[Identifier, Identifier, Identifier]]solution_ContextType@Generator[Tuple[Identifier, Identifier, Identifier], None, None]c           	      #  s    t t | D ]:}|\}}}||}||}||} fddt||||fD \}}}|durB|durB|durB|||fV  qdS )zg
    For construct/deleteWhere and friends

    Fill a triple template with instantiated variables
    c                   s&   g | ]\}}t |tr | n|qS r+   )rC   r   )r&   r*   r'   bnodeMapr+   r,   
<listcomp>   s    z!_fillTemplate.<locals>.<listcomp>N)collectionsdefaultdictr   getzip)	rR   rT   tspo_s_p_or+   rW   r,   _fillTemplate   s   






re   _ValueTvTuple[int, _ValueT]c                 C  sL   t | tr	d| fS t | trd| fS t | trd| fS t | tr$d| fS dS )zutilitity for ordering thingsr            N)rC   r   r   r   r   )rg   r+   r+   r,   _val   s   



rl   )r   r   r   r   r   r    )r   r   r   r   r   r3   )r   r8   r   r9   r   r:   )r   r>   r   r9   r   r?   )r)   r@   rA   r   r   rB   ).)r)   rF   rA   r   rG   rB   r   rF   )r)   rK   rA   r   rG   rB   r   rL   )T)r)   rM   rA   r   rG   rB   r   r   )r   r>   r)   r@   r   r?   )rR   rS   rT   rU   r   rV   )rg   rf   r   rh   )*
__future__r   rZ   typingr   r   r   r   r   r   r	   r
   r   r   rdflib.plugins.sparql.operatorsr   !rdflib.plugins.sparql.parserutilsr   r   rdflib.plugins.sparql.sparqlr   r   r   r   r   rdflib.termr   r   r   r   r   rU   r   r2   r7   r<   r#   rI   rQ   re   rf   rl   r+   r+   r+   r,   <module>   s:    0



	

