o
    	'f5                     @  s   d Z ddlmZ ddlZddlZddlmZmZmZm	Z	 ddl
mZ e	dddZG d	d
 d
eejZG dd deejZG dd dZdS )z4Base classes and other objects used by enumerations.    )annotationsN)AnyDictTypeTypeVar)Self_TBaseXmlEnum)boundc                   @  s"   e Zd ZdZdddZdd	 Zd
S )BaseEnumzBase class for Enums that do not map XML attr values.

    The enum's value will be an integer, corresponding to the integer assigned the
    corresponding member in the MS API enum of the same name.
    ms_api_valueintdocstrstrc                 C  s    t | |}||_| |_|S N)r   __new___value_strip__doc__)clsr   r   self r   F/home/ubuntu/flask/venv/lib/python3.10/site-packages/docx/enum/base.pyr      s   
zBaseEnum.__new__c                 C     | j  d| j dS zEThe symbolic name and string value of this member, e.g. 'MIDDLE (3)'.z ()namevaluer   r   r   r   __str__      zBaseEnum.__str__N)r   r   r   r   )__name__
__module____qualname__r   r   r    r   r   r   r   r      s    
r   c                   @  sH   e Zd ZU dZded< dddZd	d
 ZedddZedddZ	dS )r	   zBase class for Enums that also map XML attr values.

    The enum's value will be an integer, corresponding to the integer assigned the
    corresponding member in the MS API enum of the same name.
    r   	xml_valuer   r   r   c                 C  s&   t | |}||_||_| |_|S r   )r   r   r   r%   r   r   )r   r   r%   r   r   r   r   r   r   )   s
   
zBaseXmlEnum.__new__c                 C  r   r   r   r   r   r   r   r    0   r!   zBaseXmlEnum.__str__
str | Nonereturnr   c                   s:   t  fdd| D d}|du rt| j d  d|S )zEnumeration member corresponding to XML attribute value `xml_value`.

        Example::

            >>> WD_PARAGRAPH_ALIGNMENT.from_xml("center")
            WD_PARAGRAPH_ALIGNMENT.CENTER

        c                 3  s    | ]
}|j  kr|V  qd S r   r%   .0memberr(   r   r   	<genexpr>>   s    z'BaseXmlEnum.from_xml.<locals>.<genexpr>Nz has no XML mapping for '')next
ValueErrorr"   )r   r%   r+   r   r(   r   from_xml4   s   
zBaseXmlEnum.from_xmlr   Type[_T]r   int | _T | Nonec                 C  s
   | |j S )z@XML value of this enum member, generally an XML attribute value.r(   )r   r   r   r   r   to_xmlC   s   
zBaseXmlEnum.to_xmlN)r   r   r%   r   r   r   )r%   r&   r'   r   )r   r1   r   r2   r'   r&   )
r"   r#   r$   r   __annotations__r   r    classmethodr0   r3   r   r   r   r   r	       s   
 
c                   @  s`   e Zd ZdZdddZedd	 Zed
d ZdddZedd Z	edd Z
edd ZdS )DocsPageFormatterzGenerate an .rst doc page for an enumeration.

    Formats a RestructuredText documention page (string) for the enumeration class parts
    passed to the constructor. An immutable one-shot service object.
    clsnamer   clsdictDict[str, Any]c                 C  s   || _ || _d S r   )_clsname_clsdict)r   r7   r8   r   r   r   __init__R   s   
zDocsPageFormatter.__init__c                 C  s    d}| j | j| j| jf}|| S )zyThe RestructuredText documentation page for the enumeration.

        This is the only API member for the class.
        z.. _%s:

%s

%s

----

%s)_ms_name_page_title_intro_text_member_defs)r   tmpl
componentsr   r   r   page_strV   s   zDocsPageFormatter.page_strc                 C  s@   z| j d }W n ty   d}Y nw |du rdS t| S )z?Docstring of the enumeration, formatted for documentation page.r    N)r;   KeyErrortextwrapdedentr   )r   cls_docstringr   r   r   r?   e   s   zDocsPageFormatter._intro_textr+   BaseEnum | BaseXmlEnumc                 C  s>   |j dusJ t|j  }tj|dddd}d|j|f S )ztReturn an individual member definition formatted as an RST glossary entry,
        wrapped to fit within 78 columns.NN   z    )widthinitial_indentsubsequent_indentz%s
%s
)r   rF   rG   r   fillr   )r   r+   member_docstringr   r   r   _member_defr   s   zDocsPageFormatter._member_defc                   s&    j d } fdd|D }d|S )zgA single string containing the aggregated member definitions section of the
        documentation page.__members__c                   s    g | ]}|j d ur |qS r   )r   rP   r)   r   r   r   
<listcomp>   s    z2DocsPageFormatter._member_defs.<locals>.<listcomp>
)r;   join)r   membersmember_defsr   r   r   r@      s
   


zDocsPageFormatter._member_defsc                 C  s
   | j d S )z,The Microsoft API name for this enumeration.__ms_name__)r;   r   r   r   r   r=      s   
zDocsPageFormatter._ms_namec                 C  s    dt | jd  }d| j|f S )zThe title for the documentation page, formatted as code (surrounded in
        double-backtics) and underlined with '=' characters.=   z	``%s``
%s)lenr:   )r   title_underscorer   r   r   r>      s   zDocsPageFormatter._page_titleN)r7   r   r8   r9   )r+   rI   )r"   r#   r$   r   r<   propertyrC   r?   rP   r@   r=   r>   r   r   r   r   r6   K   s    




	
r6   )r   
__future__r   enumrF   typingr   r   r   r   typing_extensionsr   r   r   Enumr   r	   r6   r   r   r   r   <module>   s    +