
    ddb                         d dl Z d dl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  G d de          Z G d d	e          Zd
 Zd dlmZ d ZddZdS )    N)StringSetNoneSetAliasSequence)Serialisable)REL_NS
PKG_REL_NS)Element
fromstringtostringc                       e Zd ZdZd Z e            Z e            Z ed          Z	 ed          Z
 ed          Z ed          Z	 	 	 	 	 ddZdS )	Relationshipz'Represents many kinds of relationships.TargetT)
allow_noneIdNc                 x    |d                     t          |          }|| _        || _        || _        || _        dS )z
        `type` can be used as a shorthand with the default relationships namespace
        otherwise the `Type` must be a fully qualified URL
        Nz{0}/{1})formatr	   Typer   
TargetModer   )selfr   r   typer   r   s         ?lib/python3.11/site-packages/openpyxl/packaging/relationship.py__init__zRelationship.__init__$   sA      	2##FD11D	$    )NNNNN)__name__
__module____qualname____doc__tagnamer   r   r   r   targetr   r   idr    r   r   r   r      s        11G688DVXXFU8__F4(((J	4	 	 	 B	tB       r   r   c                   V    e Zd ZdZ ee          ZddZd Zd Zd Z	d Z
d	 Zd
 ZdS )RelationshipListRelationships)expected_typer#   c                     || _         d S N)r   )r   r   s     r   r   zRelationshipList.__init__>   s    (r   c                     | j         d d          }|                    |           |j        s'd                    t	          |                    |_        || _         d S )NrId{0})r   appendr   r   len)r   valuevaluess      r   r,   zRelationshipList.appendB   sV    "111%ex 	6F55EH"r   c                 *    t          | j                  S r)   )r-   r   r   s    r   __len__zRelationshipList.__len__J   s    4$%%%r   c                 *    t          | j                  S r)   )boolr   r1   s    r   __bool__zRelationshipList.__bool__N   s    D%&&&r   c              #   <   K   | j         D ]}|j        |k    r|V  dS )z
        Find relationships by content-type
        NB. these content-types namespaced objects and different to the MIME-types
        in the package manifest :-(
        N)r   r   )r   content_typers      r   findzRelationshipList.findR   s=       " 	 	Av% 	 	r   c                 x    | j         D ]}|j        |k    r|c S t          d                    |                    )NzUnknown relationship: {0})r   r   KeyErrorr   )r   keyr8   s      r   __getitem__zRelationshipList.__getitem__]   sM    " 	 	Ats{ 299#>>???r   c                     t          dt                    }t          | j        d          D ]M\  }}|j        sd                    |          |_        |                    |                                           N|S )Nr&   )xmlns   r+   )r   r
   	enumerater   r   r   r,   to_tree)r   treeidxrels       r   rB   zRelationshipList.to_treed   ss    j999!$"3Q77 	' 	'HC6 .!--KK&&&&r   N)r#   )r   r   r   r    r   r   r   r,   r2   r5   r9   r=   rB   r#   r   r   r%   r%   7   s        G8,777L) ) ) )# # #& & &' ' '  @ @ @    r   r%   c                     t          j        |           \  }}t          j        |dd                    |                    }|S )z
    Convert relative path to absolutes that can be loaded from a zip
    archive.
    The path to be passed in is that of containing object (workbook,
    worksheet, etc.)
    _relsz{0}.rels)	posixpathsplitjoinr   )pathfolderobjfilenames       r   get_rels_pathrO   n   s=     /$''KFC~fgz/@/@/E/EFFHOr   )warnc                 V   |                      |          }t          |          }	 t                              |          }nB# t          $ r5 d                    |          }t          |           t                      }Y nw xY wt          j        |          }t          j	        |          d         }|j
        D ]p}|j        dk    r|j                            d          r|j        dd         |_        =t          j        ||j                  }	t          j        |	          |_        q|S )zl
    Normalise dependency file paths to absolute ones

    Relative paths are relative to parent object
    z+{0} contains invalid dependency definitionsr   External/r@   N)readr   r%   	from_tree	TypeErrorr   rP   rH   dirnamerI   r   r   r!   
startswithrJ   normpath)
archiverN   srcnoderelsmsgrL   parentr8   pths
             r   get_dependentsra   |   s#    ,,x
 
 Cc??D"))$// " " ";BB8LLS			!!" x((F_V$$Q'F / /<:% 	/X  %% 	/x|AHH.22C )#..AHHKs   A <B ?B c                    t          ||g          st          d          |	||         }n:	 t          |                    |j                            }n# t
          $ r Y dS w xY w|j        }|                     |          }t          |          }|	                    |          }t          |          }		 t          | |	          |_        n# t          $ r
 g |_        Y nw xY w|S )z4
    Get related object based on id or rel_type
    z.Either the id or the content type are requiredN)any
ValueErrornextr9   rel_typeStopIterationr!   rT   r   rU   rO   ra   depsr;   )
rZ   rh   r"   clsrE   rK   r[   rC   rM   	rels_paths
             r   get_relrk      s    Cy>> KIJJJ	 2h	tyy..//CC 	 	 	FF	 :D
,,t

Cc??D
--

Cd##I!'955    Js#   'A 
A#"A#6C C C )NN)rH   openpyxl.descriptorsr   r   r   r   r   !openpyxl.descriptors.serialisabler   openpyxl.xml.constantsr	   r
   openpyxl.xml.functionsr   r   r   r   r%   rO   warningsrP   ra   rk   r#   r   r   <module>rq      s]                    ; : : : : : 5 5 5 5 5 5 5 5             <   @4 4 4 4 4| 4 4 4n	 	 	        6     r   