
    i@                        d dl mZ d dl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mZmZmZ 	 	 	 	 	 	 ddZ G d d	e      Zy
)    )annotations)StringIO)IOListOptionalUnion)NamespaceManager)ResultSerializer)BNodeLiteralURIRefVariablec                   | y|rnt        | t              r|j                  |       S t        | t              r| j	                         S t        | t
              r| j                  |j                        S y | j	                         S )N-)qname_callback)
isinstancer   normalizeUrir   n3r   _literal_n3)tnamespace_managers     WC:\Projects\mas-dev\.venv\Lib\site-packages\rdflib/plugins/sparql/results/txtresults.py_termStringr      ss     	ya $11!445!446M7#==0A0N0N=OO $ ttv    c                  0    e Zd ZdZ	 ddd	 	 	 	 	 	 	 ddZy)TXTResultSerializerzC
    A write-only QueryResult serializer for text/ascii tables
    N)r   c               `   d }| j                   j                  dk7  rt        d      t               }| j                   s|j	                  d       np| j                   j
                  }dgt        |      z  }| j                   D 	
cg c]  }	|D 
cg c]  }
t        |	|
   |       c}
! }}	}
|D ]9  }	t        t        |            D ]   }t        ||   t        |	|               ||<   " ; |j	                  dj                  t        |      D 
cg c]  \  }}
 ||
||          c}
}      dz          |j	                  dt        |      t        |      z   z  dz          t        |      D ]T  }	|j	                  dj                  t        ||	      D cg c]  \  }}|d	|t        |      z
  z  z    c}}      dz          V |j                         }	 |j	                  |j!                  |             y
c c}
w c c}
}	w c c}
}w c c}}w # t"        t$        f$ r |j	                  |       Y y
w xY w)z6
        return a text table of query results
        c                \    |t        |       z  }|dz  x}}|dz  r|dz  }d|z  | z   d|z  z   S )z>
            center the string s in w wide string
                   )len)swh1h2s       r   cz(TXTResultSerializer.serialize.<locals>.c-   sF     QKA1fB1ua8a<#(**r   SELECTz%Can only pretty print SELECT results!z(no results)
r   |
r   r!   N)resulttype	Exceptionr   writevarsr"   r   rangemaxjoin	enumeratesumsortedzipgetvalueencode	TypeError
ValueError)selfstreamencodingr   kwargsr'   string_streamkeysmaxlenrkbir   text_vals                  r   	serializezTXTResultSerializer.serialize!   s   	+ ;;x'CDD 
{{ 01#';;#3#3DS3t9_F  %A @DDt!QqT#45tD$   s4y)A #F1Is1Q4y 9F1I *  ioFoda!Avay/oFG$N s6{S['@ AD HIAY##HHVQPAa#SV"44PQTXX  !))+	#LL23! E G
 Q
 :& 	#LL"	#s6   	G8G3$G8G>H H
 3G8
 H-,H-)zutf-8)r<   r   r=   strr   Optional[NamespaceManager]returnNone)__name__
__module____qualname____doc__rG    r   r   r   r      sA      5#
 9=5#5# 5#
 65# 
5#r   r   N)r   z'Optional[Union[URIRef, Literal, BNode]]r   rI   rJ   rH   )
__future__r   ior   typingr   r   r   r   rdflib.namespacer	   rdflib.queryr
   rdflib.termr   r   r   r   r   r   rP   r   r   <module>rW      sI    "  , , - ) 8 8.1 	":#* :#r   