
    i"                        S r SSKJr  SSKJrJrJrJr  SSKJ	r
  SSKJrJr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  \(       a  SSKJr  SSKJr  SSKJr  SSKJr   " S S5      r  " S S5      r!g)z8Objects that implement reading and writing OPC packages.    )annotations)IOTYPE_CHECKINGIteratorcast)RELATIONSHIP_TYPE)PACKAGE_URIPackURI)PartFactory)CorePropertiesPart)PackageReader)PackageWriter)Relationships)lazyproperty)Self)CoreProperties)Part)_Relationshipc                      \ rS rSrSrS r\SS j5       rSS jrSS jr	SSS jjr
\S 5       rSS	 jr\SS
 j5       rSS jr\SS j5       rSS jr\S 5       rSS jr\SS j5       rSrg)
OpcPackage   zMain API class for |python-opc|.

A new instance is constructed by calling the :meth:`open` class method with a path
to a package file or file-like object containing one.
c                    g)zuEntry point for any post-unmarshaling processing.

May be overridden by subclasses without forwarding call to super.
N selfs    P/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/docx/opc/package.pyafter_unmarshalOpcPackage.after_unmarshal   s     	    c                .    U R                   R                  $ )zd|CoreProperties| object providing read/write access to the Dublin Core
properties for this document.)_core_properties_partcore_propertiesr   s    r   r"   OpcPackage.core_properties(   s     ))999r   c              #  T   ^#     S     SU4S jjjmT" U 5       H  nUv   M	     g7f)z{Generate exactly one reference to each relationship in the package by
performing a depth-first traversal of the rels graph.Nc              3     >#    Uc  / OUnU R                   R                  5        HS  nUv   UR                  (       a  M  UR                  nX1;   a  M-  UR	                  U5        UnT" XA5       H  nUv   M	     MU     g 7fNrelsvaluesis_externaltarget_partappend)sourcevisitedrelpart
new_source	walk_relss        r   r2   'OpcPackage.iter_rels.<locals>.walk_rels2   so      $ObG{{))+	???t$!
$Z9CI : ,s   A:A=r&   )r-   zOpcPackage | Partr.   zlist[Part] | NonereturnIterator[_Relationship]r   )r   r/   r2   s     @r   	iter_relsOpcPackage.iter_rels.   sD     
 EI	%	0A	$	 	  T?CI #s   %(c              #  F   ^#    / 4U4S jjmT" U 5       H  nUv   M	     g7f)z{Generate exactly one reference to each of the parts in the package by
performing a depth-first traversal of the rels graph.c              3     >#    U R                   R                  5        HS  nUR                  (       a  M  UR                  nX1;   a  M)  UR	                  U5        Uv   UnT" XA5       H  nUv   M	     MU     g 7fr&   r'   )r-   r.   r/   r0   r1   
walk_partss        r   r:   )OpcPackage.iter_parts.<locals>.walk_partsI   sb     {{))+???t$
!
&z;DJ < ,s   A3A6Nr   )r   r0   r:   s     @r   
iter_partsOpcPackage.iter_partsE   s&      (* 	 t$DJ %s   !c                :    U R                   R                  XX45      $ )aU  Return newly added |_Relationship| instance of `reltype` between this part
and `target` with key `rId`.

Target mode is set to ``RTM.EXTERNAL`` if `is_external` is |True|. Intended for
use during load from a serialized package, where the rId is well known. Other
methods exist for adding a new relationship to the package during processing.
)r(   add_relationship)r   reltypetargetrIdr*   s        r   load_relOpcPackage.load_relY   s     yy))'3LLr   c                @    U R                  [        R                  5      $ )zReturn a reference to the main document part for this package.

Examples include a document part for a WordprocessingML package, a presentation
part for a PresentationML package, or a workbook part for a SpreadsheetML
package.
)part_related_byRTOFFICE_DOCUMENTr   s    r   main_document_partOpcPackage.main_document_partc   s     ##B$6$677r   c                    U R                  5        Vs1 s H  o"R                  iM     nn[        S[        U5      S-   5       H  nX-  nXS;  d  M  [	        U5      s  $    gs  snf )ak  Return a |PackURI| instance representing partname matching `template`.

The returned part-name has the next available numeric suffix to distinguish it
from other parts of its type. `template` is a printf (%)-style template string
containing a single replacement item, a '%d' to be used to insert the integer
portion of the partname. Example: "/word/header%d.xml"
      N)r<   partnamerangelenr
   )r   templater0   	partnamesncandidate_partnames         r   next_partnameOpcPackage.next_partnamem   s]     04/@A/@t]]/@	Aq#i.1,-A!)!2122 . Bs   A c                t    [         R                  " U5      nU " 5       n[        R                  X#[        5        U$ )zGReturn an |OpcPackage| instance loaded with the contents of `pkg_file`.)r   	from_fileUnmarshaller	unmarshalr   )clspkg_file
pkg_readerpackages       r   openOpcPackage.open{   s0     #,,X6
%zK@r   c                8    U R                   R                  U5      $ )zReturn part to which this package has a relationship of `reltype`.

Raises |KeyError| if no such relationship is found and |ValueError| if more than
one such relationship is found.
)r(   part_with_reltype)r   r@   s     r   rF   OpcPackage.part_related_by   s     yy**733r   c                4    [        U R                  5       5      $ )zJReturn a list containing a reference to each of the parts in this package.)listr<   r   s    r   partsOpcPackage.parts   s     DOO%&&r   c                P    U R                   R                  X!5      nUR                  $ )zReturn rId key of new or existing relationship to `part`.

If a relationship of `reltype` to `part` already exists, its rId is returned. Otherwise a
new relationship is created and that rId is returned.
)r(   
get_or_addrB   )r   r0   r@   r/   s       r   	relate_toOpcPackage.relate_to   s!     ii""71wwr   c                4    [        [        R                  5      $ )zlReturn a reference to the |Relationships| instance holding the collection of
relationships for this package.)r   r	   baseURIr   s    r   r(   OpcPackage.rels   s     [0011r   c                    U R                    H  nUR                  5         M     [        R                  " XR                  U R                   5        g)z^Save this package to `pkg_file`.

`pkg_file` can be either a file-path or a file-like object.
N)rf   before_marshalr   writer(   )r   r\   r0   s      r   saveOpcPackage.save   s6    
 JJD! Hii<r   c                     [        [        U R                  [        R                  5      5      $ ! [
         a;    [        R                  " U 5      nU R                  U[        R                  5        Us $ f = f)z|CorePropertiesPart| object related to this package.

Creates a default core properties part if one is not present (not common).
)r   r   rF   rG   CORE_PROPERTIESKeyErrordefaultrj   )r   core_properties_parts     r   r!    OpcPackage._core_properties_part   sa    	(*D,@,@ASAS,TUU 	(#5#=#=d#C NN/1C1CD''	(s   ,/ AA43A4r   N)r4   r   )r4   r5   )r4   zIterator[Part])F)r@   strrA   z
Part | strrB   rz   r*   bool)rQ   rz   r4   r
   )r\   str | IO[bytes]r4   r   )r@   rz   r4   r   )r4   z
list[Part])r0   r   r@   rz   )r\   r|   )r4   r   )__name__
__module____qualname____firstlineno____doc__r   propertyr"   r6   r<   rC   rI   rU   classmethodr_   rF   rf   rj   r   r(   rr   r!   __static_attributes__r   r   r   r   r      s     : :
.(M 8 83  4 ' ' 2 2
= 
( 
(r   r   c                  H    \ rS rSrSr\S 5       r\S 5       r\S 5       rSr	g)rY      zHHosts static methods for unmarshalling a package from a |PackageReader|.c                    [         R                  XU5      n[         R                  XU5        UR                  5        H  nUR	                  5         M     UR	                  5         g)zConstruct graph of parts and realized relationships based on the contents of
`pkg_reader`, delegating construction of each part to `part_factory`.

Package relationships are added to `pkg`.
N)rY   _unmarshal_parts_unmarshal_relationshipsr)   r   )r]   r^   part_factoryrf   r0   s        r   rZ   Unmarshaller.unmarshal   sN     --j<P--j5ILLND  " #!r   c                V    0 nU R                  5        H  u  pEpgU" XEXgU5      X4'   M     U$ )zReturn a dictionary of |Part| instances unmarshalled from `pkg_reader`, keyed
by partname.

Side-effect is that each part in `pkg_reader` is constructed using
`part_factory`.
)iter_sparts)r]   r^   r   rf   rN   content_typer@   blobs           r   r   Unmarshaller._unmarshal_parts   s8     5?5K5K5M1HG*87RYZEO 6Nr   c                   U R                  5        Hm  u  p4US:X  a  UOX#   nUR                  (       a  UR                  OX$R                     nUR	                  UR
                  XdR                  UR                  5        Mo     g)zAdd a relationship to the source object corresponding to each of the
relationships in `pkg_reader` with its target_part set to the actual target part
in `parts`./N)
iter_srelsr*   
target_reftarget_partnamerC   r@   rB   )r]   r^   rf   
source_urisrelr-   rA   s          r   r   %Unmarshaller._unmarshal_relationships   se    
 !+ 5 5 7J *c 1Wu7HF(,(8(8T__eDXDX>YFOODLL&((D<L<LM !8r   r   N)
r}   r~   r   r   r   staticmethodrZ   r   r   r   r   r   r   rY   rY      sA    R
" 
" 
 
 N Nr   rY   N)"r   
__future__r   typingr   r   r   r   docx.opc.constantsr   rG   docx.opc.packurir	   r
   docx.opc.partr   docx.opc.parts.corepropsr   docx.opc.pkgreaderr   docx.opc.pkgwriterr   docx.opc.relr   docx.sharedr   typing_extensionsr   docx.opc.corepropsr   r   r   r   rY   r   r   r   <module>r      sQ    > " 4 4 6 1 % 7 , , & $&1"*[( [(|%N %Nr   