
    ,h4                       d Z ddlmZ ddlZddlmZmZmZmZm	Z	m
Z
mZmZmZ erddlmZ ddlmZ ddlmZ ddlmZ  G d d	e      Z G d
 de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d deeeef         Z ed      Z  G d dee          Z!d$dZ" G d d      Z# G d d      Z$ G d  d!      Z% G d" d#      Z&y)%zObjects shared by docx modules.    )annotationsN)	TYPE_CHECKINGAnyCallableGenericIteratorListTupleTypeVarcast)XmlPart)BaseOxmlElement)	StoryPartc                      e Zd ZdZdZdZdZdZdZddZ	e
d        Ze
d	        Ze
d
        Ze
d        Ze
d        Ze
d        Zy)Lengtha  Base 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                .    t         j                  | |      S N)int__new__clsemus     M/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/docx/shared.pyr   zLength.__new__'   s    {{3$$    c                2    | t        | j                        z  S )z7The equivalent length expressed in centimeters (float).)float_EMUS_PER_CMselfs    r   cmz	Length.cm*        eD--...r   c                    | S )z>The equivalent length expressed in English Metric Units (int). r   s    r   r   z
Length.emu/   s	     r   c                2    | t        | j                        z  S )z2The equivalent length expressed in inches (float).)r   _EMUS_PER_INCHr   s    r   incheszLength.inches4   s     eD//000r   c                2    | t        | j                        z  S )z7The equivalent length expressed in millimeters (float).)r   _EMUS_PER_MMr   s    r   mmz	Length.mm9   r!   r   c                2    | t        | j                        z  S )z Floating point length in points.)r   _EMUS_PER_PTr   s    r   ptz	Length.pt>   r!   r   c                V    t        t        | t        | j                        z              S )z/The equivalent length expressed in twips (int).)r   roundr   _EMUS_PER_TWIPr   s    r   twipszLength.twipsC   s$     5d&9&9 ::;<<r   Nr   r   )__name__
__module____qualname____doc__r%   r   r(   r+   r/   r   propertyr    r   r&   r)   r,   r0   r#   r   r   r   r      s     NLLLN% / /   1 1 / / / / = =r   r   c                      e Zd ZdZddZy)IncheszKConvenience constructor for length in inches, e.g. ``width = Inches(0.5)``.c                f    t        |t        j                  z        }t        j                  | |      S r   )r   r   r%   r   )r   r&   r   s      r   r   zInches.__new__L   s(    &60001~~c3''r   N)r&   r   r2   r3   r4   r5   r   r#   r   r   r8   r8   I   s
    U(r   r8   c                      e Zd ZdZddZy)CmzLConvenience constructor for length in centimeters, e.g. ``height = Cm(12)``.c                f    t        |t        j                  z        }t        j                  | |      S r   )r   r   r   r   )r   r    r   s      r   r   z
Cm.__new__T   (    "v***+~~c3''r   N)r    r   r:   r#   r   r   r<   r<   Q   s
    V(r   r<   c                      e Zd ZdZddZy)Emuz]Convenience constructor for length in English Metric Units, e.g. ``width =
    Emu(457200)``.c                @    t         j                  | t        |            S r   )r   r   r   r   s     r   r   zEmu.__new__]   s    ~~c3s8,,r   Nr1   r:   r#   r   r   r@   r@   Y   s    -r   r@   c                      e Zd ZdZddZy)MmzNConvenience constructor for length in millimeters, e.g. ``width = Mm(240.5)``.c                f    t        |t        j                  z        }t        j                  | |      S r   )r   r   r(   r   )r   r)   r   s      r   r   z
Mm.__new__d   r>   r   N)r)   r   r:   r#   r   r   rC   rC   a   s
    X(r   rC   c                      e Zd ZdZddZy)Ptz:Convenience value class for specifying a length in points.c                f    t        |t        j                  z        }t        j                  | |      S r   )r   r   r+   r   )r   pointsr   s      r   r   z
Pt.__new__l   s(    &6.../~~c3''r   N)rH   r   r:   r#   r   r   rF   rF   i   s
    D(r   rF   c                      e Zd ZdZddZy)Twipsz}Convenience constructor for length in twips, e.g. ``width = Twips(42)``.

    A twip is a twentieth of a point, 635 EMU.
    c                f    t        |t        j                  z        }t        j                  | |      S r   )r   r   r/   r   )r   r0   r   s      r   r   zTwips.__new__w   s(    %&///0~~c3''r   N)r0   r   r:   r#   r   r   rJ   rJ   q   s    
(r   rJ   c                  B     e Zd ZdZd fdZd Zd Zedd       Z xZ	S )RGBColorz7Immutable value object defining a particular RGB color.c                    d}|||fD ]'  }t        |t              r|dk  s|dkD  st        |       t        t        |   | |||f      S )Nz+RGBColor() takes three integer values 0-255r      )
isinstancer   
ValueErrorsuperrM   r   )r   rgbmsgval	__class__s         r   r   zRGBColor.__new__   s[    ;q!9 	&CsC(79 o%	& Xs+C!Q;;r   c                    d| z  S )Nz RGBColor(0x%02x, 0x%02x, 0x%02x)r#   r   s    r   __repr__zRGBColor.__repr__   s    1D88r   c                    d| z  S )z-Return a hex string rgb value, like '3C2F80'.z%02X%02X%02Xr#   r   s    r   __str__zRGBColor.__str__   s    $$r   c                p    t        |dd d      }t        |dd d      }t        |dd d      } | |||      S )zEReturn a new instance from an RGB color hex string like ``'3C2F80'``.N         )r   )r   rgb_hex_strrS   rT   rU   s        r   from_stringzRGBColor.from_string   sI     BQ$Aa "%AB$1a|r   )rS   r   rT   r   rU   r   )ra   strreturnrM   )
r2   r3   r4   r5   r   rZ   r\   classmethodrb   __classcell__)rX   s   @r   rM   rM   |   s)    A	<9%  r   rM   Tc                  *    e Zd ZdZddZdddZd	dZy)
lazypropertya+  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                `    || _         |j                  | _        t        j                  | |       y)aY  *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)_fgetr2   _name	functoolsupdate_wrapper)r   fgets     r   __init__zlazyproperty.__init__   s&     
]]
  t,r   Nc                    || S |j                   j                  | j                        }|*| j                  |      }||j                   | j                  <   t	        t
        |      S )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__getrl   rk   r   rg   )r   objtypevalues       r   __get__zlazyproperty.__get__   sZ     ;K   ,= JJsOE',CLL$Au~r   c                    t        d      )a  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   rt   rv   s      r   __set__zlazyproperty.__set__   s    & 233r   )ro   zCallable[..., T]rd   Noner   )rt   r   ru   r   rd   rg   )rt   r   rv   r   rd   r{   )r2   r3   r4   r5   rp   rw   rz   r#   r   r   ri   ri      s    *X-:4r   ri   c                4    | j                   }t        | |      S )z@write_only_property decorator.

    Creates a property (descriptor attribute) that accepts assignment, but not getattr
    (use in an expression).
    )fsetdoc)r5   r6   )f	docstrings     r   write_only_propertyr     s     		I	**r   c                  L    e Zd ZdZdd	dZd
dZd
dZed        Zedd       Z	y)ElementProxya,  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                     || _         || _        y r   )_element_parent)r   elementparents      r   rp   zElementProxy.__init__  s    r   c                T    t        |t              sy| j                  |j                  u S )aT  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rP   r   r   r   others     r   __eq__zElementProxy.__eq__#  s$     %.}}..r   c                T    t        |t              sy| j                  |j                  uS )NTr   r   s     r   __ne__zElementProxy.__ne__/  s"    %.}}ENN22r   c                    | j                   S )z(The lxml element proxied by this object.)r   r   s    r   r   zElementProxy.element4  s     }}r   c                \    | j                   t        d      | j                   j                  S )(The package part containing this object.z(part is not accessible from this element)r   rQ   partr   s    r   r   zElementProxy.part9  s*     <<GHH||   r   r   )r   r   r   zt.ProvidesXmlPart | None)r   object)rd   r   )
r2   r3   r4   r5   rp   r   r   r6   r   r   r#   r   r   r   r     s>    
/3
   ! !r   r   c                  (    e Zd ZdZddZed        Zy)ParentedzProvides 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                    || _         y r   r   r   r   s     r   rp   zParented.__init__I  	    r   c                .    | j                   j                  S r   r   r   r   s    r   r   zParented.partL       ||   r   N)r   zt.ProvidesXmlPartr2   r3   r4   r5   rp   r6   r   r#   r   r   r   r   A  s      ! !r   r   c                  *    e Zd ZdZddZedd       Zy)
StoryChilda  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                    || _         y r   r   r   s     r   rp   zStoryChild.__init__]  r   r   c                .    | j                   j                  S r   r   r   s    r   r   zStoryChild.part`  r   r   N)r   zt.ProvidesStoryPart)rd   r   r   r#   r   r   r   r   R  s      ! !r   r   c                  *    e Zd ZdZdddZddZd	dZy)
TextAccumulatora>  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                     || _         g | _        y r   )
_separator_texts)r   	separators     r   rp   zTextAccumulator.__init__n  s    #!#r   c                :    | j                   j                  |       y)z'Add a text fragment to the accumulator.N)r   appendr   texts     r   pushzTextAccumulator.pushr  s    4 r   c              #     K   | j                   sy| j                  j                  | j                         }| j                   j                          | yw)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   popzTextAccumulator.popv  s?      {{##DKK0
s   AAN) )r   rc   )r   rc   rd   r{   )rd   zIterator[str])r2   r3   r4   r5   rp   r   r   r#   r   r   r   r   f  s    $!
r   r   )r   zCallable[[Any, Any], None])'r5   
__future__r   rm   typingr   r   r   r   r   r	   r
   r   r   
docx.typestypestdocx.opc.partr   docx.oxml.xmlchemyr   docx.parts.storyr   r   r   r8   r<   r@   rC   rF   rJ   rM   rg   ri   r   r   r   r   r   r#   r   r   <module>r      s    % " 
 
 
 %2*-=S -=`(V (( (-& -( (( ((F (uS#s]# < CLl471: l4^+'! '!T! !"! !( r   