
    eB1i                         d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	Z	ddlZej                  d   dk(  reZdZedfedfedfed	fed
fedfedfdZ G d de      Zy)z:Class to show and manipulate user fields in odf documents.    N)UserFieldDecl)OFFICENS)load   zutf-8valuez
date-valuez
time-valuezboolean-valuezstring-value)float
percentagecurrencydatetimebooleanstringc                   R    e Zd ZdZdZdZddZd Zd Zd Z	ddZ
d Zd	 Zd
 Zd Zy)
UserFieldsz&List, view and manipulate user fields.Nc                 B   |dk(  s@dt        |      v s3dt        |      v s&dt        |      v st        |      t        d      k(  sJ |dk(  s@dt        |      v s3dt        |      v s&dt        |      v st        |      t        d      k(  sJ || _        || _        d| _        y)a  Constructor

        @param src open file in binary mode: source document,
        or filename as a unicode string, or None for stdin.
        @param dest opendile in binary mode: destination document,
        or filename as a unicode string, or None for stdout.
        NrbBufferedReaderBytesIO wbBufferedWriter)reprtypesrc_file	dest_filedocument)selfsrcdests      @/var/www/html/venv/lib/python3.12/site-packages/odf/userfield.py__init__zUserFields.__init__9   s     DyDDI-1AT#Y1NR[_cdg_hRhlpqtluw{|  xA  mA  	B  ATzTT$Z/3CtDz3QU^bfgkblUlptuypz  }A  BE  }F  qF  	G  F    c                    t         j                  d   dk(  r>t        | j                  t              sTt        | j                  t
        j                        s0t         j                  d   dk(  rQt        | j                  t              r7t        j                  | j                        s9t        d| j                  z        | j                  t         j                  | _        t        | j                        | _        y )Nr   r      z%s is no odt file.)sysversion_info
isinstancer   strioIOBase
basestringzipfile
is_zipfile	TypeErrorstdinr   r   r   s    r    loaddoczUserFields.loaddocG   s    Q"
4==#(F:VZVcVcegenenKowz  xH  xH  IJ  xK  MN  xN  S]  ^b  ^k  ^k  mw  Sx%%dmm4 5 EFF]]"IIDMT]]+r"   c                     | j                   | j                  j                  d       y | j                  j                  | j                          y )N-)r   r   saver0   s    r    savedoczUserFields.savedocR   s4    >>!MMt$MMt~~.r"   c                 N    | j                         D cg c]  }|d   	 c}S c c}w )zlList (extract) all known user-fields.

        @return list of user-field names as unicode strings.
        r   list_fields_and_values)r   xs     r    list_fieldszUserFields.list_fieldsZ   s%    
 #99;<!<<<s   "c                 @   | j                          g }| j                  j                  t              }|D ]g  }|j	                  d      }|dk(  r|j	                  d      }n|j	                  d      }|j	                  d      }|||v sT|j                  |||f       i |S )a(  List (extract) user-fields with type and value.

        @param field_names list of field names as unicode strings
        to show, or None for all.

        @return list of tuples (<field name>, <field type>, <value>)
        as type (unicode string, stringified type, unicode string).

        	valuetyper   stringvaluer   name)r1   r   getElementsByTyper   getAttributeappend)r   field_namesfound_fields
all_fieldsf
value_typer   
field_names           r    r8   z!UserFields.list_fields_and_valuesa   s     	]]44]C
 	-A5JY&~6x00J"jK&?##Z%/%*%, -	- r"   c                 P    | j                  |      D cg c]  }|d   	 c}S c c}w )zExtract the contents of given field names from the file.

        @param field_names list of field names as unicode strings

        @return list of field values as unicode strings.

        r$   r7   )r   rB   r9   s      r    list_valueszUserFields.list_values|   s'     #99+FG!GGGs   #c                 h    t        |      t        d      k(  sJ | j                  |g      }|sy|d   S )zExtract the contents of this field from the file.
        @param field_name unicode string: name of a field
        @return field value as a unicode string or None if field does not exist.

        r   Nr   )r   rI   )r   rG   valuess      r    getzUserFields.get   s=     Jc*+*!!:,/ayr"   c                 x    t        |      t        d      k(  sJ | j                  |g      }|sy|d   \  }}}||fS )zExtract the type and contents of this field from the file.
        @param field_name unicode string: name of a field
        @return tuple (<type>, <field-value>) as a pair of unicode strings
        or None if field does not exist.

        r   Nr   )r   r8   )r   rG   fieldsrF   r   s        r    get_type_and_valuezUserFields.get_type_and_value   sN     Jc*+*,,j\:(.q	%
J5  r"   c                 T   | j                          | j                  j                  t              }|D ]d  }|j	                  d      }||v s|j	                  d      }|j                  |      }|dk(  r|j                  d|       S|j                  d|       f | j                          y)zSet the value of user fields. The field types will be the same.

        data ... dict, with field name as key, field value as value

        Returns None

        r>   r<   r   r=   r   N)r1   r   r?   r   r@   rL   setAttributer5   )r   datarD   rE   rG   rF   r   s          r    updatezUserFields.update   s     	]]44]C
 	4A0JT!^^L9
,*NN>59NN8U3	4 	r"   )NN)N)__name__
__module____qualname____doc__r   r   r!   r1   r5   r:   r8   rI   rL   rO   rS    r"   r    r   r   2   s?    0 HI	,/=6H
!r"   r   )rW   r%   r,   odf.textr   odf.namespacesr   odf.opendocumentr   r)   r&   r(   unicodeOUTENCODINGVALUE_TYPESobjectr   rX   r"   r    <module>r`      s   , A 
  " # ! AG
 "h'H%&&+,/*A Ar"   