
    jy-                    L   d dl mZ d dlZd dlmZmZ d dl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mZmZ  ej        d          Zej        ee f         Z! G d de"e          Z# G d de          Z$ G d de$          Z% G d de$          Z&dS )    )annotationsN)ABCMetaabstractmethod)MappingSequenceSet)reduce)xor   )BrokenHydrationObject)
iter_items)
deprecated)BrokenRecordError)NodePathRelationship_Tc                       e Zd ZU dZded<   d*dZd Z fdZd+ fd
ZeZ	d,dZ
d,dZd Zd- fdZd. fdZ ed          d             Zd/d0dZd1dZ	 d2d3d!Zd4d#Zd5d&Zd' Zd6d)Z xZS )7Recordz A :class:`.Record` is an immutable ordered collection of key-value
    pairs. It is generally closer to a :py:class:`namedtuple` than to a
    :py:class:`OrderedDict` in as much as iteration of the collection will
    yield values rather than keys.
    zt.Tuple[str]_Record__keys c                    g }g }t          |          D ]/\  }}|                    |           |                    |           0t                              | |          }t          |          |_        |S N)r   appendtuple__new__r   )clsiterablekeysvalueskeyvalueinsts          U/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/neo4j/_data.pyr   zRecord.__new__8   ss    $X.. 	! 	!JCKKMM%    }}S&))Dkk    c                D    t          d| d| j        |          d          S )NzRecord contains broken data at z ('z'))r   r   )selfindexs     r$   _broken_record_errorzRecord._broken_record_errorB   s1     NeNNE8JNNN
 
 	
r%   c                    t                                          |          }t          |t                    r|                     |          |j        |S r   )super__getitem__
isinstancer   r)   error)r'   r(   r"   	__class__s      r$   _super_getitem_singlezRecord._super_getitem_singleG   sK    ##E**e233 	D++E22Cr%   returnstrc                    d| j         j        dd                    d t          | j        t                                                                D                       dS )N< c              3  *   K   | ]\  }}|d |V  dS )=Nr   ).0fieldr"   s      r$   	<genexpr>z"Record.__repr__.<locals>.<genexpr>P   sM       O O% !&uu- O O O O O Or%   >)r/   __name__joinzipr   r+   __iter__)r'   r/   s    r$   __repr__zRecord.__repr__M   sy     N###HH O O),T[%'':J:J:L:L)M)MO O O O O O O
 	
r%   otherobjectboolc                $   t          |t                    }t          |t                    }|ra|r_t          j        t          j        |          }t          |           t          |          k    ot          |           t          |          k    S |r?t          j        t          j        |          }t          |           t          |          k    S |r?t          j        t          j        |          }t          |           t          |          k    S dS )z In order to be flexible regarding comparison, the equality rules
        for a record permit comparison with any other Sequence or Mapping.

        :param other:
        :returns:
        F)r-   r   r   tcastlistdict)r'   rA   compare_as_sequencecompare_as_mappings       r$   __eq__zRecord.__eq__V   s     )99'w77 
	#5 
	F19e,,E::e,JdtE{{1JJ  	F1:u--E::e,, 	F19e,,E::e,,5r%   c                .    |                      |           S r   )rK   )r'   rA   s     r$   __ne__zRecord.__ne__k   s    ;;u%%%%r%   c                v    t          t          t          t          |                                                     S r   )r	   xor_operatormaphashitemsr'   s    r$   __hash__zRecord.__hash__n   s$    lCdjjll$;$;<<<r%   t.Iterator[t.Any]c              #     K   t          t                                                                D ]9\  }}t          |t                    r|                     |          |j        |V  :d S r   )	enumerater+   r?   r-   r   r)   r.   )r'   ivr/   s      r$   r?   zRecord.__iter__q   ss      egg..0011 	 	DAq!233 @//22?GGGG	 	r%   r!   t.Union[_K, slice]t.Anyc                H   t          |t                    rQ| j        |         }t                                          |          }|                     t          ||                    S 	 |                     |          }|                     |          S # t          $ r Y d S w xY wr   )
r-   slicer   r+   r,   r/   r>   r(   r0   
IndexError)r'   r!   r   r    r(   r/   s        r$   r,   zRecord.__getitem__w   s     c5!! 	5;s#DWW((--F>>#dF"3"3444	5JJsOOE --e444  	 	 	44	s   )B 
B! B!z<This method is deprecated and will be removed in the future.c                    t          ||          }| j        |         }t          |           |         }|                     t	          ||                    S r   )r]   r   r   r/   r>   )r'   startstopr!   r   r    s         r$   __getslice__zRecord.__getslice__   sI    E4  {3tS!~~c$//000r%   Ndefaultt.Optional[object]c                    	 | j                             t          |                    }n# t          $ r |cY S w xY wd|cxk    rt	          |           k     rn n|                     |          S |S )z Obtain a value from the record by key, returning a default
        value if the key does not exist.

        :param key: a key
        :param default: default value

        :returns: a value
        r   )r   r(   r2   
ValueErrorlenr0   r'   r!   rc   r(   s       r$   getz
Record.get   s    	K%%c#hh//EE 	 	 	NNN	!!!!D		!!!!!--e444Ns   '* 99_Kintc                T   t          |t                    r3d|cxk    rt          | j                  k     rn n|S t	          |          t          |t
                    r=	 | j                            |          S # t          $ r}t          |          |d}~ww xY wt          |          )za Return the index of the given item.

        :param key: a key

        :returns: index
        r   N)
r-   rk   rg   r   r^   r2   r(   rf   KeyError	TypeError)r'   r!   excs      r$   r(   zRecord.index   s     c3 
	!C****#dk*******
S//!S!! 	!-{((--- - - -smm,- C.. s   A9 9
BBBr   c                p    	 |                      |          }| |         S # t          t          f$ r |cY S w xY w)a@   Obtain a single value from the record by index or key. If no
        index or key is specified, the first value is returned. If the
        specified item does not exist, the default value is returned.

        :param key: an index or key
        :param default: default value

        :returns: a single value
        )r(   r^   rm   rh   s       r$   r"   zRecord.value   sM    	JJsOOE ; H% 	 	 	NNN	s    55t.List[str]c                *    t          | j                  S )zM Return the keys of the record.

        :returns: list of key names
        )rG   r   rS   s    r$   r   zRecord.keys   s    
 DK   r%   r   t.List[t.Any]c                    |r_g }|D ]X}	 |                      |          }|                    | |                    4# t          $ r |                    d           Y Uw xY w|S t          |           S )a   Return the values of the record, optionally filtering to
        include only certain values by index or key.

        :param keys: indexes or keys of the items to include; if none
                     are provided, all values will be included

        :returns: list of values
        N)r(   r   rm   rG   r'   r   dr!   rX   s        r$   r    zRecord.values   s      		!A & &&

3A HHT!W%%%%   # # #HHTNNNNN# HDzzs   ;AAc                N    |rng }|D ]g}	                       |          }|                     j        |          |         f           A# t          $ r |                    |df           Y dw xY w|S t	           fdt          t                               D                       S )zu Return the fields of the record as a list of key and value tuples

        :returns: a list of value tuples
        Nc              3  \   K   | ]&}j         |                             |          fV  'd S r   )r   r0   )r8   rX   r'   s     r$   r:   zRecord.items.<locals>.<genexpr>   sP       / / [^T%?%?%B%BC / / / / / /r%   )r(   r   r   rm   rG   rangerg   ru   s   `    r$   rR   zRecord.items   s    
  		A 8 88

3A HHdk!nd1g67777   * * *HHc4[)))))* H / / / /"3t99--/ / / / / 	/s   A		!A-,A-t.Dict[str, t.Any]c                n    t                                          t           | j        |                     S )a]   Return the keys and values of this record as a dictionary,
        optionally including only certain values by index or key. Keys
        provided in the items that are not in the record will be
        inserted with a value of :data:`None`; indexes provided
        that are out of bounds will trigger an :exc:`IndexError`.

        :param keys: indexes or keys of the items to include; if none
                      are provided, all values will be included

        :returns: dictionary of values, keyed by field name

        :raises: :exc:`IndexError` if an out-of-bounds index is specified
        )RecordExporter	transformrH   rR   )r'   r   s     r$   datazRecord.data   s/     ))$ztz4/@*A*ABBBr%   )r   )r1   r2   )rA   rB   r1   rC   )r1   rU   )r!   rZ   r1   r[   r   )r!   r2   rc   rd   r1   r[   )r!   rj   r1   rk   )r   N)r!   rj   rc   rd   r1   r[   )r1   rq   )r   rj   r1   rs   )r   rj   r1   rz   )r<   
__module____qualname____doc____annotations__r   r)   r0   r@   __str__rK   rM   rT   r?   r,   r   rb   ri   r(   r"   r   r    rR   r~   __classcell__)r/   s   @r$   r   r   /   s             
 
 

    
 
 
 
 
 
 G   *& & & &= = =     5 5 5 5 5 5 ZNOO1 1 PO1    $! ! ! !( :>    &! ! ! !   */ / /$C C C C C C C Cr%   r   c                  (    e Zd ZdZed             ZdS )DataTransformerzO Abstract base class for transforming data from one form into
    another.
    c                    dS )zs Transform a value, or collection of values.

        :param x: input value
        :returns: output value
        Nr   )r'   xs     r$   r}   zDataTransformer.transform	  s      r%   N)r<   r   r   r   r   r}   r   r%   r$   r   r     s9            ^  r%   r   )	metaclassc                      e Zd ZdZd ZdS )r|   z@ Transformer class used by the :meth:`.Record.data` method.
    c                    t          |t                    r"                     t          |                    S t          |t                    rY                     t          |j                            |j        j                             t          |j                            fS t          |t                    r                     |j                  g}t          |j                  D ]m\  }}|                                         |j        j                             |                                         |j        |dz                                 n|S t          |t                    r|S t          |t                    r-t!          |          } |t#           j        |                    S t          |t$                    r-t!          |          } |t#           j        |                    S t          |t&                    r8t!          |          } | fd|                                D                       S |S )Nr   c              3  L   K   | ]\  }}|                     |          fV  d S r   )r}   )r8   krY   r'   s      r$   r:   z+RecordExporter.transform.<locals>.<genexpr>-  s8      DD$!Q4>>!,,-DDDDDDr%   )r-   r   r}   rH   r   
start_noder/   r<   end_noder   rW   relationshipsr   nodesr2   r   typerP   r   r   rR   )r'   r   pathrX   relationshiptyps   `     r$   r}   zRecordExporter.transform  s   a 	>>$q''***<(( 	NN4#5#566K(NN4
#3#3446 6 4   	NN1<001D#,Q_#=#= < <<DNN<+A+JKKLLLDNN171q5>::;;;;K3 	H8$$ 
	q''C3s4>1--...3 	q''C3s4>1--...7## 	q''C3DDDD!''))DDDDDDHr%   N)r<   r   r   r   r}   r   r%   r$   r|   r|     s-             r%   r|   c                      e Zd ZdZd Zd ZdS )RecordTableRowExporterz;Transformer class used by the :meth:`.Result.to_df` method.c                     t          |t                    sJ t          |          } | fd|                                D                       S )Nc              3     K   | ]]\  }}                     ||                    d d                              dd                                                    D ]}|V  ^dS )\\\.\.prefixN
_transformreplacerR   )r8   r   rY   itemr'   s       r$   r:   z3RecordTableRowExporter.transform.<locals>.<genexpr>8  s        q!#4!8!8!@!@e!L!L  /    UWW	         r%   )r-   r   r   rR   )r'   r   r   s   `  r$   r}   z RecordTableRowExporter.transform5  sf    !W%%%%%1ggs     wwyy     	r%   c                H    t          |t                    rKdz  |j        dz  |j        i}|                    fd|                                D                        |S t          |t                    rndz  |j        dz  |j        j        dz  |j        j        dz  |j	        j
        i}|                    fd|                                D                        |S t          |t                    st          |t                    r|iS t          |t                    r)t           fd	t          |          D                       S t          |t                     r9t#          |          } | fd
|                                D                       S |iS )Nz%s().element_idz%s().labelsc              3  0   K   | ]\  }}d ||fV  dS )z().prop.Nr   r8   r   rY   r   s      r$   r:   z4RecordTableRowExporter._transform.<locals>.<genexpr>D  7      OOTQ&&&!!4a8OOOOOOr%   z%s->.element_idz%s->.start.element_idz%s->.end.element_idz	%s->.typec              3  0   K   | ]\  }}d ||fV  dS )z->.prop.Nr   r   s      r$   r:   z4RecordTableRowExporter._transform.<locals>.<genexpr>M  r   r%   c              3     K   | ]:\  }}                     |d |fz                                            D ]}|V  ;dS )z%s[].%ir   N)r   rR   )r8   rX   rY   r   r   r'   s       r$   r:   z4RecordTableRowExporter._transform.<locals>.<genexpr>R  s|        Aq OOi61+5 ,  %''         r%   c           
   3     K   | ]b\  }}                     |d |                    dd                              dd                                                    D ]}|V  cdS )z{}.r   r   r   r   r   Nr   )r8   r   rY   r   r   r'   s       r$   r:   z4RecordTableRowExporter._transform.<locals>.<genexpr>[  s        Aq OO666199T63J3J5<WS%5H5H4I J ,   %''         r%   )r-   r   
element_idlabelsupdaterR   r   r   r   r/   r<   r   r2   r   rH   rW   r   r   )r'   r   r   resr   s   ` `  r$   r   z!RecordTableRowExporter._transform>  s   a %	!F*AL&C JJOOOOQWWYYOOOOOOJ<(( 	!F*AL'&0!,2I%.
0Ef$ak&:	C JJOOOOQWWYYOOOOOOJ4   	Jq#$6$6 	A;8$$ 	     %aLL      7## 	q''C3     GGII      A;r%   N)r<   r   r   r   r}   r   r   r%   r$   r   r   2  s8        EE  & & & & &r%   r   )'
__future__r   typingrE   abcr   r   collections.abcr   r   r   	functoolsr	   operatorr
   rO   _codec.hydrationr   _confr   _metar   
exceptionsr   graphr   r   r   TypeVarr   Unionrk   r2   rj   r   r   r   r|   r   r   r%   r$   <module>r      s  " # " " " " "                    
       ( ( ( ( ( ( 3 3 3 3 3 3             ) ) ) ) ) )          QYt__WS#XRC RC RC RC RCUG RC RC RCj            _   @2 2 2 2 2_ 2 2 2 2 2r%   