o
    ýÞhÎ  ã                   @  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	m
Z
 er&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)ÚTYPE_CHECKINGÚAnyÚDictÚTypeÚTypeVar)ÚSelfÚ_TÚBaseXmlEnum)Úboundc                   @  s"   e Zd ZdZddd„Zdd	„ Zd
S )ÚBaseEnumzÌBase 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   úN/var/www/html/premium_crap/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
   zÊBase 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.
    ú
str | NoneÚ	xml_valuer   r   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!   1   r"   zBaseXmlEnum.__str__Úreturnr   c                   s:   t ‡ fdd„| D ƒdƒ}|du rt| j› dˆ › d�ƒ‚|S )zÆEnumeration 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_xml5   s   
zBaseXmlEnum.from_xmlr   úType[_T]r   úint | _T | Nonec                 C  s.   | |ƒ}|j }|st| j› d|j› d�ƒ‚|S )z@XML value of this enum member, generally an XML attribute value.Ú.z has no XML representation)r'   r0   r#   r   )r   r   r,   r'   r   r   r   Úto_xmlD   s
   zBaseXmlEnum.to_xmlN)r   r   r'   r&   r   r   )r'   r&   r(   r   )r   r2   r   r3   r(   r&   )
r#   r$   r%   r   Ú__annotations__r   r!   Úclassmethodr1   r5   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 )ÚDocsPageFormatterzÑGenerate 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   r9   r:   r   r   r   Ú__init__W   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_str[   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   rA   j   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.NéN   z    )ÚwidthÚinitial_indentÚsubsequent_indentz%s
%s
)r   rH   rI   r   Úfillr   )r   r,   Úmember_docstringr   r   r   Ú_member_defw   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   rR   r*   r    r   r   Ú
<listcomp>‰   s     z2DocsPageFormatter._member_defs.<locals>.<listcomp>Ú
)r=   Újoin)r   ÚmembersÚmember_defsr   r    r   rB   „   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 )zƒThe 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)r9   r   r:   r;   )r,   rK   )r#   r$   r%   r   r>   ÚpropertyrE   rA   rR   rB   r?   r@   r   r   r   r   r8   P   s    





r8   )r   Ú
__future__r   ÚenumrH   Útypingr   r   r   r   r   Útyping_extensionsr   r	   r   ÚEnumr   r
   r8   r   r   r   r   Ú<module>   s    /