
    fh                         d dl m Z  d dlmZ  ee          ZddlmZ ddl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mZ eefZ G d
 de          ZdS )    )copy)kwlist   )
Descriptor)MetaSerialisable)SequenceNestedSequenceMultiSequencePart)
namespaced)safe_string)Element	localnamec                       e Zd ZdZdZdZdZdZdZe	d             Z
dZed             ZddZd Zd Zd	 Zd
 Zd Zd Zd ZdS )Serialisablea  
    Objects can serialise to XML their attributes and child objects.
    The following class attributes are created by the metaclass at runtime:
    __attrs__ = attributes
    __nested__ = single-valued child treated as an attribute
    __elements__ = child elements
    Nr   c                     t           N)NotImplementedError)selfs    X/var/www/histauto/venv/lib/python3.11/site-packages/openpyxl/descriptors/serialisable.pytagnamezSerialisable.tagname(   s    !"    c                 P   t          |j                  }| j        D ]\  }}||v r||         ||<   ||= t          |          D ]^}|                    d          r||= |t
          v r||         |d|z   <   ||= 6d|v r$|                    dd          }||         ||<   ||= _|j        rd| j        v r
|j        |d<   |D ]`}t          |          }|t
          v rd|z   }t          | |d          }|t          |t                    rIt          |d          r|                    |          }	n7t          |j        d          r|j                            |          }	n|j        }	t          |t                     r|	||<   t          |t"                    r3|                    |g            ||                             |	           	t          |t(                    r=|                    |j        g            ||j                                     |	           [|	||<   b | di |S )z(
        Create object from XML
        {_-	attr_textN	from_tree )dictattrib__namespaced__list
startswithKEYWORDSreplacetext	__attrs__r   getattr
isinstancepropertyhasattrr   expected_typer	   r   
setdefaultappendr
   store)
clsnoder    keynsneltagdescobjs
             r   r   zSerialisable.from_tree.   sf    dk"") 	 	GCV||$Rjs2J << 		  		 C~~c""  3KK$*3KsSy!3KKKKS))"3Kq	3K9 	,55"&)F; 	" 	"BB--ChCi3T**D|z$99|t[)) 	"nnR((4-{;; ",66r::CC 'C$// 	"!sD(++ "!!#r***s""3''''D"344 "!!$*b111tz"))#....!ss}}V}}r   c                     || j         }|                    d          r
|dd          }t          | |          }t          | d          t	          |           }| j        D ]\  }}||v r||         ||<   ||= t          ||          }d| j        v r"t          t          | d                    |_	        | j
        D ]Ot          | j        d           }t          |           }	t          |d          rt          |	d          r|j        |	_        t          |	t                    rt          |t                     r|	s|                    |	          g}
nHt          |t$                    r$| j        |_        |                    |	          }
nfd|	D             }
|
D ]}|                    |           | j        v r|                    |	          }n|	#|	                              }||                    |           Q|S )Nr   r   	namespacer   c              3   D   K   | ]}|                               V  d S r   )to_tree).0v	child_tagr:   s     r   	<genexpr>z'Serialisable.to_tree.<locals>.<genexpr>   s1      JJQYYy)<<JJJJJJr   )r   r#   r   r(   r   r!   r   r'   r   r&   __elements__	__class__r+   r:   r)   	seq_typesr	   r<   r   idx_baser.   
__nested__)r   r   idxr:   attrsr2   r3   r5   r7   r8   nodesr1   r?   s      `        @r   r<   zSerialisable.to_treej   sC   ?lG c"" 	"abbkGT7I66D+y99	T

* 	 	GCe||!#Jb	#JWe$$$.((!'$"<"<==BG* 	$ 	$I4>9d;;D$	**Ct[)) /gc;.G.G / $#y)) $dN33 
K ! !\\)S)DDEEEh// K$(MDM!\\)S)DDEEJJJJJcJJJE! $ $DIIdOOOO$ //<<	3	BBDD[;;y11D#IIdOOO	r   c              #   @  K   | j         D ]}t          | |          }|                    d          r|dd          }nF|dk    r@d|v r<t          | j        |          }t          |dd          r|                    dd          }|dk    r||t          |          fV  d S )Nr   r   r   
hyphenatedFr   )r'   r(   r#   rB   r%   r   )r   attrvaluer7   s       r   __iter__zSerialisable.__iter__   s      N 		/ 		/DD$''Es## 2ABBx$$t~t444u55 2<<S11D{""u'8K......		/ 		/r   c                     | j         |j         k    sdS t          |           t          |          k    sdS | j        D ]'}t          | |          t          ||          k    r dS (dS )NFT)rB   r   rA   r(   )r   otherr5   s      r   __eq__zSerialisable.__eq__   st    ~005dtE{{**5# 	 	BtR  GE2$6$666uu 7tr   c                     | |k     S r   r   )r   rO   s     r   __ne__zSerialisable.__ne__   s    5=  r   c           	         d                     | j        | j        j                  }g }| j        | j        z   D ]_}t          | |          }t          |t                    rd }|	                    d                     |t          |                               `d                    |          }d                    ||g          S )Nz<{0}.{1} object>
Parameters:z{0}={1}z, 
)format
__module__rB   __name__r'   rA   r(   r)   r   r.   reprjoin)r   sargskr>   s        r   __repr__zSerialisable.__repr__   s    ,33ON#
 
 $"33 	7 	7Aa  A!Z(( KK
))!T!WW556666zz$zz1d)$$$r   c                     g }| j         | j        z   D ]K}t          | |          }t          |t                    rt          |          }|                    |           Lt          t          |                    S r   )r'   rA   r(   r)   r"   tupler.   hash)r   fieldsrK   vals       r   __hash__zSerialisable.__hash__   su    NT%66 	 	D$%%C#t$$ !CjjMM#E&MM"""r   c                 T   t          |           t          |          k    rt          d          i }| j        D ]%}t          | |          pt          ||          ||<   &| j        D ]6}t          | |          }t          ||          }|r|r	||z   ||<   /|p|||<   7 | j        di |S )Nz+Cannot combine instances of different typesr   )type	TypeErrorr'   r(   rA   rB   )r   rO   valsrK   r5   abs          r   __add__zSerialisable.__add__   s    ::e$$IJJJN 	E 	ED t,,Dt0D0DDJJ# 	" 	"Bb!!Ar""A "Q "q5R6Rt~%%%%%r   c                     |                      d          }| j                            |          }| j        D ]A}|| j        | j        z   vr.t          t          | |                    }t          |||           B|S )Ndummy)r   )	r<   rB   r   __dict__r'   rA   r   r(   setattr)r   xmlcpr\   r>   s        r   __copy__zSerialisable.__copy__   s    ll7l++^%%c** 	" 	"A)::::q))**Aq!!!	r   )NNN)rW   rV   __qualname____doc__r'   rE   rA   r!   rD   r*   r   r:   classmethodr   r<   rM   rP   rR   r]   rc   rj   rq   r   r   r   r   r      s          IJLNH# # X# I8 8 [8v3 3 3 3l
/ 
/ 
/  ! ! !% % % # # #& & & 	 	 	 	 	r   r   )	metaclassN)r   keywordr   	frozensetr$    r   r   sequencer   r	   r
   r:   r   openpyxl.compatr   openpyxl.xml.functionsr   r   r"   r_   rC   r   r   r   r   <module>r|      s.              9V                     
 " ! ! ! ! ! ' ' ' ' ' '       
 5M	X X X X X- X X X X X Xr   