U o^@sddlZddlmZmZmZmZmZddlmZddl m Z m Z ddl m Z mZmZGdddeZGdd d eZd d Zdd lmZd dZdddZdS)N)StringSetNoneSetAliasSequence) Serialisable)REL_NS PKG_REL_NS)Element fromstringtostringc@sNeZdZdZdZeZeZedZ eddZ eddZ edZ d ddZ dS) Relationshipz'Represents many kinds of relationships.TargetT) allow_noneIdNcCs0|dk rdt|}||_||_||_||_dS)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})formatrTyper TargetModer)selfrrtyperrry/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/openpyxl/openpyxl/packaging/relationship.py__init__$s  zRelationship.__init__)NNNNN)__name__ __module__ __qualname____doc__tagnamerrrrtargetrridrrrrrr s  r c@sTeZdZdZeedZdddZddZdd Zd d Z d d Z ddZ ddZ dS)RelationshipList Relationships)Z expected_typercCs ||_dSN)r )rr rrrr>szRelationshipList.__init__cCs8|jdd}|||js.dt||_||_dS)NrId{0})r appendrrlen)rvaluevaluesrrrr$Bs  zRelationshipList.appendcCs t|jSr")r%r rrrr__len__JszRelationshipList.__len__cCs t|jSr")boolr r(rrr__bool__NszRelationshipList.__bool__ccs |jD]}|j|kr|VqdS)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_typerrrrfindRs  zRelationshipList.findcCs0|jD]}|j|kr|Sqtd|dS)NzUnknown relationship: {0})r rKeyErrorr)rkeyr-rrr __getitem__]s   zRelationshipList.__getitem__cCsFtdtd}t|jdD](\}}|js2d||_||q|S)Nr!)xmlnsr#)r r enumerater rrr$to_tree)rtreeidxrelrrrr5ds   zRelationshipList.to_treeN)r) rrrrrr rr$r)r+r.r1r5rrrrr 7s   r cCs&t|\}}t|dd|}|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.) Z_relsz{0}.rels) posixpathsplitjoinr)pathfolderobjfilenamerrr get_rels_pathnsr@)warnc Cs||}t|}zt|}Wn,tk rLd|}t|t}YnXt|}t |d}|j D]J}|j dkr~qlql|j dr|j dd|_ qlt||j } t| |_ ql|S)zl Normalise dependency file paths to absolute ones Relative paths are relative to parent object z+{0} contains invalid dependency definitionsrZExternal/r3N)readr r from_tree TypeErrorrrAr9dirnamer:r rr startswithr;normpath) archiver?srcnodeZrelsmsgr=parentr-pthrrrget_dependents|s$       rOc Cst||gstd|dk r&||}n,zt||j}Wntk rPYdSX|j}||}t|}| |}t |} zt || |_ Wnt k rg|_ YnX|S)z4 Get related object based on id or rel_type z.Either the id or the content type are requiredN)any ValueErrornextr.Zrel_type StopIterationrrCr rDr@rOdepsr/) rIrTrclsr8r<rJr6r>Z rels_pathrrrget_rels$     rV)NN)r9Zopenpyxl.descriptorsrrrrrZ!openpyxl.descriptors.serialisablerZopenpyxl.xml.constantsrr Zopenpyxl.xml.functionsr r r r r r@warningsrArOrVrrrrs  7