o
    	'fU                     @  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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                   s   t  | || _d S N)super__init___element)selfr   	__class__ J/home/ubuntu/flask/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| )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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   5   s    z"Styles.__iter__.<locals>.<genexpr>)r   r   r   r   r   r   __iter__4   s   zStyles.__iter__c                 C  s   t | jjS r   )lenr   r   r-   r   r   r   __len__7   s   zStyles.__len__Fc                 C  s6   t |}|| v rtd| | 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   r   r   r   	add_style:   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   defaultF   s   zStyles.defaultstyle_id
str | Nonec                 C  s   |du r	|  |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`.
        N)r8   
_get_by_id)r   r9   r3   r   r   r   r'   N   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_idX   s
   
zStyles.get_style_idc                 C  s   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_latentStylesr-   r   r   r   latent_stylesg   s   zStyles.latent_stylesc                 C  s8   |r| j |nd}|du s|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'   typer8   r
   )r   r9   r3   r   r   r   r   r;   n   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>   y   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 )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 %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    