
    wdfB                         d Z dZddlZddlmZ 	 eZn# e$ r eZeZY nw xY wd Z	ddZ
dd	Zd
ddddddZeZd ZdZ ed eD                       Zd Zd Z G d de          Z G d de          Zd ZdS )z5
Utility classes for creating dynamic html documents
a  
This file is part of Dominate.

Dominate is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.

Dominate is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General
Public License along with Dominate.  If not, see
<http://www.gnu.org/licenses/>.
    N   )dom_tagc                     t          | d          }|                                }|                                 t          |          S )zA
  includes the contents of a file on disk.
  takes a filename
  r)openreadcloseraw)ffldatas      R/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/dominate/util.pyincluder   "   s7    
 As||"	$((***	T    c                     ddl }|                    | d|j        |j                  }|                    |          \  }}|                    d          S )z#
  pipes the output of a program
  r   NT)shellstdoutstdinutf8)
subprocessPopenPIPEcommunicatedecode)cmdr   r   souterrs         r   systemr   -   sW     s$zjoVV!]]4  (#s	F		r   Tc                     |                      dd          } |                      dd          } |                      dd          } |r|                      dd          } | S )	a+  
  Escapes special characters into their html entities
  Replace special characters "&", "<" and ">" to HTML-safe sequences.
  If the optional flag quote is true, the quotation mark character (")
  is also translated.

  This is used to escape content that appears in the body of an HTML document
  &z&amp;<z&lt;>z&gt;"z&quot;)replace)r   quotes     r   escaper'   7   s]     
c7	#	#$	c6	"	"$	c6	"	"$
 '<<X&&D	+r   "   &   <   >          )quotampltgtnbspyumlc                    t          j        d          }g }|                    |           }|r	|                    | d|                                                    |                    d          }|r2t          |          }|                    t          |                     n]t          	                    |                    d          t          d                    }|                    t          |                     | |                                d         } |                    |           }|	|                    |            d                    |          S )z6
  unescapes html entities. the opposite of escape.
  z&(?:(?:#(\d+))|([^;]+));r   r      ?N )recompilesearchappendstartgroupintunichr	_unescapegetordendjoin)r   ccresultmds        r   unescaperI   U   s    
z-.."&iioo!	 
MM$q{#$$$	

A 
a&&ammF1II
--

CHH
-
-ammF1II>D
		$A 	
  	--	r   z;/?:@&=+$, c              #   >   K   | ]}|d t          |          z  fV  dS )z%%%2XN)rB   .0cs     r   	<genexpr>rN   o   s2      ==aQ#a&&()======r   c                 @    d                     d | D                       S )Nr7   c              3   L   K   | ]}t                               ||          V   d S N)_replace_maprA   rK   s     r   rN   zurl_escape.<locals>.<genexpr>s   s2      66A!!!Q''666666r   )rD   r   s    r   
url_escaperT   r   s#    	66666	6	66r   c                 0    t          j        dd |           S )Nz%([0-9a-fA-F]{2})c                 b    t          t          |                     d          d                    S )Nr      )r?   r>   r=   )rG   s    r   <lambda>zurl_unescape.<locals>.<lambda>x   s"    fSR(()) r   )r8   subrS   s    r   url_unescaperZ   v   s!    	#))4
1 
1 1r   c                   .     e Zd ZdZd Z fdZd Z xZS )lazyz.
  delays function execution until rendered
  c                 6    t                               |           S )z
    Need to reset this special method or else
    dom_tag will think it's being used as a dectorator.

    This means lazy() can't be used as a dectorator, but
    thinking about when you might want that just confuses me.
    )object__new__)_clsargskwargss      r   r_   zlazy.__new__   s     >>$r   c                     t          t          |                                            || _        || _        || _        d S rQ   )superr\   __init__funcra   rb   )selfrf   ra   rb   	__class__s       r   re   zlazy.__init__   s8    	$   DIDIDKKKr   c                 x     | j         | j        i | j        }|                    t	          |                     d S rQ   )rf   ra   rb   r;   str)rg   sbakwr   s        r   _renderzlazy._render   s:    	49,,,AIIc!ffr   )__name__
__module____qualname____doc__r_   re   rn   __classcell__rh   s   @r   r\   r\   {   s`                        r   r\   c                   2     e Zd ZdZdZdZd fd	Zd Z xZS )textz7
  Just a string. useful for inside context managers
  FTc                     t          t          |                                            |rt          |          | _        d S || _        d S rQ   )rd   rv   re   
str_escape)rg   _textr'   rh   s      r   re   ztext.__init__   sE    	$    U##diiidiiir   c                 :    |                     | j                   |S rQ   )r;   rv   )rg   rk   rl   rm   s       r   rn   ztext._render   s    IIdiIr   T)	ro   rp   rq   rr   	is_pretty	is_inlinere   rn   rs   rt   s   @r   rv   rv      sb          ))           r   rv   c                 $    t          | d          S )z0
  Inserts a raw string into the DOM. Unsafe.
  F)r'   )rv   )r   s    r   r
   r
      s     
a			r   rQ   r{   )rr   __license__r8   r   
basestring	NameErrorrj   chrr?   r   r   r'   r@   rx   rI   	_reserveddictrR   rT   rZ   r\   rv   r
    r   r   <module>r      s   $ 
			      **   *&&&
        $ 



 	 		 
  2 	t==9=====7 7 71 1 1
    7   6    7   &    s    	