o
    ýÞhè  ã                   @  s|   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„ 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                      s”   e Zd ZdZd)‡ fdd„Zdd„ Zd*d
d„Zdd„ Zdd„ Zd+dd„Z	d,dd„Z
d-dd„Zdd„ Zedd„ ƒZd-dd „Zd.d#d$„Zd/d'd(„Z‡  ZS )0ÚStyleszÂProvides 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                   s   t ƒ  |¡ || _d S ©N)ÚsuperÚ__init__Ú_element)Úselfr   ©Ú	__class__© úR/var/www/html/premium_crap/venv/lib/python3.10/site-packages/docx/styles/styles.pyr      s   
zStyles.__init__c                   s$   t  |¡‰ t‡ fdd„| jjD ƒƒS )z$Enables `in` operator on style name.c                 3  s   � | ]}|j ˆ kV  qd S r   )Úname_val©Ú.0Ústyle©Úinternal_namer   r   Ú	<genexpr>   s   € z&Styles.__contains__.<locals>.<genexpr>)r   Úui2internalÚanyr   Ú	style_lst)r   Únamer   r   r   Ú__contains__   s   
zStyles.__contains__ÚkeyÚstrc                 C  s\   | j  t |¡¡}|durt|ƒS | j  |¡}|dur(d}t|tdd� t|ƒS td| ƒ‚)z©Enables 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Úmsgr   r   r   Ú__getitem__   s   zStyles.__getitem__c                 C  s   dd„ | j jD ƒS )Nc                 s  s   � | ]}t |ƒV  qd S r   )r
   r   r   r   r   r   2   s   € z"Styles.__iter__.<locals>.<genexpr>)r   r   ©r   r   r   r   Ú__iter__1   s   zStyles.__iter__c                 C  s   t | jjƒS r   )Úlenr   r   r-   r   r   r   Ú__len__4   s   zStyles.__len__Fc                 C  s6   t  |¡}|| v rtd| ƒ‚| j |||¡}t|ƒS )z¹Return 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   r   r   r   Ú	add_style7   s
   
zStyles.add_styler3   r   c                 C  s    | j  |¡}|du r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   r3   r   r   r   r   ÚdefaultC   s   zStyles.defaultÚstyle_idú
str | Nonec                 C  s   |du r	|   |¡S |  ||¡S )z×Return 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`.
        N)r8   Ú
_get_by_id)r   r9   r3   r   r   r   r'   K   s   
zStyles.get_by_idc                 C  s.   |du r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_namer3   r   r   r   Úget_style_idU   s
   
zStyles.get_style_idc                 C  s   t | j ¡ ƒS )zÝA |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_latentStylesr-   r   r   r   Úlatent_stylesd   s   zStyles.latent_stylesc                 C  s8   |r| j  |¡nd}|du s|j|kr|  |¡S t|ƒS )zÉReturn 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'   Útyper8   r
   )r   r9   r3   r   r   r   r   r;   k   s   
zStyles._get_by_idr5   Úreturnc                 C  s   |   | | |¡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`.
        )r=   )r   r5   r3   r   r   r   r>   v   s   zStyles._get_style_id_from_namer   r	   c                 C  s4   |j |krtd|j |f ƒ‚||  |¡krdS |jS )z‹Id 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 %s, need type %sN)rC   r1   r8   r9   )r   r   r3   r   r   r   r=      s
   
zStyles._get_style_id_from_style)r   r   )r"   r#   )F)r3   r   )r9   r:   r3   r   )r5   r#   r3   r   rD   r:   )r   r	   r3   r   rD   r:   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r!   r,   r.   r0   r6   r8   r'   r@   ÚpropertyrB   r;   r>   r=   Ú__classcell__r   r   r   r   r      s     







	r   N)rH   Ú
__future__r   Úwarningsr   Údocx.enum.styler   Údocx.oxml.stylesr   Údocx.sharedr   Údocx.stylesr   Údocx.styles.latentr   Údocx.styles.styler	   r
   r   r   r   r   r   Ú<module>   s    