o
    	'f&                     @   sh   d Z ddlZddlmZmZ ddlmZ ddlmZmZ ddl	m
Z
 ddlmZmZ G dd	 d	eZdS )
z@Custom element classes for core properties-related XML elements.    N)datetime	timedelta)Any)nsdeclsqn)	parse_xml)BaseOxmlElement	ZeroOrOnec                   @   s  e Zd ZdZedddZedddZedddZedddZedddZ	ed	ddZ
ed
ddZedddZedddZedddZedddZedddZedddZedddZedddZdeddd Zedd Zedd ZejdefddZedefddZejdefd dZedefd!d"Zejdefd#d"Zed$d% Zejdefd&d%Zed'd( Zejd)d( Zed*d+ Z e jd,d+ Z ed-d. Z!e!jd/d. Z!ed0d1 Z"e"jd2d1 Z"ed3d4 Z#e#jd5d4 Z#ed6d7 Z$e$jd8d7 Z$ed9d: Z%e%jd;d: Z%ed<d= Z&e&jd>d= Z&ed?d@ Z'e'jdAd@ Z'edBdC Z(e(jdDdC Z(edEdF Z)e)jdGdF Z)dHdI Z*dJdK Z+edLdM Z,e-.dNZ/edOdP Z0dQdR Z1dSede2ddTfdUdVZ3dWedefdXdYZ4dTS )ZCT_CorePropertiesaX  `<cp:coreProperties>` element, the root element of the Core Properties part.

    Stored as `/docProps/core.xml`. Implements many of the Dublin Core document metadata
    elements. String elements resolve to an empty string ("") if the element is not
    present in the XML. String elements are limited in length to 255 unicode characters.
    zcp:category )
successorszcp:contentStatuszdcterms:createdz
dc:creatorzdc:descriptionzdc:identifierzcp:keywordszdc:languagezcp:lastModifiedByzcp:lastPrintedzdcterms:modifiedzcp:revisionz
dc:subjectzdc:titlez
cp:versionz<cp:coreProperties %s/>
cpdcdctermsc                 C   s   | j }t|}|S )z+Return a new `<cp:coreProperties>` element.)_coreProperties_tmplr   )clsxmlcorePropertiesr   r   K/home/ubuntu/flask/venv/lib/python3.10/site-packages/docx/oxml/coreprops.pynew&   s   zCT_CoreProperties.newc                 C   
   |  dS )z+The text in the `dc:creator` child element.creator_text_of_elementselfr   r   r   author_text-   s   
zCT_CoreProperties.author_textvaluec                 C      |  d| d S )Nr   _set_element_textr   r   r   r   r   r   2      returnc                 C   r   Ncategoryr   r   r   r   r   category_text6      
zCT_CoreProperties.category_textc                 C   r   r$   r   r!   r   r   r   r&   :   r"   c                 C   r   Ndescriptionr   r   r   r   r   comments_text>   r'   zCT_CoreProperties.comments_textc                 C   r   r(   r   r!   r   r   r   r*   B   r"   c                 C   r   NcontentStatusr   r   r   r   r   contentStatus_textF   r'   z$CT_CoreProperties.contentStatus_textc                 C   r   r+   r   r!   r   r   r   r-   J   r"   c                 C   r   Ncreated_datetime_of_elementr   r   r   r   created_datetimeN   r'   z"CT_CoreProperties.created_datetimec                 C   r   r.   _set_element_datetimer!   r   r   r   r2   R   r"   c                 C   r   N
identifierr   r   r   r   r   identifier_textV   r'   z!CT_CoreProperties.identifier_textc                 C   r   r5   r   r!   r   r   r   r7   Z   r"   c                 C   r   Nkeywordsr   r   r   r   r   keywords_text^   r'   zCT_CoreProperties.keywords_textc                 C   r   r8   r   r!   r   r   r   r:   b   r"   c                 C   r   Nlanguager   r   r   r   r   language_textf   r'   zCT_CoreProperties.language_textc                 C   r   r;   r   r!   r   r   r   r=   j   r"   c                 C   r   NlastModifiedByr   r   r   r   r   lastModifiedBy_textn   r'   z%CT_CoreProperties.lastModifiedBy_textc                 C   r   r>   r   r!   r   r   r   r@   r   r"   c                 C   r   NlastPrintedr0   r   r   r   r   lastPrinted_datetimev   r'   z&CT_CoreProperties.lastPrinted_datetimec                 C   r   rA   r3   r!   r   r   r   rC   z   r"   c                 C   r   Nmodifiedr0   r   r   r   r   modified_datetime~   r'   z#CT_CoreProperties.modified_datetimec                 C   r   rD   r3   r!   r   r   r   rF      r"   c                 C   sL   | j }|du r	dS |j}zt|}W n ty   d}Y nw |dk r$d}|S )z#Integer value of revision property.Nr   )revisiontextint
ValueError)r   rG   revision_strr   r   r   revision_number   s   z!CT_CoreProperties.revision_numberc                 C   s8   t |tr	|dk rd}t|| |  }t||_dS )z9Set revision property to string value of integer `value`.   z1revision property requires positive int, got '%s'N)
isinstancerI   rJ   get_or_add_revisionstrrH   )r   r   tmplrG   r   r   r   rL      s
   c                 C   r   Nsubjectr   r   r   r   r   subject_text   r'   zCT_CoreProperties.subject_textc                 C   r   rR   r   r!   r   r   r   rT      r"   c                 C   r   Ntitler   r   r   r   r   
title_text   r'   zCT_CoreProperties.title_textc                 C   r   rU   r   r!   r   r   r   rW      r"   c                 C   r   Nversionr   r   r   r   r   version_text   r'   zCT_CoreProperties.version_textc                 C   r   rX   r   r!   r   r   r   rZ      r"   c                 C   s>   t | |}|d u rd S |j}z| |W S  ty   Y d S w )N)getattrrH   _parse_W3CDTF_to_datetimerJ   )r   property_nameelementdatetime_strr   r   r   r1      s   
z&CT_CoreProperties._datetime_of_elementc                 C   s   d| }t | |}| }|S )z@Return element returned by "get_or_add_" method for `prop_name`.zget_or_add_%s)r[   )r   	prop_nameget_or_add_method_nameget_or_add_methodr^   r   r   r   _get_or_add   s   
zCT_CoreProperties._get_or_addc                 C   sj   | j |}|du rtd| | \}}}|dkrdnd}t|| }t|| }	t||	d}
||
 S )z}A |datetime| instance offset from `dt` by timezone offset in `offset_str`.

        `offset_str` is like `"-07:00"`.
        Nz!'%s' is not a valid offset string+rM   )hoursminutes)_offset_patternmatchrJ   groupsrI   r   )r   dt
offset_strri   sign	hours_strminutes_strsign_factorrf   rg   tdr   r   r   
_offset_dt   s   zCT_CoreProperties._offset_dtz([+-])(\d\d):(\d\d)c              	   C   s   d}|d d }|dd  }d }|D ]}zt ||}W q ty%   Y qw |d u r2d}t|| t|dkr>| ||S |S )N)z%Y-%m-%dT%H:%M:%Sz%Y-%m-%dz%Y-%mz%Y   z+could not parse W3CDTF datetime string '%s'   )r   strptimerJ   lenrr   )r   
w3cdtf_str	templatesparseable_partrl   rk   rQ   r   r   r   r\      s    z+CT_CoreProperties._parse_W3CDTF_to_datetimec                 C   st   t |tsd}t|t| | |}|d}||_|dv r8| tdd |tdd | j	td= dS dS )	zCSet date/time value of child element having `prop_name` to `value`.z;property requires <type 'datetime.datetime'> object, got %sz%Y-%m-%dT%H:%M:%SZ)r/   rE   zxsi:foobarzxsi:typezdcterms:W3CDTFN)
rN   r   rJ   typerc   strftimerH   setr   attrib)r   r`   r   rQ   r^   dt_strr   r   r   r4      s   


z'CT_CoreProperties._set_element_datetimer`   Nc                 C   sB   t |ts	t|}t|dkrd}t|| | |}||_dS )z/Set string value of `name` property to `value`.   z0exceeded 255 char limit for property, got:

'%s'N)rN   rP   rv   rJ   rc   rH   )r   r`   r   rQ   r^   r   r   r   r      s   


z#CT_CoreProperties._set_element_textr]   c                 C   s*   t | |}|du rdS |jdu rdS |jS )zThe text in the element matching `property_name`.

        The empty string if the element is not present or contains no text.
        N )r[   rH   )r   r]   r^   r   r   r   r     s   

z"CT_CoreProperties._text_of_element)5__name__
__module____qualname____doc__r	   r%   r,   r/   r   r)   r6   r9   r<   r?   rB   rE   rG   rS   rV   rY   r   r   classmethodr   propertyr   setterrP   r&   r*   r-   r2   r7   r:   r=   r@   rC   rF   rL   rT   rW   rZ   r1   rc   rr   recompilerh   r\   r4   r   r    r   r   r   r   r   r
      s    



























r
   )r   r   r   r   typingr   docx.oxml.nsr   r   docx.oxml.parserr   docx.oxml.xmlchemyr   r	   r
   r   r   r   r   <module>   s    