
    ,hU                        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y)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.
    c                2    t         |   |       || _        y N)super__init___element)selfstyles	__class__s     T/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/docx/styles/styles.pyr   zStyles.__init__   s         c                ~    t        j                  |      t        fd| j                  j                  D              S )z$Enables `in` operator on style name.c              3  <   K   | ]  }|j                   k(    y wr   )name_val).0styleinternal_names     r   	<genexpr>z&Styles.__contains__.<locals>.<genexpr>   s     Xu5>>]2Xs   )r   ui2internalanyr   	style_lst)r   namer   s     @r   __contains__zStyles.__contains__   s.    !--d3X@W@WXXXr   c                   | j                   j                  t        j                  |            }|t	        |      S | j                   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.
        zFstyle 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   key	style_elmmsgs       r   __getitem__zStyles.__getitem__   s     MM--i.C.CC.HI	 	**MM++C0	   ka0	**03677r   c                <    d | j                   j                  D        S )Nc              3  2   K   | ]  }t        |        y wr   )r   )r   r   s     r   r   z"Styles.__iter__.<locals>.<genexpr>5   s     IU#Is   )r   r!   r   s    r   __iter__zStyles.__iter__4   s    I1H1HIIr   c                @    t        | j                  j                        S r   )lenr   r!   r1   s    r   __len__zStyles.__len__7   s    4==**++r   c                    t        j                  |      }|| v rt        d|z        | j                  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_style:   sP     **40
CdJKK//
JPE""r   c                T    | j                   j                  |      }|y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   r9   r   s      r   defaultzStyles.defaultF   s+     ))*5=E""r   c                L    || j                  |      S | j                  ||      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   style_idr9   s      r   r(   zStyles.get_by_idN   s*     <<
++x44r   c                p    |yt        |t              r| j                  ||      S | j                  ||      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_namer9   s      r   get_style_idzStyles.get_style_idX   s=      y100
KK//zJJr   c                H    t        | j                  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_latentStylesr1   s    r   latent_styleszStyles.latent_stylesg   s    
 DMMAACDDr   c                    |r| j                   j                  |      nd}||j                  |k7  r| j                  |      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   rB   r9   r   s       r   rA   zStyles._get_by_idn   sF     6>''14=EJJ*4<<
++E""r   c                ,    | j                  | |   |      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`.
        )rE   )r   r;   r9   s      r   rF   zStyles._get_style_id_from_namey   s     ,,T*-=zJJr   c                    |j                   |k7  rt        d|j                   d|      || j                  |      k(  ry|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)rM   r7   r?   rB   )r   r   r9   s      r   rE   zStyles._get_style_id_from_style   sI     ::#=BZZT  DLL,,~~r   )r   r   )r+   str)F)r9   r   )rB   
str | Noner9   r   )r;   rP   r9   r   returnrQ   )r   r
   r9   r   rR   rQ   )__name__
__module____qualname____doc__r   r#   r.   r2   r5   r<   r?   r(   rH   propertyrK   rA   rF   rE   __classcell__)r   s   @r   r   r      s    Y
8*J,
##5K E E	#	K	K+8	K		K,9	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 "  ) & $ ! + 5B\ Br   