
    h4                       S r SSKJr  SSKrSSKJrJrJrJrJ	r	J
r
JrJr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 " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\\\\4   5      r\" S5      r  " S S\\    5      r!S$S jr" " S S5      r# " S S5      r$ " S  S!5      r% " S" S#5      r&g)%zObjects shared by docx modules.    )annotationsN)	TYPE_CHECKINGAnyCallableGenericIteratorListTupleTypeVarcast)XmlPart)BaseOxmlElement)	StoryPartc                      \ rS rSrSrSrSrSrSrSr	SS jr
\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       rSrg)Length   zBase class for length constructor classes Inches, Cm, Mm, Px, and Emu.

Behaves as an int count of English Metric Units, 914,400 to the inch, 36,000 to the
mm. Provides convenience unit conversion methods in the form of read-only
properties. Immutable.
i i@~ i  i1  i{  c                ,    [         R                  X5      $ N)int__new__clsemus     =/var/www/html/env/lib/python3.13/site-packages/docx/shared.pyr   Length.__new__'   s    {{3$$    c                2    U [        U R                  5      -  $ )z7The equivalent length expressed in centimeters (float).)float_EMUS_PER_CMselfs    r   cm	Length.cm*        eD--...r   c                    U $ )z>The equivalent length expressed in English Metric Units (int). r    s    r   r   
Length.emu/   s	     r   c                2    U [        U R                  5      -  $ )z2The equivalent length expressed in inches (float).)r   _EMUS_PER_INCHr    s    r   inchesLength.inches4   s     eD//000r   c                2    U [        U R                  5      -  $ )z7The equivalent length expressed in millimeters (float).)r   _EMUS_PER_MMr    s    r   mm	Length.mm9   r$   r   c                2    U [        U R                  5      -  $ )z Floating point length in points.)r   _EMUS_PER_PTr    s    r   pt	Length.pt>   r$   r   c                V    [        [        U [        U R                  5      -  5      5      $ )z/The equivalent length expressed in twips (int).)r   roundr   _EMUS_PER_TWIPr    s    r   twipsLength.twipsC   s$     5d&9&9 ::;<<r   r&   Nr   r   )__name__
__module____qualname____firstlineno____doc__r)   r   r-   r1   r6   r   propertyr"   r   r*   r.   r2   r7   __static_attributes__r&   r   r   r   r      s     NLLLN% / /   1 1 / / / / = =r   r   c                  "    \ rS rSrSrSS jrSrg)InchesI   zKConvenience constructor for length in inches, e.g. ``width = Inches(0.5)``.c                d    [        U[        R                  -  5      n[        R                  X5      $ r   )r   r   r)   r   )r   r*   r   s      r   r   Inches.__new__L   s&    &60001~~c''r   r&   N)r*   r   r:   r;   r<   r=   r>   r   r@   r&   r   r   rB   rB   I   s
    U(r   rB   c                  "    \ rS rSrSrSS jrSrg)CmQ   zLConvenience constructor for length in centimeters, e.g. ``height = Cm(12)``.c                d    [        U[        R                  -  5      n[        R                  X5      $ r   )r   r   r   r   )r   r"   r   s      r   r   
Cm.__new__T   &    "v***+~~c''r   r&   N)r"   r   rF   r&   r   r   rH   rH   Q   s
    V(r   rH   c                  "    \ rS rSrSrSS jrSrg)EmuY   zYConvenience constructor for length in English Metric Units, e.g. ``width =
Emu(457200)``.c                @    [         R                  U [        U5      5      $ r   )r   r   r   r   s     r   r   Emu.__new__]   s    ~~c3s8,,r   r&   Nr9   rF   r&   r   r   rN   rN   Y   s    -r   rN   c                  "    \ rS rSrSrSS jrSrg)Mma   zNConvenience constructor for length in millimeters, e.g. ``width = Mm(240.5)``.c                d    [        U[        R                  -  5      n[        R                  X5      $ r   )r   r   r-   r   )r   r.   r   s      r   r   
Mm.__new__d   rL   r   r&   N)r.   r   rF   r&   r   r   rS   rS   a   s
    X(r   rS   c                  "    \ rS rSrSrSS jrSrg)Pti   z:Convenience value class for specifying a length in points.c                d    [        U[        R                  -  5      n[        R                  X5      $ r   )r   r   r1   r   )r   pointsr   s      r   r   
Pt.__new__l   s&    &6.../~~c''r   r&   N)r[   r   rF   r&   r   r   rX   rX   i   s
    D(r   rX   c                  "    \ rS rSrSrSS jrSrg)Twipsq   zuConvenience constructor for length in twips, e.g. ``width = Twips(42)``.

A twip is a twentieth of a point, 635 EMU.
c                d    [        U[        R                  -  5      n[        R                  X5      $ r   )r   r   r6   r   )r   r7   r   s      r   r   Twips.__new__w   s&    %&///0~~c''r   r&   N)r7   r   rF   r&   r   r   r^   r^   q   s    
(r   r^   c                  P   ^  \ rS rSrSrSU 4S jjrS rS r\S	S j5       r	Sr
U =r$ )
RGBColor|   z7Immutable value object defining a particular RGB color.c                   > SnXU4 H/  n[        U[        5      (       a  US:  d  US:  d  M&  [        U5      e   [        [        U ]  XX#45      $ )Nz+RGBColor() takes three integer values 0-255r      )
isinstancer   
ValueErrorsuperrc   r   )r   rgbmsgval	__class__s         r   r   RGBColor.__new__   sS    ;!9CsC((79 o%  Xs+CQ;;r   c                    SU -  $ )Nz RGBColor(0x%02x, 0x%02x, 0x%02x)r&   r    s    r   __repr__RGBColor.__repr__   s    1D88r   c                    SU -  $ )z-Return a hex string rgb value, like '3C2F80'.z%02X%02X%02Xr&   r    s    r   __str__RGBColor.__str__   s    $$r   c                n    [        USS S5      n[        USS S5      n[        USS S5      nU " X#U5      $ )zEReturn a new instance from an RGB color hex string like ``'3C2F80'``.N         )r   )r   rgb_hex_strrj   rk   rl   s        r   from_stringRGBColor.from_string   sG     BQ$Aa "%AB$1|r   r&   )rj   r   rk   r   rl   r   )r{   strreturnrc   )r:   r;   r<   r=   r>   r   rr   ru   classmethodr|   r@   __classcell__)ro   s   @r   rc   rc   |   s)    A	<9%  r   rc   Tc                  :    \ rS rSrSrSS jrS	S
S jjrSS jrSrg)lazyproperty   a  Decorator like @property, but evaluated only on first access.

Like @property, this can only be used to decorate methods having only a `self`
parameter, and is accessed like an attribute on an instance, i.e. trailing
parentheses are not used. Unlike @property, the decorated method is only evaluated
on first access; the resulting value is cached and that same value returned on
second and later access without re-evaluation of the method.

Like @property, this class produces a *data descriptor* object, which is stored in
the __dict__ of the *class* under the name of the decorated method ('fget'
nominally). The cached value is stored in the __dict__ of the *instance* under that
same name.

Because it is a data descriptor (as opposed to a *non-data descriptor*), its
`__get__()` method is executed on each access of the decorated attribute; the
__dict__ item of the same name is "shadowed" by the descriptor.

While this may represent a performance improvement over a property, its greater
benefit may be its other characteristics. One common use is to construct
collaborator objects, removing that "real work" from the constructor, while still
only executing once. It also de-couples client code from any sequencing
considerations; if it's accessed from more than one location, it's assured it will
be ready whenever needed.

Loosely based on: https://stackoverflow.com/a/6849299/1902513.

A lazyproperty is read-only. There is no counterpart to the optional "setter" (or
deleter) behavior of an @property. This is critically important to maintaining its
immutability and idempotence guarantees. Attempting to assign to a lazyproperty
raises AttributeError unconditionally.

The parameter names in the methods below correspond to this usage example::

    class Obj(object)

        @lazyproperty
        def fget(self):
            return 'some result'

    obj = Obj()

Not suitable for wrapping a function (as opposed to a method) because it is not
callable.c                ^    Xl         UR                  U l        [        R                  " X5        g)a1  *fget* is the decorated method (a "getter" function).

A lazyproperty is read-only, so there is only an *fget* function (a regular
@property can also have an fset and fdel function). This name was chosen for
consistency with Python's `property` class which uses this name for the
corresponding parameter.
N)_fgetr:   _name	functoolsupdate_wrapper)r!   fgets     r   __init__lazyproperty.__init__   s"     
]]
  ,r   Nc                    Uc  U $ UR                   R                  U R                  5      nUc)  U R                  U5      nX1R                   U R                  '   [	        [
        U5      $ )a  Called on each access of 'fget' attribute on class or instance.

*self* is this instance of a lazyproperty descriptor "wrapping" the property
method it decorates (`fget`, nominally).

*obj* is the "host" object instance when the attribute is accessed from an
object instance, e.g. `obj = Obj(); obj.fget`. *obj* is None when accessed on
the class, e.g. `Obj.fget`.

*type* is the class hosting the decorated getter method (`fget`) on both class
and instance attribute access.
)__dict__getr   r   r   r   )r!   objtypevalues       r   __get__lazyproperty.__get__   sX     ;K   ,= JJsOE',LL$Au~r   c                    [        S5      e)ay  Raises unconditionally, to preserve read-only behavior.

This decorator is intended to implement immutable (and idempotent) object
attributes. For that reason, assignment to this property must be explicitly
prevented.

If this __set__ method was not present, this descriptor would become a
*non-data descriptor*. That would be nice because the cached value would be
accessed directly once set (__dict__ attrs have precedence over non-data
descriptors on instance attribute lookup). The problem is, there would be
nothing to stop assignment to the cached value, which would overwrite the result
of `fget()` and break both the immutability and idempotence guarantees of this
decorator.

The performance with this __set__() method in place was roughly 0.4 usec per
access when measured on a 2.8GHz development machine; so quite snappy and
probably not a rich target for optimization efforts.
zcan't set attribute)AttributeError)r!   r   r   s      r   __set__lazyproperty.__set__   s    & 233r   )r   r   )r   zCallable[..., T]r   Noner   )r   r   r   r   r   r   )r   r   r   r   r   r   )	r:   r;   r<   r=   r>   r   r   r   r@   r&   r   r   r   r      s    *X-:4r   r   c                ,    U R                   n[        XS9$ )z@write_only_property decorator.

Creates a property (descriptor attribute) that accepts assignment, but not getattr
(use in an expression).
)fsetdoc)r>   r?   )f	docstrings     r   write_only_propertyr     s     		I**r   c                  ^    \ rS rSrSrS
SS jjrSS jrSS jr\S 5       r	\SS j5       r
S	rg)ElementProxyi  a  Base class for lxml element proxy classes.

An element proxy class is one whose primary responsibilities are fulfilled by
manipulating the attributes and child elements of an XML element. They are the most
common type of class in python-docx other than custom element (oxml) classes.
Nc                    Xl         X l        g r   _element_parent)r!   elementparents      r   r   ElementProxy.__init__  s    r   c                ^    [        U[        5      (       d  gU R                  UR                  L $ )a,  Return |True| if this proxy object refers to the same oxml element as does
`other`.

ElementProxy objects are value objects and should maintain no mutable local
state. Equality for proxy objects is defined as referring to the same XML
element, whether or not they are the same proxy object instance.
Frg   r   r   r!   others     r   __eq__ElementProxy.__eq__#  s'     %..}}..r   c                ^    [        U[        5      (       d  gU R                  UR                  L$ )NTr   r   s     r   __ne__ElementProxy.__ne__/  s%    %..}}ENN22r   c                    U R                   $ )z(The lxml element proxied by this object.)r   r    s    r   r   ElementProxy.element4  s     }}r   c                ^    U R                   c  [        S5      eU R                   R                  $ )(The package part containing this object.z(part is not accessible from this element)r   rh   partr    s    r   r   ElementProxy.part9  s*     <<GHH||   r   r   r   )r   r   r   zt.ProvidesXmlPart | None)r   object)r   r   )r:   r;   r<   r=   r>   r   r   r   r?   r   r   r@   r&   r   r   r   r     s>    
/3
   ! !r   r   c                  2    \ rS rSrSrSS jr\S 5       rSrg)ParentediA  zProvides common services for document elements that occur below a part but may
occasionally require an ancestor object to provide a service, such as add or drop a
relationship.

Provides ``self._parent`` attribute to subclasses.
c                    Xl         g r   r   r!   r   s     r   r   Parented.__init__I      r   c                .    U R                   R                  $ r   r   r   r    s    r   r   Parented.partL       ||   r   r   N)r   zt.ProvidesXmlPart	r:   r;   r<   r=   r>   r   r?   r   r@   r&   r   r   r   r   A  s      ! !r   r   c                  6    \ rS rSrSrSS jr\SS j5       rSrg)	
StoryChildiR  a  A document element within a story part.

Story parts include DocumentPart and Header/FooterPart and can contain block items
(paragraphs and tables). Items from the block-item subtree occasionally require an
ancestor object to provide access to part-level or package-level items like styles
or images or to add or drop a relationship.

Provides `self._parent` attribute to subclasses.
c                    Xl         g r   r   r   s     r   r   StoryChild.__init__]  r   r   c                .    U R                   R                  $ r   r   r    s    r   r   StoryChild.part`  r   r   r   N)r   zt.ProvidesStoryPart)r   r   r   r&   r   r   r   r   R  s      ! !r   r   c                  :    \ rS rSrSrSS	S jjrS
S jrSS jrSrg)TextAccumulatorif  a.  Accepts `str` fragments and joins them together, in order, on `.pop().

Handy when text in a stream is broken up arbitrarily and you want to join it back
together within certain bounds. The optional `separator` argument determines how
the text fragments are punctuated, defaulting to the empty string.
c                    Xl         / U l        g r   
_separator_texts)r!   	separators     r   r   TextAccumulator.__init__n  s    #!#r   c                :    U R                   R                  U5        g)z'Add a text fragment to the accumulator.N)r   appendr!   texts     r   pushTextAccumulator.pushr  s    4 r   c              #     #    U R                   (       d  gU R                  R                  U R                   5      nU R                   R                  5         Uv   g7f)zGenerate sero-or-one str from those accumulated.

Using `yield from accum.pop()` in a generator setting avoids producing an empty
string when no text is in the accumulator.
N)r   r   joinclearr   s     r   popTextAccumulator.popv  s>      {{##DKK0
s   AAr   N) )r   r~   )r   r~   r   r   )r   zIterator[str])	r:   r;   r<   r=   r>   r   r   r   r@   r&   r   r   r   r   f  s    $!
r   r   )r   zCallable[[Any, Any], None])'r>   
__future__r   r   typingr   r   r   r   r   r	   r
   r   r   
docx.typestypestdocx.opc.partr   docx.oxml.xmlchemyr   docx.parts.storyr   r   r   rB   rH   rN   rS   rX   r^   rc   r   r   r   r   r   r   r   r&   r   r   <module>r      s    % " 
 
 
 %2*-=S -=`(V (( (-& -( (( ((F (uS#s]# < CLl471: l4^+'! '!T! !"! !( r   