
    Mwg                         d dl 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 d dlmZmZ  G d d	e      Z G d
 de
      Zd Zd ZddZy)    N)warn)StringAliasSequence)Serialisable)ElementList)REL_NS
PKG_REL_NS)Element
fromstringc                       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y)	Relationshipz'Represents many kinds of relationships.TargetT)
allow_noneIdNc                 l    |dj                  t        |      }|| _        || _        || _        || _        y)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         V/var/www/horilla/myenv/lib/python3.12/site-packages/openpyxl/packaging/relationship.py__init__zRelationship.__init__"   s8     ##FD1D	$    )NNNNN)__name__
__module____qualname____doc__tagnamer   r   r   r   targetr   r   idr    r   r   r   r      sT    1G8DXF8_F4(J	4	 B	tB  r   r   c                   B     e Zd ZdZeZ fdZd Zd Zd Z	 fdZ
 xZS )RelationshipListRelationshipsc                 d    t         |   |       |j                  sdt        |        |_        y y )NrId)superappendr   len)r   value	__class__s     r   r)   zRelationshipList.append;   s-    uxxSYK(EH r   c              #   B   K   | D ]  }|j                   |k(  s|  yw)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   content_typers      r   findzRelationshipList.findA   s(       	Avv%	s   c                 j    | D ]  }|j                   |k(  s|c S  t        dj                  |            )NzUnknown relationship: {0})r   KeyErrorr   )r   keyr/   s      r   getzRelationshipList.getL   s:     	Atts{	 299#>??r   c                 B    | D ci c]  }|j                   | c}S c c}w )z,Return a dictionary of relations keyed by id)r!   )r   r/   s     r   to_dictzRelationshipList.to_dictS   s     $%1Q%%%s   c                 P    t         |          }|j                  dt               |S )Nxmlns)r(   to_treesetr
   )r   treer,   s     r   r9   zRelationshipList.to_treeX   s"    w *%r   )r   r   r   r   r   expected_typer)   r0   r4   r6   r9   __classcell__)r,   s   @r   r$   r$   5   s,    G M)@&
 r   r$   c                     t        j                  |       \  }}t        j                  |ddj                  |            }|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_pathrG   ^   s8     //$'KFC~~fgz/@/@/EFHOr   c                 0   | j                  |      }t        |      }	 t        j                  |      }t        j                  |      }t        j                  |      d   }|D ]|  }|j                  dk(  r|j                  j                  d      r|j                  dd |_        Ct        j                  ||j                        }	t        j                  |	      |_        ~ |S # t        $ r) dj                  |      }t        |       t               }Y w xY w)zl
    Normalise dependency file paths to absolute ones

    Relative paths are relative to parent object
    z+{0} contains invalid dependency definitionsr   External/   N)readr   r$   	from_tree	TypeErrorr   r   r@   dirnamerA   r   r    
startswithrB   normpath)
archiverF   srcnoderelsmsgrD   parentr/   pths
             r   get_dependentsrY   j   s     ,,x
 Cc?D"))$/
 x(F__V$Q'F /<<:%XX  %xx|AH..2C ))#.AH/ K  ";BB8LS	!"s   C# #/DDc                    t        ||g      st        d      ||j                  |      }n%	 t        |j	                  |j
                              }|j                  }| j                  |      }t        |      }|j                  |      }t        |      }		 t        | |	      |_        |S # t        $ r Y yw xY w# t        $ r g |_        Y |S w xY w)z4
    Get related object based on id or rel_type
    z.Either the id or the content type are requiredN)any
ValueErrorr4   nextr0   rel_typeStopIterationr    rL   r   rM   rG   rY   depsr2   )
rR   r`   r!   clsrelrC   rS   r;   rE   	rels_paths
             r   get_relrd      s     Cy>IJJ	~hhrl	tyy./C ::D
,,t
Cc?D
--
Cd#I!'95 J  		  Js#   $B* B9 *	B65B69CC)NN)r@   warningsr   openpyxl.descriptorsr   r   r   !openpyxl.descriptors.serialisabler   openpyxl.descriptors.containerr   openpyxl.xml.constantsr	   r
   openpyxl.xml.functionsr   r   r   r$   rG   rY   rd   r"   r   r   <module>rk      sP      
 ; 6 5< @&{ &R	6r   