U
    !eYQ                     @   s  d Z dZdee f Zze ddlZW n   eZeZeZY nX ddlZG dd dZ	G dd dZ
G d	d
 d
ZeddZeddZeddZdd Zdd Zd0ddZeZdd ZG dd dZe Zde_de_de_G dd dZG dd  d eZG d!d" d"eZG d#d$ d$eZG d%d& d&eZG d'd( d(eZG d)d* d*eZ G d+d, d,eZ!G d-d. d.eZ"e#d/krddl$Z$e$j%&e dS )1z16 March 2015z1.10a  
This is markup.py - a Python module that attempts to
make it easier to generate HTML/XML from a Python program
in an intuitive, lightweight, customizable and pythonic way.
It works with both python 2 and 3.

The code is in the public domain.

Version: %s as of %s.

Documentation and further info is at http://markup.sourceforge.net/

Please send bug reports, feature requests, enhancement
ideas or questions to nogradi at gmail dot com.

Installation: drop markup.py somewhere into your Python path.
    Nc                   @   s:   e Zd ZdZdddZdd Zdd	 Zd
d Zdd ZdS )elementz1This class handles the addition of a new element.lowerNc                 C   sH   || _ |dkr| | _n*|dkr.| | _n|dkr>|| _n|| _d S )Nupperr   given)parentr   tagr   )selfr   caser    r
   O/var/www/html/UseVoiceDocker/env/lib/python3.8/site-packages/MarkupPy/markup.py__init__)   s    zelement.__init__c                    sx  t |dkrt j jd k	r@ jjd k	r@d|kr@ jj|d<  jd krxt |dkrx fddt||D }d|S  jd krt |dkr fddt||D }d|S  j jjkrt||D ]\}}  jd|| qn j jj	kr:t |dkr.t||D ]\}}  jd	|| qn
t
 jn: jjd
krd j jjkrdt jnt j jjd S )N   class_c                    s"   g | ]\}}   jd ||qS )Frenderr   .0myargmydictr   r
   r   
<listcomp>?   s     z$element.__call__.<locals>.<listcomp>
r   c                    s"   g | ]\}}   jd ||qS )Tr   r   r   r
   r   r   B   s     FTstrict_html)lenArgumentErrorr   r   r   
_argsdictsjointwotagsr   onetagsClosingErrormodedeptagsDeprecationErrorInvalidElementError)r   argskwargsxr   r   r
   r   r   __call__5   s,    


zelement.__call__c                 C   s   d| }t | D ]T\}}|dk	r\|d}|dkr<d}n|dkrHd}d||t|f }qd	||f }q|dk	rd
|||f }n|rd| }nd| }| jdk	r| jj| n|S dS )z"Append the actual tags to content.z<%sN_
http_equivz
http-equivZaccept_charsetzaccept-charsetz
%s %s="%s"z%s %sz
%s>%s</%s>z%s />z%s>)listitemsstripescaper   contentappend)r   r   ZsingleZbetweenr%   outkeyvaluer
   r
   r   r   S   s$    


zelement.renderc                 C   sf   | j | jjkr$| jjd| j   n>| j | jjkr>t| j n$| jjdkrb| j | jjkrbt	| j dS )z9Append a closing tag unless element has only opening tag.z</%s>r   N)
r   r   r   r.   r/   r   r   r    r!   r"   r   r
   r
   r   closem   s    zelement.closec                 K   sV   | j | jjks| j | jjkr0| | j dd| n"| jdkrR| j | jjkrRt| j dS )zAppend an opening tag.FNr   )r   r   r   r   r   r    r!   r"   )r   r%   r
   r
   r   openw   s    zelement.open)r   N)	__name__
__module____qualname____doc__r   r'   r   r3   r4   r
   r
   r
   r   r   &   s   

r   c                   @   sv   e Zd ZdZd ddZdd	 Zd
d Zd!ddZdd Zdd Z	dd Z
dd Zd"ddZdd Zdd Zdd ZdS )#pagezrThis is our main class representing a document. Elements are added
    as attributes of an instance of this class.r   r   Nr   c              F   C   s<  ddddddddd	d
dg}ddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQgF}dRdSg}	dTdUdVdWdXdYdZd[g}
g | _ g | _g | _|| _|| _d\| _|| _|d]ks|d^krv|| _|  jtt	t
j| j7  _|| _|  jtt	t
j| j7  _|	|
 | _|  jtt	t
j| j7  _d]| _n|d_kr||	 | _|  jtt	t
j| j7  _||
 | _|  jtt	t
j| j7  _|| _nd|d`kr0|r|r|| _|| _n0|r|r|r|st nt | _t | _|| _nt|daS )bal  Stuff that effects the whole document.

        mode -- 'strict_html'   for HTML 4.01 (default)
                'html'          alias for 'strict_html'
                'loose_html'    to allow some deprecated elements
                'xml'           to allow arbitrary elements

        case -- 'lower'         element names will be printed in lower case (default)
                'upper'         they will be printed in upper case
                'given'         element names will be printed as they are given

        onetags --              list or tuple of valid elements with opening tags only
        twotags --              list or tuple of valid elements with both opening and closing tags
                                these two keyword arguments may be used to select
                                the set of valid elements in 'xml' mode
                                invalid elements will raise appropriate exceptions
        
        separator --            string to place between added elements, defaults to newline
        
        class_ --               a class that will be added to every element if definedZAREAZBASEZBRZCOLFRAMEZHRZIMGZINPUTZLINKZMETAZPARAMAZABBRZACRONYMZADDRESSBZBDOZBIGZ
BLOCKQUOTEZBODYZBUTTONZCAPTIONZCITEZCODEZCOLGROUPZDDZDELZDFNZDIVZDLZDTZEMZFIELDSETZFORMZFRAMESETZH1ZH2ZH3ZH4ZH5ZH6ZHEADZHTMLIZIFRAMEZINSZKBDZLABELZLEGENDZLIZMAPZNOFRAMESZNOSCRIPTZOBJECTZOLZOPTGROUPZOPTIONPZPREQZSAMPZSCRIPTZSELECTZSMALLZSPANZSTRONGZSTYLEZSUBZSUPZTABLEZTBODYZTDZTEXTAREAZTFOOTZTHZTHEADZTITLEZTRZTTZULZVARZBASEFONTZISINDEXZAPPLETZCENTERZDIRZFONTZMENUSZSTRIKEUFr   html
loose_htmlxmlN)headerr.   footerr	   	separator_fullr   r   r*   mapstringr   r   r!   r    CustomizationErrorrussell	ModeError)r   r    r	   r   r   rG   r   Zvalid_onetagsZvalid_twotagsZdeprecated_onetagsZdeprecated_twotagsr
   r
   r   r      s                                                          




zpage.__init__c                 C   sR   | dr|drt|| drB|d}|tjkrBt|t|| j| dS N__r(   )r	   r   
startswithendswithAttributeErrorlstripkeywordkwlistr   r	   r   attrr
   r
   r   __getattr__   s    


zpage.__getattr__c                 C   sF   | j r$| jdks| jdkr$ddg}ng }| j| j| j | j | S )Nr   rC   z</body>z</html>)rH   r    rG   r   rE   r.   rF   )r   endr
   r
   r   __str__   s    
zpage.__str__Fc                 C   s   |rt |  S |  S dS )zReturn the document as a string.

        escape --   False   print normally
                    True    replace < and > by &lt; and &gt;
                            the default escape sequences in most browsersN)_escaper[   )r   r-   r
   r
   r   r'      s    zpage.__call__c                 C   s   |  | dS )zThis is an alias to addcontent.N)
addcontentr   textr
   r
   r   add   s    zpage.addc                 C   s   | j | dS )z+Add some text to the bottom of the documentN)rF   r/   r^   r
   r
   r   	addfooter   s    zpage.addfooterc                 C   s   | j | dS )z(Add some text to the top of the documentN)rE   r/   r^   r
   r
   r   	addheader   s    zpage.addheaderc                 C   s   | j | dS )z.Add some text to the main part of the documentN)r.   r/   r^   r
   r
   r   r]      s    zpage.addcontentenc                 C   sT  d| _ | jdks| jdkr|	dkr(d}	| j|	 | j|d |   |dk	rb| jdd| d	 |dk	rt| | |dk	r| | |dk	r| 	| |dk	r| 
| |dk	r| jd
| d | j  |
dk	r| jf |
 n|   |dk	r| j| |dk	rP| j| n:| jdkrP|	dkrD|dk	r@d| }	nd}	| j|	 dS )a  This method is used for complete documents with appropriate
        doctype, encoding, title, etc information. For an HTML/XML snippet
        omit this method.

        lang --     language, usually a two character string, will appear
                    as <html lang='en'> in html mode (ignored in xml mode)
        
        css --      Cascading Style Sheet filename as a string or a list of
                    strings for multiple css files (ignored in xml mode)

        metainfo -- a dictionary in the form { 'name':'content' } to be inserted
                    into meta element(s) as <meta name='name' content='content'>
                    (ignored in xml mode)
        
        base     -- set the <base href="..."> tag in <head>
        
        bodyattrs --a dictionary in the form { 'key':'value', ... } which will be added
                    as attributes of the <body> element as <body key='value' ... >
                    (ignored in xml mode)

        script --   dictionary containing src:type pairs, <script type='text/type' src=src></script>
                    or a list of [ 'src1', 'src2', ... ] in which case 'javascript' is assumed for all

        title --    the title of the document as a string to be inserted into
                    a title element as <title>my title</title> (ignored in xml mode)

        header --   some text to be inserted right after the <body> element
                    (ignored in xml mode)

        footer --   some text to be inserted right before the </body> element
                    (ignored in xml mode)

        charset --  a string defining the character set, will be inserted into a
                    <meta http-equiv='Content-Type' content='text/html; charset=myset'>
                    element (ignored in xml mode)

        encoding -- a string defining the encoding, will be put into to first line of
                    the document as <?xml version='1.0' encoding='myencoding' ?> in
                    xml mode (ignored in html mode)

        doctype --  the document type string, defaults to
                    <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
                    in html mode (ignored in xml mode)Tr   rC   Nz?<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>)langzContent-Typeztext/html; charset=%s)r)   r.   z%s)hrefrD   z$<?xml version='1.0' encoding='%s' ?>z<?xml version='1.0' ?>)rH   r    rE   r/   rB   headmetametainfocsstitlescriptsbaser3   bodyr.   rF   )r   rd   ri   rh   rj   rE   rF   charsetencodingdoctypeZ	bodyattrsscriptrl   r
   r
   r   init   sB    .








z	page.initc                 C   s>   t |tr| j|dddd n|D ]}| j|dddd q"dS )z|This convenience function is only useful for html.
        It adds css stylesheet(s) to the document via the <link> element.Z
stylesheetztext/cssall)re   reltypeZmediaN)
isinstance
basestringlink)r   filelistfiler
   r
   r   ri   P  s    
zpage.cssc                 C   s<   t |tr0t| D ]\}}| j||d qntddS )zThis convenience function is only useful for html.
        It adds meta information via the <meta> element, the argument is
        a dictionary of the form { 'name':'content' }.)namer.   zKMetainfo should be called with a dictionary argument of name:content pairs.N)rv   dictr*   r+   rg   	TypeError)r   r   r{   r.   r
   r
   r   rh   Z  s    
zpage.metainfoc                 C   sn   t |tr6t| D ]\}}| jd|d| d qn4z|D ]}| jd|dd q<W n   tdY nX dS )zOnly useful in html, mydict is dictionary of src:type pairs or a list
        of script sources [ 'src1', 'src2', ... ] in which case 'javascript' is assumed for type.
        Will be rendered as <script type='text/type' src=src></script> ztext/%s)srcru   ztext/javascriptzTScript should be given a dictionary of src:type pairs or a list of javascript src's.N)rv   r|   r*   r+   rq   r}   )r   r   r   ru   r
   r
   r   rk   e  s    
zpage.scripts)r   r   NNr   N)F)rc   NNNNNNNNNNN)r5   r6   r7   r8   r   rY   r[   r'   r`   ra   rb   r]   rr   ri   rh   rk   r
   r
   r
   r   r9      s*   
F	
              
T
r9   c                   @   s"   e Zd ZdZdddZdd ZdS )		_onelinerzAn instance of oneliner returns a string corresponding to one element.
    This class can be used to write 'oneliners' that return a string
    immediately so there is no need to instantiate the page class.r   c                 C   s
   || _ d S Nr	   )r   r	   r
   r
   r   r   z  s    z_oneliner.__init__c                 C   sR   | dr|drt|| drB|d}|tjkrBt|t|| jd dS rN   rP   rW   r
   r
   r   rY   }  s    


z_oneliner.__getattr__N)r   )r5   r6   r7   r8   r   rY   r
   r
   r
   r   r   u  s   
r   r   r   r   r   c           
   
   c   s   t | dkrd} n"t | dkr,t| d } ntdt| }tttt| }tttt | g| }t|D ]}i }t	||D ]:\}}z|| ||< W q t
k
r   |d ||< Y qX qz| | }	W n t
k
r   | d }	Y nX |	|fV  qvdS )zoA utility generator that pads argument list and dictionary values, will only be called with len( args ) = 0, 1.r   r   r   z!We should have never gotten here.N)r   _totuple	Exceptionr*   keysrI   valuesmaxrangezip
IndexError)
r$   r   ZmykeysZmyvaluesZ	maxlengthiZthisdictr1   r2   Zthisargr
   r
   r   r     s(    r   c                 C   sH   t | tr| f}n2t | tttfr.t| f}n| dkr<d}nt| }|S )zVUtility stuff to convert string, int, long, float, None or anything to a usable tuple.Nr   )rv   rw   intlongfloatstrtuple)r&   r0   r
   r
   r   r     s    
r   Fc                 C   s   t | trd| kr| dd} d| kr2| dd} d| krF| dd} d| krZ| dd} d	| krn| d	d} |rd
| kr| d
d} | S )zEscape special html characters.&&amp;>&gt;<&lt;"&quot;'r   z<br>rv   rw   replace)r_   newliner
   r
   r   r-     s    
r-   c                 C   s^   t | trZd| kr| dd} d| kr2| dd} d| krF| dd} d| krZ| dd} | S )	zInverse of escape.r   r   r   r   r   r   r   r   r   )r_   r
   r
   r   unescape  s    
r   c                   @   s   e Zd ZdZdS )dummyz'A dummy class for attaching attributes.N)r5   r6   r7   r8   r
   r
   r
   r   r     s   r   ze<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">zZ<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">zf<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">c                   @   s   e Zd ZdZdd ZdS )rL   z%A dummy class that contains anything.c                 C   s   dS )NTr
   )r   itemr
   r
   r   __contains__  s    zrussell.__contains__N)r5   r6   r7   r8   r   r
   r
   r
   r   rL     s   rL   c                   @   s   e Zd ZdZdd ZdS )MarkupErrorz!All our exceptions subclass this.c                 C   s   | j S r   messager   r
   r
   r   r[     s    zMarkupError.__str__N)r5   r6   r7   r8   r[   r
   r
   r
   r   r     s   r   c                   @   s   e Zd Zdd ZdS )r   c                 C   s   d| | _ d S )NzLThe element '%s' does not accept non-keyword arguments (has no closing tag).r   r   r   r
   r
   r   r     s    zClosingError.__init__Nr5   r6   r7   r   r
   r
   r
   r   r     s   r   c                   @   s   e Zd Zdd ZdS )OpeningErrorc                 C   s   d| | _ d S )Nz#The element '%s' can not be opened.r   r   r
   r
   r   r     s    zOpeningError.__init__Nr   r
   r
   r
   r   r     s   r   c                   @   s   e Zd Zdd ZdS )r   c                 C   s   d| | _ d S )NzDThe element '%s' was called with more than one non-keyword argument.r   r   r
   r
   r   r     s    zArgumentError.__init__Nr   r
   r
   r
   r   r     s   r   c                   @   s   e Zd Zdd ZdS )r#   c                 C   s   d||f | _ d S )Nz1The element '%s' is not valid for your mode '%s'.r   )r   r   r    r
   r
   r   r      s    zInvalidElementError.__init__Nr   r
   r
   r
   r   r#     s   r#   c                   @   s   e Zd Zdd ZdS )r"   c                 C   s   d| | _ d S )Nz[The element '%s' is deprecated, instantiate markup.page with mode='loose_html' to allow it.r   r   r
   r
   r   r     s    zDeprecationError.__init__Nr   r
   r
   r
   r   r"     s   r"   c                   @   s   e Zd Zdd ZdS )rM   c                 C   s   d| | _ d S )NzbMode '%s' is invalid, possible values: strict_html, html (alias for strict_html), loose_html, xml.r   )r   r    r
   r
   r   r     s    zModeError.__init__Nr   r
   r
   r
   r   rM     s   rM   c                   @   s   e Zd Zdd ZdS )rK   c                 C   s
   d| _ d S )NzZIf you customize the allowed elements, you must define both types 'onetags' and 'twotags'.r   r   r
   r
   r   r     s    zCustomizationError.__init__Nr   r
   r
   r
   r   rK     s   rK   __main__)F)'__date____version__r8   rw   rJ   r   r   r   rU   r   r9   r   ZonelinerZupper_onelinerZgiven_onelinerr   r   r-   r\   r   r   rp   ZframesetstrictZlooserL   r   r   r   r   r   r#   r"   rM   rK   r5   sysstdoutwriter
   r
   r
   r   <module>   sR   
Y w




