
    hi                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZmZ  G d
 de
          ZdS )z<Styles object, container for all objects in the styles part.    )annotations)warn)WD_STYLE_TYPE)	CT_Styles)ElementProxy)	BabelFish)LatentStyles)	BaseStyleStyleFactoryc                       e Zd ZdZd fdZd ZddZd	 Zd
 ZddZ	ddZ
d dZd Zed             Zd dZd!dZd"dZ xZS )#StyleszProvides access to the styles defined in a document.

    Accessed using the :attr:`.Document.styles` property. Supports ``len()``, iteration,
    and dictionary-style access by style name.
    stylesr   c                X    t                                          |           || _        d S N)super__init___element)selfr   	__class__s     j/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/docx/styles/styles.pyr   zStyles.__init__   s&           c                v    t          j        |          t          fd| j        j        D                       S )z$Enables `in` operator on style name.c              3  .   K   | ]}|j         k    V  d S r   )name_val).0styleinternal_names     r   	<genexpr>z&Styles.__contains__.<locals>.<genexpr>   s*      XXu5>]2XXXXXXr   )r   ui2internalanyr   	style_lst)r   namer   s     @r   __contains__zStyles.__contains__   s;    !-d33XXXX@WXXXXXXr   keystrc                (   | j                             t          j        |                    }|t	          |          S | j                             |          }|(d}t          |t          d           t	          |          S t          d|z            )zEnables dictionary-style access by UI name.

        Lookup by style id is deprecated, triggers a warning, and will be removed in a
        near-future release.
        NzFstyle lookup by style_id is deprecated. Use style name as key instead.   )
stacklevelzno style with name '%s')	r   get_by_namer   r   r   	get_by_idr   UserWarningKeyError)r   r$   	style_elmmsgs       r   __getitem__zStyles.__getitem__   s     M--i.CC.H.HII	 	***M++C00	 ZCka0000	***036777r   c                .    d | j         j        D             S )Nc              3  4   K   | ]}t          |          V  d S r   )r   )r   r   s     r   r   z"Styles.__iter__.<locals>.<genexpr>2   s*      IIU##IIIIIIr   )r   r!   r   s    r   __iter__zStyles.__iter__1   s    II1HIIIIr   c                4    t          | j        j                  S r   )lenr   r!   r2   s    r   __len__zStyles.__len__4   s    4=*+++r   Fc                    t          j        |          }|| v rt          d|z            | j                            |||          }t          |          S )zReturn a newly added style object of `style_type` and identified by `name`.

        A builtin style can be defined by passing True for the optional `builtin`
        argument.
        z$document already contains style '%s')r   r   
ValueErrorr   add_style_of_typer   )r   r"   
style_typebuiltin
style_namer   s         r   	add_stylezStyles.add_style7   sZ     *400
CdJKKK//
JPPE"""r   r:   r   c                \    | j                             |          }|dS t          |          S )zpReturn the default style for `style_type` or |None| if no default is defined
        for that type (not common).N)r   default_forr   )r   r:   r   s      r   defaultzStyles.defaultC   s1     ))*55=4E"""r   style_id
str | Nonec                \    ||                      |          S |                     ||          S )zReturn the style of `style_type` matching `style_id`.

        Returns the default for `style_type` if `style_id` is not found or is |None|, or
        if the style having `style_id` is not of `style_type`.
        )r@   
_get_by_id)r   rA   r:   s      r   r*   zStyles.get_by_idK   s0     <<
+++x444r   c                    |dS t          |t                    r|                     ||          S |                     ||          S )ar  Return the id of the style corresponding to `style_or_name`, or |None| if
        `style_or_name` is |None|.

        If `style_or_name` is not a style object, the style is looked up using
        `style_or_name` as a style name, raising |ValueError| if no style with that name
        is defined. Raises |ValueError| if the target style is not of `style_type`.
        N)
isinstancer
   _get_style_id_from_style_get_style_id_from_name)r   style_or_namer:   s      r   get_style_idzStyles.get_style_idU   sN      4y11 	K00
KKK//zJJJr   c                N    t          | j                                                  S )zA |LatentStyles| object providing access to the default behaviors for latent
        styles and the collection of |_LatentStyle| objects that define overrides of
        those defaults for a particular named latent style.)r	   r   get_or_add_latentStylesr2   s    r   latent_styleszStyles.latent_stylesd   s     
 DMAACCDDDr   c                    |r| j                             |          nd}||j        |k    r|                     |          S t	          |          S )zReturn the style of `style_type` matching `style_id`.

        Returns the default for `style_type` if `style_id` is not found or if the style
        having `style_id` is not of `style_type`.
        N)r   r*   typer@   r   )r   rA   r:   r   s       r   rD   zStyles._get_by_idk   sT     6>G''1114=EJ*44<<
+++E"""r   r<   returnc                :    |                      | |         |          S )a  Return the id of the style of `style_type` corresponding to `style_name`.

        Returns |None| if that style is the default style for `style_type`. Raises
        |ValueError| if the named style is not found in the document or does not match
        `style_type`.
        )rG   )r   r<   r:   s      r   rH   zStyles._get_style_id_from_namev   s     ,,T*-=zJJJr   r   r
   c                    |j         |k    rt          d|j         d|          ||                     |          k    rdS |j        S )zId of `style`, or |None| if it is the default style of `style_type`.

        Raises |ValueError| if style is not of `style_type`.
        zassigned style is type z, need type N)rO   r8   r@   rA   )r   r   r:   s      r   rG   zStyles._get_style_id_from_style   sT    
 :##*%***V`V`abbbDLL,,,,4~r   )r   r   )r$   r%   )F)r:   r   )rA   rB   r:   r   )r<   r%   r:   r   rP   rB   )r   r
   r:   r   rP   rB   )__name__
__module____qualname____doc__r   r#   r/   r3   r6   r=   r@   r*   rJ   propertyrM   rD   rH   rG   __classcell__)r   s   @r   r   r      s:             Y Y Y
8 8 8 8$J J J, , ,
# 
# 
# 
## # # #5 5 5 5K K K E E XE	# 	# 	# 	#K K K K	 	 	 	 	 	 	 	r   r   N)rV   
__future__r   warningsr   docx.enum.styler   docx.oxml.stylesr   docx.sharedr   docx.stylesr   docx.styles.latentr	   docx.styles.styler
   r   r    r   r   <module>rb      s    B B " " " " " "       ) ) ) ) ) ) & & & & & & $ $ $ $ $ $ ! ! ! ! ! ! + + + + + + 5 5 5 5 5 5 5 5y y y y y\ y y y y yr   