o
    Z2hb)                     @  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	 ddl
mZmZ ddlmZ ddlmZmZ er8ddlmZ G d	d
 d
eZdS )z@Custom element classes for core properties-related XML elements.    )annotationsN)TYPE_CHECKINGAnyCallable)nsdeclsqn)	parse_xml)BaseOxmlElement	ZeroOrOne)_Elementc                   @  s  e Zd ZU dZded< 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< 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dhd!dZedid#d$Zejdhd%d$Zedid&d'Zejdhd(d'Zed)d* Zejdhd+d*Zed,d- Zejdjd/d-Zed0d1 Z e jdhd2d1Z ed3d4 Z!e!jdhd5d4Z!ed6d7 Z"e"jdhd8d7Z"ed9d: Z#e#jdhd;d:Z#ed<d= Z$e$jdjd>d=Z$edkd@dAZ%e%jdjdBdAZ%edCdD Z&e&jdldFdDZ&edGdH Z'e'jdhdIdHZ'edJdK Z(e(jdhdLdKZ(edMdN Z)e)jdhdOdNZ)dmdQdRZ*dndUdVZ+edodYdZZ,e-.d[Z/edpd]d^Z0dqd_d`Z1drdcddZ2dsdedfZ3dgS )t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Callable[[], etree_Element]get_or_add_revisionz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etree_Element | None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   d/home/skpark/git/infrasmart_work/infrasmart/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_text6   s   
zCT_CoreProperties.author_textvaluestrc                 C     |  d| d S )Nr   _set_element_textr   r!   r   r   r   r    ;      returnc                 C  r   Ncategoryr   r   r   r   r   category_text?      
zCT_CoreProperties.category_textc                 C  r#   r)   r$   r&   r   r   r   r+   C   r'   c                 C  r   Ndescriptionr   r   r   r   r   comments_textG   r,   zCT_CoreProperties.comments_textc                 C  r#   r-   r$   r&   r   r   r   r/   K   r'   c                 C  r   NcontentStatusr   r   r   r   r   contentStatus_textO   r,   z$CT_CoreProperties.contentStatus_textc                 C  r#   r0   r$   r&   r   r   r   r2   S   r'   c                 C  r   Ncreated_datetime_of_elementr   r   r   r   created_datetimeW   r,   z"CT_CoreProperties.created_datetimedt.datetimec                 C  r#   r3   _set_element_datetimer&   r   r   r   r7   [   r'   c                 C  r   N
identifierr   r   r   r   r   identifier_text_   r,   z!CT_CoreProperties.identifier_textc                 C  r#   r;   r$   r&   r   r   r   r=   c   r'   c                 C  r   Nkeywordsr   r   r   r   r   keywords_textg   r,   zCT_CoreProperties.keywords_textc                 C  r#   r>   r$   r&   r   r   r   r@   k   r'   c                 C  r   Nlanguager   r   r   r   r   language_texto   r,   zCT_CoreProperties.language_textc                 C  r#   rA   r$   r&   r   r   r   rC   s   r'   c                 C  r   NlastModifiedByr   r   r   r   r   lastModifiedBy_textw   r,   z%CT_CoreProperties.lastModifiedBy_textc                 C  r#   rD   r$   r&   r   r   r   rF   {   r'   c                 C  r   NlastPrintedr5   r   r   r   r   lastPrinted_datetime   r,   z&CT_CoreProperties.lastPrinted_datetimec                 C  r#   rG   r9   r&   r   r   r   rI      r'   dt.datetime | Nonec                 C  r   Nmodifiedr5   r   r   r   r   modified_datetime   r,   z#CT_CoreProperties.modified_datetimec                 C  r#   rK   r9   r&   r   r   r   rM      r'   c                 C  sP   | j }|du r	dS t|j}zt|}W n ty   d}Y nw |dk r&d}|S )z#Integer value of revision property.Nr   )r   r"   textint
ValueError)r   r   revision_strr   r   r   revision_number   s   
z!CT_CoreProperties.revision_numberrO   c                 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)
isinstancerO   rP   r   r"   rN   )r   r!   tmplr   r   r   r   rR      s
   c                 C  r   Nsubjectr   r   r   r   r   subject_text   r,   zCT_CoreProperties.subject_textc                 C  r#   rV   r$   r&   r   r   r   rX      r'   c                 C  r   Ntitler   r   r   r   r   
title_text   r,   zCT_CoreProperties.title_textc                 C  r#   rY   r$   r&   r   r   r   r[      r'   c                 C  r   Nversionr   r   r   r   r   version_text   r,   zCT_CoreProperties.version_textc                 C  r#   r\   r$   r&   r   r   r   r^      r'   property_namec                 C  s>   t | |}|d u rd S |j}z| |W S  ty   Y d S w )N)getattrrN   _parse_W3CDTF_to_datetimerP   )r   r_   elementdatetime_strr   r   r   r6      s   
z&CT_CoreProperties._datetime_of_element	prop_namer	   c                 C  s   d| }t | |}| }|S )z@Return element returned by "get_or_add_" method for `prop_name`.zget_or_add_%s)r`   )r   rd   get_or_add_method_nameget_or_add_methodrb   r   r   r   _get_or_add   s   
zCT_CoreProperties._get_or_adddt_
offset_strc                 C  sl   | j |}|du rtd| | \}}}|dkrdnd}t|| }t|| }	tj||	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+rS   )hoursminutes)_offset_patternmatchrP   groupsrO   dt	timedelta)r   rh   ri   ro   sign	hours_strminutes_strsign_factorrl   rm   tdr   r   r   
_offset_dt   s   zCT_CoreProperties._offset_dtz([+-])(\d\d):(\d\d)
w3cdtf_strc              	   C  s   d}|d d }|dd  }d }|D ]}z	t j||}W q ty&   Y qw |d u r3d}t|| t|dkr?| ||}|jt jjdS )N)z%Y-%m-%dT%H:%M:%Sz%Y-%m-%dz%Y-%mz%Y   z+could not parse W3CDTF datetime string '%s'   )tzinfo)	rq   datetimestrptimerP   lenrx   replacetimezoneutc)r   ry   	templatesparseable_partri   rh   rU   r   r   r   ra      s    z+CT_CoreProperties._parse_W3CDTF_to_datetimec                 C  sv   t |tjsd}t|t| | |}|d}||_|dv r9| 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)r4   rL   zxsi:foobarzxsi:typezdcterms:W3CDTFN)rT   rq   r}   rP   typerg   strftimerN   setr   attrib)r   rd   r!   rU   rb   dt_strr   r   r   r:     s   

z'CT_CoreProperties._set_element_datetimer   Nonec                 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)rT   r"   r   rP   rg   rN   )r   rd   r!   rU   rb   r   r   r   r%     s   


z#CT_CoreProperties._set_element_textc                 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`   rN   )r   r_   rb   r   r   r   r      s   

z"CT_CoreProperties._text_of_elementN)r!   r"   )r(   r"   )r!   r8   )r(   rJ   )r!   rO   )r_   r"   r(   rJ   )rd   r"   r(   r	   )rh   r8   ri   r"   r(   r8   )ry   r"   r(   r8   )rd   r"   r!   r8   )rd   r"   r!   r   r(   r   )r_   r"   r(   r"   )4__name__
__module____qualname____doc____annotations__r
   r*   r1   r4   r   r.   r<   r?   rB   rE   rH   rL   r   rW   rZ   r]   r   r   classmethodr   propertyr    setterr+   r/   r2   r7   r=   r@   rC   rF   rI   rM   rR   rX   r[   r^   r6   rg   rx   recompilern   ra   r:   r%   r   r   r   r   r   r      s   
 

















r   )r   
__future__r   r}   rq   r   typingr   r   r   docx.oxml.nsr   r   docx.oxml.parserr   docx.oxml.xmlchemyr	   r
   
lxml.etreer   etree_Elementr   r   r   r   r   <module>   s    