U
    6#^                     @   s  d Z ddlZddlZddlZddlZddlZddlZddlZej	
ej	e ddlmZmZ ddlT ddlmZ ddlmZ ddlT ddlmZ ddlmZ ddlmZ ddlmZ ddlZejd dkre Z!e"Z#d	Z$d
Z%dZ&dZ'ejd dkrejd dks
t(dddddddddddddddddZ)G dd dZ*G d d! d!Z+d"d# Z,d$d% Z-d&d' Z.d(d) Z/d*d+ Z0d,d- Z1d.d/ Z2d0d1 Z3d2d3 Z4d4d5 Z5d6d7 Z6dS )8z,Use OpenDocument to generate your documents.    N)StringIOBytesIO)*)make_NCName)InputSource)manifestlist   z'<?xml version='1.0' encoding='UTF-8'?>
l     H       z.odtz.ottz.odgz.otgz.odpz.otpz.odsz.otsz.odcz.otcz.odiz.otiz.odfz.otfz.odmz.oth)'application/vnd.oasis.opendocument.textz0application/vnd.oasis.opendocument.text-template+application/vnd.oasis.opendocument.graphicsz4application/vnd.oasis.opendocument.graphics-template/application/vnd.oasis.opendocument.presentationz8application/vnd.oasis.opendocument.presentation-template.application/vnd.oasis.opendocument.spreadsheetz7application/vnd.oasis.opendocument.spreadsheet-template(application/vnd.oasis.opendocument.chartz1application/vnd.oasis.opendocument.chart-template(application/vnd.oasis.opendocument.imagez1application/vnd.oasis.opendocument.image-template*application/vnd.oasis.opendocument.formulaz3application/vnd.oasis.opendocument.formula-template.application/vnd.oasis.opendocument.text-masterz+application/vnd.oasis.opendocument.text-webc                   @   s   e Zd ZdZdddZdS )OpaqueObjectzK
    just a record to bear a filename, a mediatype and a bytes content
    Nc                 C   sZ   t |t dkstt |t dks(tt |t dksD|dksDt|| _|| _|| _dS )z
        the constructor
        @param filename a unicode string
        @param mediatype a unicode string
        @param content a byte string or None
             N)typeAssertionError	mediatypefilenamecontent)selfr   r   r    r   P/var/www/html/UseVoiceDocker/env/lib/python3.8/site-packages/odf/opendocument.py__init__c   s    zOpaqueObject.__init__)N)__name__
__module____qualname____doc__r   r   r   r   r   r   _   s   r   c                   @   s$  e Zd ZdZdZdFddZdGddZdd	 Zd
d Zdd Z	dd Z
dHddZdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" ZdId#d$ZdJd%d&Zd'd( ZdKd)d*ZdLd+d,Zd-d. Zd/d0 ZdMd2d3Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Z d>d? Z!d@dA Z"dBdC Z#dDdE Z$dS )NOpenDocumentz
    A class to hold the content of an OpenDocument document
    Use the xml method to write the XML
    source to the screen or to a file.
    Example of use: d = OpenDocument(mimetype); fd.write(d.xml())
    NTc                 C   s,  t |t dkstt|djs$t|| _g | _g | _d| _t| jd| _	| | j	_
|   i | _t | _| j	| j |r| jtjtd t | _| j	| j t | _| j	| j t | _| j	| j t | _| j	| j t | _| j	| j t | _| j	| j t | _| j	| j dS )zq
        the constructor
        @param mimetype a unicode string
        @param add_generator a boolean
        r   T)mimetypetextN) r   r   
isinstance	__class__r$   childobjects_extrafolderZDocumenttopnodeZownerDocumentclear_cachesPicturesZMetameta
addElement	GeneratorTOOLSVERSIONZScriptsscriptsZFontFaceDeclsfontfacedeclsZSettingssettingsZStylesstylesAutomaticStylesautomaticstylesZMasterStylesmasterstylesBodybody)r   r$   add_generatorr   r   r   r   {   s8    zOpenDocument.__init__c                 C   s@   |d kr| j }| | |jD ]}|jtjjkr| | qd S )N)r,   build_caches
childNodesnodeTypeelementNodeELEMENT_NODErebuild_caches)r   nodeer   r   r   rC      s     

zOpenDocument.rebuild_cachesc                 C   s   i | _ i | _i | _dS )z(
        Clears internal caches
        N)element_dict_styles_dict_styles_ooo_fixr   r   r   r   r-      s    zOpenDocument.clear_cachesc                 C   s   ddl }t|tjs&t||jjs&t|j| jkr>g | j|j< | j|j | |jtdfkrh| 	| |
td}|dk	r|| jkr|td| j|  dS )zo
        Builds internal caches; called from element.py
        @param elt an element.Element instance
        r   Nstyle
style-name)odf.elementr'   r@   Elementr   qnamerF   appendSTYLENS!_OpenDocument__register_stylename	getAttrNSTEXTNSrH   	setAttrNS)r   eltodfstylerefr   r   r   r=      s    	
zOpenDocument.build_cachesc                 C   s~   ddl }t|tjs&t||jjs&t| j|j | |jD ]}|j	tj
jkr>| | q>|jtdfkrz| j|td= dS )zy
        Updates internal caches when an element has been removed
        @param elt an element.Element instance
        r   NrJ   name)rL   r'   r@   rM   r   rF   rN   remover>   r?   rA   rB   remove_from_cachesrP   rG   rR   )r   rU   rV   rE   r   r   r   rZ      s    
zOpenDocument.remove_from_cachesc                 C   s|   t |tjst|td}|dkr(dS |jjtdftdffkrx|| j	krnd| }|| j
|< |}|td| || j	|< dS )z
        Register a style. But there are three style dictionaries:
        office:styles, office:automatic-styles and office:master-styles
        Chapter 14.
        @param elt an element.Element instance
        rX   Nr6   zautomatic-stylesM)r'   r@   rM   r   rR   rP   Z
parentNoderN   ZOFFICENSrG   rH   rT   )r   rU   rX   Znewnamer   r   r   Z__register_stylename   s    

z!OpenDocument.__register_stylenamer   c                 C   s   t |t dkstd}t }tjd dkr8|t n
|t | jd| |s^|	 }n&t
j|ddd}||	  |  |S )a  
        converts the document to a valid Xml format.
        @param filename unicode string: the name of a file, defaults to
        an empty string.
        @return if filename is not empty, the XML code will be written into it
        and the method returns None; otherwise the method returns a StringIO
        containing valid XML.
        Then a ".getvalue()" should return a unicode string.
        r   Nr   r
   wutf-8)encoding)r   r   r   sysversion_infowrite_XMLPROLOGUEr;   toXmlgetvaluecodecsopenclose)r   r   resultxmlfr   r   r   rc      s    


zOpenDocument.toXmlc                 C   sN   |    t }tjd dkr(|t n
|t | jd| | 	dS )zm
        Generates the full document as an XML "file"
        @return a bytestream in UTF-8 encoding
        r   r
   r]   )
_OpenDocument__replaceGeneratorr   r_   r`   ra   rb   r,   rc   rd   encode)r   ri   r   r   r   ri     s    
zOpenDocument.xmlc                 C   s   t  }|t t }|d| | j r:| jd| | j rR| jd| t	 }| 
| j| j| jg}t|dkr|d| |D ]}|d| q|d| n|d| | jd| |d| | dS )z_
        Generates the content.xml file
        @return a bytestream in UTF-8 encoding
        r   r	   r
   r]   )r   ra   rb   ZDocumentContentwrite_open_tagr3   hasChildNodesrc   r4   r7   _used_auto_stylesr6   r8   r;   lenwrite_close_tagrd   rl   )r   ri   xa	stylelistsr   r   r   
contentxml  s&    


zOpenDocument.contentxmlc                 C   s>   t  }|t | jd| | }t|tdks:t|S )z
        Generates the manifest.xml file;
        The self.manifest isn't avaible unless the document is being saved
        @return a unicode string
        r   r   )r   ra   rb   manifestrc   rd   r   r   )r   ri   rh   r   r   r   Z__manifestxml/  s    
zOpenDocument.__manifestxmlc                 C   sV   |    t }|| j t }|t |d| | }t	|t	dksRt
|S )zN
        Generates the meta.xml file
        @return a unicode string
        r   r   )rk   ZDocumentMetar0   r/   r   ra   rb   rc   rd   r   r   r   rr   ri   rh   r   r   r   metaxml<  s    
zOpenDocument.metaxmlc                 C   sh   t  }|| j t }tjd dkr2|t n
|t |d| |	 }t
|t
dksdt|S )zR
        Generates the settings.xml file
        @return a unicode string
        r   r
   r   )ZDocumentSettingsr0   r5   r   r_   r`   ra   rb   rc   rd   r   r   rx   r   r   r   settingsxmlK  s    
zOpenDocument.settingsxmlc                 C   s   |j D ]}|jtjjkrtdftdftdftdftdftdftdftdft	dft	dft
dffD ]B}||d |d r^||d |d }||kr^|t| q^| ||}q|S )	z
        Finds references to style objects in master-styles
        and add the style name to the style list if not already there.
        Recursive
        @return the list of style names as unicode strings
        rK   ztext-style-namezdata-style-namezlist-style-namezpage-layout-namezdefault-cell-style-namer   r	   )r>   r?   r@   rA   rB   ZCHARTNSZDRAWNSZPRESENTATIONNSrP   ZTABLENSrS   rR   rO   unicode_parseoneelement)r   topstylenamelistrE   rW   Z	stylenamer   r   r   r|   \  s(    
zOpenDocument._parseoneelementc                 C   s|   g }|D ]}|  ||}qg }| jjD ]*}t|tjr&|td|kr&|| q&d}|D ]}|olt|tj}qZ|sxt	|S )z
        Loop through the masterstyles elements, and find the automatic
        styles that are used. These will be added to the automatic-styles
        element in styles.xml
        @return a list of element.Element instances
        rX   T)
r|   r8   r>   r'   r@   rM   rR   rP   rO   r   )r   segmentsr~   r}   rt   rE   okr   r   r   ro   z  s     zOpenDocument._used_auto_stylesc                 C   s   t  }|t t }|d| | j r:| jd| | jd| t	 }|d| | 
| jgD ]}|d| qh|d| | j r| jd| |d| | }t|tdkst|S )zb
        Generates the styles.xml file
        @return valid XML code as a unicode string
        r   r	   r
   r   )r   ra   rb   ZDocumentStylesrm   r4   rn   rc   r6   r7   ro   r9   rq   rd   r   r   )r   ri   rr   rs   ru   rh   r   r   r   	stylesxml  s$    


zOpenDocument.stylesxmlc                 C   s   |dkr|dkrt |\}}|dkrTd}z||dd }W q^   d}Y q^X n
t |}dt j |f }t||f| j	|< d}d}n|}t
||f| j	|< t|tdkstt|tdkst|S )a  
        Add a picture
        It uses the same convention as OOo, in that it saves the picture in
        the zipfile in the subdirectory 'Pictures'
        If passed a file ptr, mediatype must be set
        @param filename unicode string: name of a file for Pictures
        @param mediatype unicode string: name of a media, None by default
        @param content bytes: content of media, None by default
        @return a unicode string: the file name of the media, eventually
        created on the fly
        Nr   .Pictures/%s%sr   )	mimetypes
guess_typerindexguess_extensionuuiduuid4hexupperIS_FILENAMEr.   IS_IMAGEr   r   )r   r   r   r   r^   ext
manifestfnr   r   r   
addPicture  s&      
zOpenDocument.addPicturec                 C   s   |dkrt |\}}|dkrTd}z||dd }W q^ tk
rP   d}Y q^X n
t |}dt j |f }t	||f| j
|< t|tdkstt|tdkst|S )a  
        Add a picture
        It uses the same convention as OOo, in that it saves the picture in
        the zipfile in the subdirectory 'Pictures'.
        If mediatype is not given, it will be guessed from the filename
        extension.
        @param filesname unicode string: name of an image file
        @param mediatype unicode string: type of media, dfaults to None
        @return a unicode string, the name of the created file
        Nr   r   r   )r   r   r   
ValueErrorr   r   r   r   r   r   r.   r   r   )r   r   r   r^   r   r   r   r   r   addPictureFromFile  s      
zOpenDocument.addPictureFromFilec                 C   s\   t |t dkstt |t dks(tt|}dt j |f }t||f| j	|< |S )a  
        Add a picture from contents given as a Byte string.
        It uses the same convention as OOo, in that it saves the picture in
        the zipfile in the subdirectory 'Pictures'. The content variable
        is a string that contains the binary image data. The mediatype
        indicates the image format.
        @param content bytes: content of media
        @param mediatype unicode string: name of a media
        @return a unicode string, the name of the created file
        r   r   r   )
r   r   r   r   r   r   r   r   r   r.   )r   r   r   r   r   r   r   r   addPictureFromString  s    
z!OpenDocument.addPictureFromStringc                 C   s:   t |t dkst|dkr0ddl}| | _n|| _dS )z
        Add a fixed thumbnail
        The thumbnail in the library is big, so this is pretty useless.
        @param filecontent bytes: the content of a file; defaults to None
        r   Nr   )r   r   	thumbnail)r   Zfilecontentr   r   r   r   addThumbnail  s
    zOpenDocument.addThumbnailc                 C   sf   t |tstt|tdks*|dks*t| j| |dkrVd| jt| jf |_n||_d|j S )a/  
        Adds an object (subdocument). The object must be an OpenDocument class
        @param document OpenDocument instance
        @param objectname unicode string: the name of an object to add
        @return a unicode string: the folder name in the zipfile the object is
        stored in.
        r   Nz%s/Object %dz.%s)r'   r#   r   r   r)   rO   r+   rp   )r   ZdocumentZ
objectnamer   r   r   	addObject  s    zOpenDocument.addObjectc                 C   s   t |tstt|tdks"td}|j D ]\}}|\}}}| jtjd||f |d d}|t	kr| j
||| tj q0tt|| j}	tj|	_t|	_| j
|	| q0d}
|jD ] }| |d||
f  |
d7 }
qdS )	z
        saves pictures contained in an object
        @param anObject instance of OpenDocument containing pictures
        @param folder unicode string: place to save pictures
        r   Fz%s%sfullpathr   Tr	   %sObject %d/N)r'   r#   r   r   r.   itemsrw   r0   	FileEntryr   _zra   zipfile
ZIP_STOREDZipInfostr_nowcompress_type	UNIXPERMSexternal_attrwritestrr)   _savePictures)r   anObjectr+   ZhasPicturesarcnameZ
picturerecZ
what_it_isfileobjr   zisubobjectnum	subobjectr   r   r   r     s"    

zOpenDocument._savePicturesc                 C   sH   | j jdd D ]}|jtdfkr| j | q| j t jtd dS )z
        Removes a previous 'generator' stance and declares TOOLSVERSION
        as the new generator.
        Section 3.1.1: The application MUST NOT export the original identifier
        belonging to the application that created the document.
        N	generatorr%   )r/   r>   rN   ZMETANSZremoveChildr0   r1   r2   )r   mr   r   r   Z__replaceGenerator8  s    zOpenDocument.__replaceGeneratorFc                 C   sP   |dkrt tjd}n"|r.|t| jd }t |d}| | |  dS )ao  
        Save the document under the filename.
        If the filename is '-' then save to stdout
        @param outputfile unicode string: the special name '-' is for stdout;
        as an alternative, it can be an io.ByteIO instance which contains
        the ZIP content.
        @param addsuffix boolean: whether to add a suffix or not; defaults to False
        -r\   z.xxxN)	r   ZipFiler_   stdoutodmimetypesgetr$   _OpenDocument__zipwriterg   )r   Z
outputfileZ	addsuffixoutputfpr   r   r   saveD  s    

zOpenDocument.savec                 C   s   t |d}| | dS )z
        User API to write the ODF file to an open file descriptor
        Writes the ZIP format
        @param outputfp open file descriptor
        r\   N)r   r   r   )r   r   Zzipoutputfpr   r   r   ra   W  s    zOpenDocument.writec                 C   s  t |tjst|| _t dd | _t	 | _t
d| j}tj|_t|_| j|| jd | | d | | d | jdk	r| jtjddd | jtjddd t
d| j}tj|_t|_| j|| j | jD ]}|jd	krq| jtj|j|jd tjd
 dkr0t
|j| j}nt
|jd| j}tj|_t|_|jdk	r| j||j qt
d| j}tj|_t|_| j||   | `| `| `dS )z
        Write the document to an open file pointer
        This is where the real work is done
        @param outputfp instance of zipfile.ZipFile
        N   r$   r]   r   zThumbnails/r   Thumbnails/thumbnail.pngzMETA-INF/documentsignatures.xmlr   r   META-INF/manifest.xml)r'   r   r   r   r   time	localtimer   rw   ZManifestr   r   r   r   r   r   r$   rl   _saveXmlObjectsr   r   r0   r   ZIP_DEFLATEDr*   r   r   r_   r`   r   _OpenDocument__manifestxml)r   r   r   opr   r   r   Z
__zipwrite`  sF    



 
zOpenDocument.__zipwritec                 C   s  t |tstt|tdks"t| |krD| jtjd|jd n| jtj||jd | jtjd| dd t	d| | j
}tj|_t|_| j|| d | jtjd| dd t	d| | j
}tj|_t|_| j||  |j rX| jtjd| dd t	d| | j
}tj|_t|_| j|| d | |kr| jtjd	dd t	d	| j
}tj|_t|_| j|| d d
}|jD ]"}| |d||f  |d
7 }qdS )z
        save xml objects of an opendocument to some folder
        @param anObject instance of OpenDocument
        @param folder unicode string place to save xml objects
        r   /r   z%sstyles.xmlztext/xmlr]   z%scontent.xmlz%ssettings.xmlmeta.xmlr	   r   N)r'   r#   r   r   rw   r0   r   r$   r   r   r   r   r   r   r   r   r   r   rl   rv   r5   rn   rz   ry   r)   r   )r   r   r+   r   r   r   r   r   r   r     s>    

zOpenDocument._saveXmlObjectsc                 C   s   t |tjst|ddS )a  
        Inconvenient interface to create an element, but follows XML-DOM.
        Does not allow attributes as argument, therefore can't check grammar.
        @param elt element.Element instance
        @return an element.Element instance whose grammar is not checked
        FZcheck_grammar)r'   r@   rM   r   )r   rU   r   r   r   createElement  s    zOpenDocument.createElementc                 C   s   t |t dkstt|S )z
        Method to create a text node
        @param data unicode string to include in the Text element
        @return an instance of element.Text
        r   )r   r   r@   Textr   datar   r   r   createTextNode  s    zOpenDocument.createTextNodec                 C   s   t |t dkstttS )z
        Method to create a CDATA section
        @param data unicode string to include in the CDATA element
        @return an instance of element.CDATASection
        r   )r   r   r@   ZCDATASectioncdatar   r   r   r   createCDATASection  s    zOpenDocument.createCDATASectionc                 C   s   t | jt dkst| jS )zI
        Returns the media type
        @result a unicode string
        r   )r   r$   r   rI   r   r   r   getMediaType  s    zOpenDocument.getMediaTypec                 C   sP   t |t dkstt|}| ji kr.|   | j|d}t|tjsLt|S )z
        Finds a style object based on the name
        @param name unicode string the name of style to search
        @return a syle as an element.Element instance
        r   N)	r   r   r   rG   rC   r   r'   r@   rM   )r   rX   Zncnamerh   r   r   r   getStyleByName  s    
zOpenDocument.getStyleByNamec                 C   s~   ddl }t||jst|dd}t|tjs2t| ji krD|   | j|j	g }d}|D ]}|ont|tj}q\|szt|S )z
        Gets elements based on the type, which is function from
        text.py, draw.py etc.
        @param elt instance of a function which returns an element.Element
        @return a list of istances of element.Element
        r   NFr   T)
typesr'   FunctionTyper   r@   rM   rF   rC   r   rN   )r   rU   r   objrh   r   rE   r   r   r   getElementsByType  s    

 zOpenDocument.getElementsByType)T)N)r   )NN)N)N)N)F)%r   r    r!   r"   r   r   rC   r-   r=   rZ   rQ   rc   ri   rv   r   ry   rz   r|   ro   r   r   r   r   r   r   r   rk   r   ra   r   r   r   r   r   r   r   r   r   r   r   r   r#   r   sD   
&


"



	62

	r#   c                  C   s"   t d} t | _| j| j | S )z[
    Creates a chart document
    @return an OpenDocument instance with chart mimetype
    r   )r#   ZChartchartr;   r0   docr   r   r   OpenDocumentChart"  s    r   c                  C   s"   t d} t | _| j| j | S )z_
    Creates a drawing document
    @return an OpenDocument instance with drawing mimetype
    r   )r#   ZDrawingZdrawingr;   r0   r   r   r   r   OpenDocumentDrawing,  s    r   c                  C   s"   t d} t | _| j| j | S )z\
    Creates an image document
    @return an OpenDocument instance with image mimetype
    r   )r#   ZImageimager;   r0   r   r   r   r   OpenDocumentImage6  s    r   c                  C   s"   t d} t | _| j| j | S )zi
    Creates a presentation document
    @return an OpenDocument instance with presentation mimetype
    r   )r#   ZPresentationpresentationr;   r0   r   r   r   r   OpenDocumentPresentation@  s    r   c                  C   s"   t d} t | _| j| j | S )zg
    Creates a spreadsheet document
    @return an OpenDocument instance with spreadsheet mimetype
    r   )r#   ZSpreadsheetspreadsheetr;   r0   r   r   r   r   OpenDocumentSpreadsheetJ  s    r   c                  C   s"   t d} t | _| j| j | S )zY
    Creates a text document
    @return an OpenDocument instance with text mimetype
    r   r#   r   r&   r;   r0   r   r   r   r   OpenDocumentTextT  s    r   c                  C   s"   t d} t | _| j| j | S )zb
    Creates a text master document
    @return an OpenDocument instance with master mimetype
    r   r   r   r   r   r   OpenDocumentTextMaster^  s    r   c                 C   st  t | tjstt|tt ks&tt |ts4tt|tdksHtddlm} ddl	m
} ddlm} |d |d |d |d	 fD ]}||krqdd
lm} z| |d}	||_| }
|
|jd |
|jd |
|| |
|  t }t|	}	|t|	d |
| |`W q tk
rN } zW 5 d}~X Y q |k
rl   td|	 Y qX qdS )a   
    Parses a document from its zipfile
    @param z an instance of zipfile.ZipFile
    @param manifest Manifest data structured in a dictionary
    @param doc instance of OpenDocument to feed in
    @param objectpath unicode string: path to an object
    r   r   )
LoadParser)make_parser)handlersettings.xmlr   content.xml
styles.xml)SAXParseExceptionr]   r	   Nz&====== SAX FAILED TO PARSE ==========
) r'   r   r   r   r   dictr#   Zodf.loadr   Zdefusedxml.saxr   Zxml.saxr   Zxml.sax._exceptionsr   readdecodeZ_parsingZ
setFeatureZfeature_namespacesZfeature_external_gesZsetContentHandlerZsetErrorHandlerZErrorHandlerr   __fixXmlPartZsetByteStreamr   rl   parseKeyErrorprint)zrw   r   Z
objectpathr   r   r   Zxmlfiler   xmlpartparserZinpsrcvr   r   r   __loadxmlpartsh  s8     
 r   c                 C   sj   | }d}|D ]X}dj |d| krz6|d}dj |d}|d| | ||d  }W q   Y qX q|S )z
    fixes an xml code when it does not contain a set of requested
    "xmlns:whatever" declarations.
    added by G.K. on 2014/10/21
    @param xmlpart unicode string: some XML code
    @return fixed XML code
    )	r/   configZdcrJ   ZsvgfoZdrawtableZformz xmlns:{prefix})prefixz xmlns:zD xmlns:{prefix}="urn:oasis:names:tc:opendocument:xmlns:{prefix}:1.0"N)formatindex)r   rh   ZrequestedPrefixesr   posZtoInsertr   r   r   r     s    
 r   c                 C   s   t | tjstz| dd}|W S    Y nX | d}t|}| D ]4\}}|dkrNt|d tdksvt|d   S qNdS )z
    detects the mime-type of an ODF file
    @param zipfd an open zipfile.ZipFile instance
    @param odffile this parameter is not used
    @return a mime-type as a unicode string
    r$   r]   r   r   
media-typer   r   )	r'   r   r   r   r   r   r   r   r   )Zzipfdodffiler$   manifestpartrw   mentrymvaluer   r   r   __detectmimetype  s    
r   c           
   	   C   sr  t | }t|| }t|dd}|d}t|}t|||d | D ]2\}}|dd dkrt|dkr|	|d |d	 || qH|d
kr|
|| qH|dkrqH|dd dkrt|dk r|d dkrt|d	 dd}||d|dd   t|||| qH|dd dkr*qH|d d dkrZ|jt|d |d	 d qH|jt|d |d	 || qH|  |t}	|dd dkr|	d j|_n|dd dkr|	d j|_n|dd dkr|	d j|_n~|dd dkr|	d j|_n^|dd dkr0|	d j|_n>|dd dkrP|	d j|_n|dd dkrn|	d j|_|S )z
    Load an ODF file into memory
    @param odffile unicode string: name of a file, or as an alternative,
    an open readable stream
    @return a reference to the structure (an OpenDocument instance)
    F)r<   r   r   N	   z	Pictures/z	full-pathr   r   )r   r   r   r      zObject    r   '   r   r   +   r   /   r   .   r   (   r   r   *   r   )r   r   r   r#   r   r   r   r   rp   r   r   r   r*   rO   r   rg   r   r:   Z
firstChildr&   Zgraphicsr   r   r   r   Zformula)
r   r   r$   r   r   rw   r   r   Zsubdocbr   r   r   load  sN    


.$
r	  )7r"   r   r   r   r_   r   copyos.pathospathrO   dirname__file__ior   r   Zodf.namespacesZodf.manifestrw   Zodf.metar/   Z
odf.officerL   r@   Zodf.attrconvertersr   Zxml.sax.xmlreaderr   Zodf.odfmanifestr   re   r`   r   r{   r2   __version__rb   r   r   r   r   r   r   r#   r   r   r   r   r   r   r   r   r   r   r	  r   r   r   r   <module>   sn   8
$
     5






2