
O(Oc           @   sv  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 d  d l Z d  d l	 Z	 d  d l
 Z
 d   Z d   Z d d d     YZ d e  j  f d     YZ d e  j  f d	     YZ d
 d d     YZ d e  j  f d     YZ d e  j  f d     YZ d d d     YZ d e  j  f d     YZ d e  j  f d     YZ d e  j  f d     YZ d S(   iNc         C   sS   |  d d !d k r d |  S|  d d !d k rC d t  j |  d  Sd d |  Sd	 S(
   s9   Get internal cherrytree link attribute from HTTP link urli    i   t   https   webs %si   s   file://s   file %ss   http://N(   t   base64t	   b64encode(   t   link_url(    (    s   modules/imports.pyt   get_internal_link_from_http_url   s
      c         C   sK  g  } t  |   } | d } d } x"| | k  rFt } |  | d k rj |  | | d !d k r t } q nf |  | d k r |  | | d !d k r t } q n3 |  | d	 k r |  | | d !d
 k r t } q n  | r9| d } x6 | | k  r|  | t j t j g k r| d 7} q W| j | | g  | d } q% | d 7} q% W| S(   s'   Parse plain text for possible web linksi   i    t   hi   R    t   fi   t   ftpt   ws   www.i   (   t   lent   Falset   Truet   const
   CHAR_SPACEt   CHAR_NEWLINEt   append(   t
   plain_textt	   web_linkst   max_end_offsett   max_start_offsett   start_offsett   is_linkt
   end_offset(    (    s   modules/imports.pyt%   get_web_links_offsets_from_plain_text!   s0    

t
   LeoHandlerc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s#   The Handler of the Leo File Parsingc         C   s   t  j |   |  _ d S(   s   Machine bootN(   t   machinest
   XMLHandlert   xml_handler(   t   self(    (    s   modules/imports.pyt   __init__@   s    c         C   s;  i  |  _  t j j j |  } | j } x& | rO | j d k rC Pn  | j } q* W| j } x | r| j d k r} | j } nx | j d k r | j } x] | r | j d k r | j r | j j } n d } | |  j  | j	 d j
 <n  | j } q Wn  | j } q\ Wx2 | r6| j d k r*|  j |  n  | j } qWd S(	   s   Leo XML Parsingt   leo_filet   vnodest   tnodest   tt    t   txt   vN(   t   tnodes_dictt   xmlt   domt   minidomt   parseStringt
   firstChildt   nodeNamet   nextSiblingt   datat
   attributest   valuet   append_leo_node(   R   t
   leo_stringR'   t   dom_itert   child_dom_itert   vnode_dom_itert   tnode_dom_itert	   fill_text(    (    s   modules/imports.pyt   parse_leo_xmlD   s2    			 					 	 c         C   sI   |  j  j d  } |  j d j |  |  j  j |  } | j |  d S(   s'   Appends a new part to the XML rich textt	   rich_textiN(   R'   t   createElementt
   nodes_listt   appendChildt   createTextNode(   R   t	   text_dataR2   t	   text_iter(    (    s   modules/imports.pyt   rich_text_serialize]   s    c         C   s  |  j  j |  j j d   d } | j } x | r | j d k r | j r[ | j j } n  |  j  d j d |  |  j  d j d t j	  |  j  d j
 |  j  d  |  j |  j | j d j  n | j d	 k r |  j |  n  | j } q. W|  j  j   d
 S(   s   Append a Leo Nodet   nodet   ?t   vhit   namet	   prog_langiR!   R$   N(   R:   R   R'   R9   R*   R+   R-   t   setAttributeR   t   CUSTOM_COLORS_IDR;   R?   R%   R.   R/   R0   R,   t   pop(   R   R4   t	   node_nameR3   (    (    s   modules/imports.pyR0   g   s    			 ! c         C   s^   t  j j j   |  _ |  j j d  g |  _ |  j j |  j d  |  j |  |  j j   S(   s4   Returns a CherryTree string Containing the Leo Nodest
   cherrytreei    (	   R&   R'   R(   t   DocumentR9   R:   R;   R7   t   toxml(   R   R1   (    (    s   modules/imports.pyt   get_cherrytree_xmlw   s
    (   t   __name__t
   __module__t   __doc__R   R7   R?   R0   RL   (    (    (    s   modules/imports.pyR   =   s   			
	t   TuxCardsHandlerc           B   s_   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   s(   The Handler of the TuxCards File Parsingc         C   s&   t  j  j |   t j |   |  _ d S(   s   Machine bootN(   t
   HTMLParserR   R   R   R   (   R   (    (    s   modules/imports.pyR      s    c         C   s   |  j  j d  } x> t j D]3 } |  j | d k r | j | |  j |  q q W|  j d j |  |  j  j |  } | j |  d S(   s'   Appends a new part to the XML rich textR8   R"   iN(	   R'   R9   R   t   TAG_PROPERTIESt   curr_attributesRE   R:   R;   R<   (   R   R=   R2   t   tag_propertyR>   (    (    s   modules/imports.pyR?      s    c         C   s   t  j j j |  } | j } x& | rF | j d k r: Pn  | j } q! W| j } x& | rx | j d k rl Pn  | j } qS W|  j |  d S(   s   Start the Parsingt   InformationCollectiont   InformationElementN(   R&   R'   R(   R)   R*   R+   R,   t   node_add(   R   t   tuxcards_stringR'   R2   R3   (    (    s   modules/imports.pyt   start_parsing   s    		 		 c         C   s  | j  } |  j j |  j j d   xF| rm| j d k r | j  rU | j  j } n d } |  j d j d |  |  j d j d t j	  |  j d j
 |  j d  n | j d k rB| j  r | j  j } n d } d	 |  _ g  |  _ d	 |  _ |  j | j d
 d   xS |  j D]& } |  j j | |  j d |  j  qWn | j d k ra|  j |  n  | j } q( W|  j j   d S(   s
   Add a NodeR@   t   DescriptionR"   iRC   RD   it   Informationi    s   utf-8t   ignoreRV   N(   R*   R:   R   R'   R9   R+   R-   RE   R   RF   R;   t
   curr_statet   pixbuf_vectort   chars_countert   feedt   decodeR   t   pixbuf_element_to_xmlRW   R,   RG   (   R   R2   R3   RH   t   node_stringt   pixbuf_element(    (    s   modules/imports.pyRW      s0    			 	 			'c         C   s  |  j  d k r* | d k rd |  _  qn| d k r=| d d d k r=d | d d k rn d |  j d <qd	 | d d k r d
 | d d k r d
 |  j d <qd | d d k r d | d d k r d |  j d <qd | d d k rt j d | d d  } | d k r:| j d  j   |  j d <q:qnn| d k rt |  d k r| d d } t |  d k rt |  |  j d <qn| d k rt |  d k r| d d } t	 j
 j |  rt j j |  } |  j j |  j | d g  |  j d 7_ qd | GHn | d k rI|  j d  |  j d 7_ nb | d k r|  j t j  |  j t t j  7_ n+ | d k r|  j d  |  j d 7_ n  d S(   s"   Encountered the beginning of a tagi    t   bodyi   t   spant   styles   font-weightt   heavyt   weights
   font-stylet   italics   text-decorationt	   underlinet   singlet   colors   (?<=^).+:(.+);(?=$)t
   foregroundt   ai   t   linkt   imgt   lefts   %s not foundt   brs   
t   hrt   lis   
• i   N(   R]   RS   t   ret   matcht   Nonet   groupt   stripR	   R   t   ost   patht   isfilet   gtkt   gdkt   pixbuf_new_from_fileR^   R   R_   R?   R   t   HORIZONTAL_RULE(   R   t   tagt   attrsRw   R   t   img_patht   pixbuf(    (    s   modules/imports.pyt   handle_starttag   sD       ( (  %c         C   s   |  j  d k r d S| d k r> |  j d  |  j d 7_ n_ | d k r d |  j d <d |  j d	 <d |  j d
 <d |  j d <n | d k r d |  j d <n  d S(   s   Encountered the end of a tagi    Nt   ps   
i   Rf   R"   Ri   Rg   Rk   Rn   Ro   Rp   (   R]   R?   R_   RS   (   R   R   (    (    s   modules/imports.pyt   handle_endtag   s      c         C   sW   |  j  d k s | d k r d S| j d d  } |  j |  |  j t |  7_ d S(   s
   Found Datai    s   
s   

NR"   (   s   
s   

(   R]   t   replaceR?   R_   R	   (   R   R-   (    (    s   modules/imports.pyt   handle_data   s
     c         C   sX   |  j  d k r d S| t j k rT t t j |  } |  j |  |  j d 7_ n  d S(   s"   Found Entity Reference like &name;i    Ni   (   R]   t   htmlentitydefst   name2codepointt   unichrR?   R_   (   R   RC   t   unicode_char(    (    s   modules/imports.pyt   handle_entityref   s     c         C   s   t  j j j   |  _ |  j j d  g |  _ |  j j |  j d  i  |  _ x t j	 D] } d |  j | <qW Wd |  _
 |  j |  |  j j   S(   s9   Returns a CherryTree string Containing the TuxCards NodesRI   i    R"   (   R&   R'   R(   RJ   R9   R:   R;   RS   R   RR   t   latest_spanRY   RK   (   R   RX   RT   (    (    s   modules/imports.pyRL      s    	 	(   RM   RN   RO   R   R?   RY   RW   R   R   R   R   RL   (    (    (    s   modules/imports.pyRP      s   		
			#			t   KeepnoteHandlerc           B   s_   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   s*   The Handler of the KeepNote Folder Parsingc         C   s/   t  j  j |   | |  _ t j |   |  _ d S(   s   Machine bootN(   RQ   R   t
   folderpathR   R   R   (   R   R   (    (    s   modules/imports.pyR   	  s    	c         C   s   |  j  j d  } x> t j D]3 } |  j | d k r | j | |  j |  q q W|  j d j |  |  j  j |  } | j |  d S(   s'   Appends a new part to the XML rich textR8   R"   iN(	   R'   R9   R   RR   RS   RE   R:   R;   R<   (   R   R=   R2   RT   R>   (    (    s   modules/imports.pyR?     s    c         C   sy   xr t  t j |  j   D]X } t j j t j j |  j |   r | d k r |  j t j j |  j |   q q Wd S(   s   Start the Parsingt	   __TRASH__t   __NOTEBOOK__N(   R   R   (   t   reversedR{   t   listdirR   R|   t   isdirt   joinRW   (   R   t   element(    (    s   modules/imports.pyRY     s    $c         C   s  |  j  j |  j j d   |  j  d j d t j j |   |  j  d j d t j	  |  j  d j
 |  j  d  t j j | d  } t j j |  r y) t | d  } | j   } | j   Wq d | GHd	 SXn d
 } d |  _ g  |  _ | |  _ d |  _ |  j | j d d   x1 |  j D]& } |  j j | |  j  d |  j  q(Wx] t t j |   D]F } t j j t j j | |   rh|  j t j j | |   qhqhW|  j  j   d	 S(   s
   Add a NodeR@   iRC   RD   is	   page.htmlt   rs   Error opening the file %sNR"   i    s   utf-8R\   (   R:   R   R'   R9   RE   R{   R|   t   basenameR   RF   R;   R   R}   t   opent   readt   closeR]   R^   t   curr_folderR_   R`   Ra   R   Rb   R   R   R   RW   RG   (   R   t   node_foldert   filepatht   file_descriptorRc   Rd   R   (    (    s   modules/imports.pyRW      s2    #					$!#c         C   s  |  j  d k r* | d k rd |  _  qn| d k rF d |  j d <n| d k rb d |  j d	 <n| d
 k r~ d |  j d <nh| d k r d |  j d <nL| d k r`| d d d	 k r`t j d | d d  } | d# k r| j d  d k r| j d  j   |  j d <d |  _ q]| j d  d k r]| j d  j   |  j d <d |  _ q]qn| d k rt |  d k r| d d } t |  d k rt	 |  |  j d <qn/| d k rYt |  d k rY| d d } t
 j j |  j |  } t
 j j |  rMt j j |  } |  j j |  j | d g  |  j d 7_ qd | GHn | d k r|  j d  |  j d 7_ nb | d k r|  j t j  |  j t t j  7_ n+ | d  k r|  j d!  |  j d" 7_ n  d# S($   s"   Encountered the beginning of a tagi    Re   i   t   bRh   Ri   t   iRj   Rg   t   uRl   Rk   t   striket   truet   strikethroughRf   s   (?<=^)(.+):(.+)(?=$)Rm   i   Rn   s   background-colort
   backgroundRo   i   Rp   Rq   Rr   s   %s not foundRs   s   
Rt   Ru   s   
• i   N(   R]   RS   Rv   Rw   Rx   Ry   Rz   R   R	   R   R{   R|   R   R   R}   R~   R   R   R^   R   R_   R?   R   R   (   R   R   R   Rw   R   t   img_nameR   R   (    (    s   modules/imports.pyR   ?  sR          c         C   s   |  j  d k r d S| d k r/ d |  j d <n | d k rK d |  j d <n | d k rg d |  j d	 <n | d
 k r d |  j d <ni | d k r |  j d k r d |  j d <q |  j d k r d |  j d <q n | d k r d |  j d <n  d S(   s   Encountered the end of a tagi    NR   R"   Ri   R   Rg   R   Rk   R   R   Rf   Rn   R   Ro   Rp   (   R]   RS   R   (   R   R   (    (    s   modules/imports.pyR   i  s"            c         C   sW   |  j  d k s | d k r d S| j d d  } |  j |  |  j t |  7_ d S(   s
   Found Datai    s   
s   

NR"   (   s   
s   

(   R]   R   R?   R_   R	   (   R   R-   (    (    s   modules/imports.pyR   u  s
     c         C   sX   |  j  d k r d S| t j k rT t t j |  } |  j |  |  j d 7_ n  d S(   s"   Found Entity Reference like &name;i    Ni   (   R]   R   R   R   R?   R_   (   R   RC   R   (    (    s   modules/imports.pyR   |  s     c         C   s   t  j j j   |  _ |  j j d  g |  _ |  j j |  j d  i  |  _ x t j	 D] } d |  j | <qW Wd |  _
 |  j   |  j j   S(   s9   Returns a CherryTree string Containing the KeepNote NodesRI   i    R"   (   R&   R'   R(   RJ   R9   R:   R;   RS   R   RR   R   RY   RK   (   R   RT   (    (    s   modules/imports.pyRL     s    	 	
(   RM   RN   RO   R   R?   RY   RW   R   R   R   R   RL   (    (    (    s   modules/imports.pyR     s   		
			*			t   TomboyHandlerc           B   s_   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   s(   The Handler of the Tomboy Folder Parsingc         C   s   | |  _  t j |   |  _ d S(   s   Machine bootN(   R   R   R   R   (   R   R   (    (    s   modules/imports.pyR     s    	c         C   s   |  j  j d  } x> t j D]3 } |  j | d k r | j | |  j |  q q W|  j j |  |  j  j |  } | j |  d S(   s'   Appends a new part to the XML rich textR8   R"   N(	   R'   R9   R   RR   RS   RE   t   dest_dom_newR;   R<   (   R   R=   R2   RT   R>   (    (    s   modules/imports.pyR?     s    c         C   s   x t  t j |  j   D]q } t j j t j j |  j |   r t t j j |  j |  d  } | j   } | j	   |  j
 |  q q Wd S(   s   Start the ParsingR   N(   R   R{   R   R   R|   R}   R   R   R   R   t	   doc_parse(   R   R   R   t
   xml_string(    (    s   modules/imports.pyRY     s    $!
c   
      C   s  |  j  } t j j j |  } | j } x& | rO | j d k rC Pn  | j } q* W| j } d |  _ x| r~| j d k r | j r | j j	 n d |  _ t
 |  j  d k rr|  j d d k rrd Sn | j d k r | } n | j d	 k rr| j } xx | rn| j d
 k rb| j rb| j j	 } t
 |  d k r_| d  d k r_|  j | d  } q_qbn  | j } q Wn  | j } qe W| j }	 x6 |	 r|	 j d k r|  j |	 |  Pn  |	 j }	 qWd S(   s   Parse an xml filet   notes   ???t   titlei   is    Notebook TemplateNt   textt   tagsR   i   s   system:notebook:s   note-content(   t   dest_orphans_dom_nodeR&   R'   R(   R)   R*   R+   R,   t
   node_titleR-   R	   t   notebook_exist_or_createRW   (
   R   R   t   dest_dom_fatherR'   R2   R3   t   text_dom_itert   tag_dom_itert   tag_textt   nephew_dom_iter(    (    s   modules/imports.pyR     s@    			 			(				"		c         C   s   |  j  j d  |  _ |  j j d |  j  |  j j d t j  | j |  j  x t j D] } d |  j	 | <q[ Wd |  _
 |  j | j  d S(   s
   Add a NodeR@   RC   RD   R"   i    N(   R'   R9   R   RE   R   R   RF   R;   RR   RS   R_   t   node_add_iterR*   (   R   t   content_iterR   RT   (    (    s   modules/imports.pyRW     s     	c         C   sK  xD| rF| j  d k r | j } |  j d d k rM |  j d c | j 7<na |  j rc d | } nK |  j r |  j j i | d 6|  j d 6|  j d 6|  j t	 |  d 6 n  |  j
 |  |  j t	 |  7_ ng| j  d	 k rd
 |  j d <|  j | j  d |  j d <n+| j  d k rKd |  j d <|  j | j  d |  j d <n| j  d k rd |  j d <|  j | j  d |  j d <n| j  d k rt j |  j d <|  j | j  d |  j d <nt| j  d k rd |  j d <|  j | j  d |  j d <n8| j  d k r>d |  j d <|  j | j  d |  j d <n | j  d k rzd |  j d <|  j | j  d |  j d <n | j  d k rd |  j d <|  j | j  d |  j d <n | j  d k rt |  _ |  j | j  t |  _ nP | j  d k rt |  _ |  j | j  t |  _ n | j r:|  j | j  n  | j } q Wd S(   s   Recursively parse nodess   #textRp   s   webs s   • t	   name_destt   node_sourcet
   char_startt   char_endt   boldRh   Ri   R"   Rj   Rg   R   R   t	   highlightR   s
   size:smallt   smallt   scales
   size:larget   h1s	   size:huget   h2s   link:urls	   list-items   link:internalN(   R+   R-   RS   t   is_list_itemt   is_link_to_nodet   links_to_node_listR   R   R_   R	   R?   R   R*   R   t   COLOR_YELLOWR   R
   R,   (   R   R2   R=   (    (    s   modules/imports.pyR     sr    				

			c         C   s~   | |  j  k rs |  j j d  |  j  | <|  j  | j d |  |  j  | j d t j  |  j j |  j  |  n  |  j  | S(   s3   Check if there's already a notebook with this titleR@   RC   RD   (   t   dest_notebooks_dom_nodesR'   R9   RE   R   RF   t   dest_top_domR;   (   R   t   notebook_title(    (    s   modules/imports.pyR     s    c         C   s   t  j j j   |  _ |  j j d  |  _ |  j j |  j  i  |  _ t |  _	 t |  _
 g  |  _ |  j j d  |  _ |  j j d d  |  j j d t j  |  j j |  j  i  |  _ |  j   |  j j   S(   s7   Returns a CherryTree string Containing the Tomboy NodesRI   R@   RC   t   ORPHANSRD   (   R&   R'   R(   RJ   R9   R   R;   RS   R
   R   R   R   R   RE   R   RF   R   RY   RK   (   R   (    (    s   modules/imports.pyRL     s    					
c         C   s   x |  j  D] } | j | d  } | j | d  } | sB q
 n  | sN q
 n  | j | d } | j   | d k  r{ q
 n  d t j t | j | d  } | j | j d |  | j	 | d  | j	 | d   q
 Wd	 S(
   s=   After the node import, set the links to nodes on the new treeR   R   i   R   R@   i   Rp   R   N(
   R   t   get_tree_iter_from_node_namet	   treestoret   get_char_countR   R   t   strt   apply_tag_by_namet   apply_tag_exist_or_createt   get_iter_at_offset(   R   t   dadt   link_to_nodet	   node_destR   t   source_buffert   property_value(    (    s   modules/imports.pyt   set_links_to_nodes1  s    "(   RM   RN   RO   R   R?   RY   R   RW   R   R   RL   R   (    (    (    s   modules/imports.pyR     s   		
			"	
	=			t   BasketHandlerc           B   sz   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z RS(   s(   The Handler of the Basket Folder Parsingc         C   s/   t  j  j |   | |  _ t j |   |  _ d S(   s   Machine bootN(   RQ   R   R   R   R   R   (   R   R   (    (    s   modules/imports.pyR   H  s    	c         C   s.   t  j j |  j d  |  _ t  j j |  j  S(   s/   Check the Selected Folder to be a Basket Folders   baskets.xml(   R{   R|   R   R   t   baskets_xml_filepathR}   (   R   (    (    s   modules/imports.pyt   check_basket_structureN  s    c         C   s   |  j  j d  } x> t j D]3 } |  j | d k r | j | |  j |  q q W|  j d j |  |  j  j |  } | j |  d S(   s'   Appends a new part to the XML rich textR8   R"   iN(	   R'   R9   R   RR   RS   RE   R:   R;   R<   (   R   R=   R2   RT   R>   (    (    s   modules/imports.pyR?   S  s    c         C   s   t  |  j d  } | j   } | j   t j j j |  } | j } x | j d k rd | j
 } qI W| j } x2 | r | j d k r |  j |  n  | j
 } qq Wd S(   s   Start the ParsingR   t   basketN(   R   R   R   R   R&   R'   R(   R)   R*   Rx   R,   R+   RW   (   R   R   t   baskets_xml_stringR'   R2   R3   (    (    s   modules/imports.pyRY   ]  s    
			 c         C   sy  g  |  _  d |  _ | j d j d d !} d } | j } xn | r | j d k r | j } x@ | r | j d k r | j r | j j } q n  | j } q\ Wn  | j } q; Wt j	 j
 |  j |  |  _ t j	 j
 |  j d  } t | d  } | j   } | j   t j j j |  }	 |	 j }
 |
 j } x | sF|
 j }
 |
 j } q+Wx | r| j d k r|  j j |  j j d	   |  j d j d |  |  j d j d
 t j  |  j d j |  j d  n | j d k r|  j |  n  | j } qJWx1 |  j  D]& } |  j j | |  j d |  j  q W| j } x2 | rg| j d k r[|  j |  n  | j } q6W|  j j   d S(   s
   Add a Nodei    t
   folderNameiRA   t
   propertiesRC   s   .basketR   R@   RD   it   notesR   N(    R^   R_   R.   R/   R*   R+   R-   R,   R{   R|   R   R   t   subfolder_pathR   R   R   R&   R'   R(   R)   R:   R   R9   RE   R   RF   R;   t   notes_parseR   Rb   RW   RG   (   R   t   top_dom_itert   folder_nameRH   R3   R   t   node_xml_filepathR   t   node_xml_stringR'   R2   Rd   (    (    s   modules/imports.pyRW   k  sT    							 
					$		 c         C   sa   | j  } xQ | r\ | j d k r1 |  j |  n | j d k rP |  j |  n  | j } q Wd S(   s   Parse a 'notes'Ry   R   N(   R*   R+   R   t
   note_parseR,   (   R   t   notes_dom_iterR   (    (    s   modules/imports.pyR     s    		c   	      C   s  | j  d j d k r d |  _ | j } x| r | j d k r t j j |  j | j j	  } t j j
 |  r t | d  } | j   } | j   n d } |  j | j d d   |  j d	  |  j d
 7_ Pn  | j } q+ Wn| j  d j d k r| j } x| r| j d k rt j j |  j | j j	  } t j j
 |  rt j j |  } |  j j |  j | d g  |  j d
 7_ |  j d	  |  j d
 7_ n  Pn  | j } q	Wn| j  d j d k r| j } x | r| j d k r| j j	 } | d  d k r| d  d k r5d | |  j d <n1 | d  d k rfd t j | d  |  j d <n  | j  d j } |  j |  d |  j d <|  j d	  |  j t |  d
 7_ n  Pn  | j } qWn  d S(   s   Parse a 'note't   typet   htmli    t   contentR   R"   s   utf-8R\   s   
i   t   imageRr   Rp   i   R    t   files   webs %ss   file %si   R   N(   s   https   file(   R.   R/   R]   R*   R+   R{   R|   R   R   R-   R}   R   R   R   R`   Ra   R?   R_   R,   R~   R   R   R^   R   RS   R   R   R	   (	   R   t   note_dom_itert   content_dom_itert   content_pathR   Rc   R   R   t   content_title(    (    s   modules/imports.pyR     s\    							!c         C   s%  |  j  d k r* | d k r!d |  _  q!n| d k r=| d d d k r=d | d d k rn d |  j d <q!d	 | d d k r d
 | d d k r d
 |  j d <q!d | d d k r d | d d k r d |  j d <q!d | d d k r!t j d | d d  } | d k r:| j d  j   |  j d <q:q!n | d k rt |  d k r| d d } t |  d k r!t |  |  j d <q!n | d k r|  j	 d  |  j
 d 7_
 nb | d k r|  j	 t j  |  j
 t t j  7_
 n+ | d k r!|  j	 d  |  j
 d 7_
 n  d S(   s"   Encountered the beginning of a tagi    Re   i   Rf   Rg   s   font-weightRh   Ri   s
   font-styleRj   s   text-decorationRk   Rl   Rm   s   (?<=^).+:(.+);(?=$)Rn   Ro   i   Rp   Rs   s   
Rt   Ru   s   
• i   N(   R]   RS   Rv   Rw   Rx   Ry   Rz   R	   R   R?   R_   R   R   (   R   R   R   Rw   R   (    (    s   modules/imports.pyR     s6       ( (  %c         C   s   |  j  d k r d S| d k r> |  j d  |  j d 7_ n | d k r d |  j d <d |  j d	 <d |  j d
 <d |  j d <nG | d k r d |  j d <n+ | d k r |  j d  |  j d 7_ n  d S(   s   Encountered the end of a tagi    NR   s   
i   Rf   R"   Ri   Rg   Rk   Rn   Ro   Rp   Re   (   R]   R?   R_   RS   (   R   R   (    (    s   modules/imports.pyR     s      c         C   sW   |  j  d k s | d k r d S| j d d  } |  j |  |  j t |  7_ d S(   s
   Found Datai    s   
s   

NR"   (   s   
s   

(   R]   R   R?   R_   R	   (   R   R-   (    (    s   modules/imports.pyR     s
     c         C   sX   |  j  d k r d S| t j k rT t t j |  } |  j |  |  j d 7_ n  d S(   s"   Found Entity Reference like &name;i    Ni   (   R]   R   R   R   R?   R_   (   R   RC   R   (    (    s   modules/imports.pyR     s     c         C   s   t  j j j   |  _ |  j j d  g |  _ |  j j |  j d  i  |  _ x t j	 D] } d |  j | <qW Wd |  _
 |  j   |  j j   S(   s7   Returns a CherryTree string Containing the Basket NodesRI   i    R"   (   R&   R'   R(   RJ   R9   R:   R;   RS   R   RR   R   RY   RK   (   R   RT   (    (    s   modules/imports.pyRL     s    	 	
(   RM   RN   RO   R   R   R?   RY   RW   R   R   R   R   R   R   RL   (    (    (    s   modules/imports.pyR   E  s   			
		,	
	3				t   KnowitHandlerc           B   sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s&   The Handler of the Knowit File Parsingc         C   s&   t  j  j |   t j |   |  _ d S(   s   Machine bootN(   RQ   R   R   R   R   (   R   (    (    s   modules/imports.pyR     s    c         C   s   |  j  j d  } x> t j D]3 } |  j | d k r | j | |  j |  q q W|  j d j |  |  j  j |  } | j |  d S(   s'   Appends a new part to the XML rich textR8   R"   iN(	   R'   R9   R   RR   RS   RE   R:   R;   R<   (   R   R=   R2   RT   R>   (    (    s   modules/imports.pyR?   $  s    c      	   C   s  d |  _  d |  _ d |  _ d |  _ d |  _ x| D]} | j d d  } |  j  d k r-t |  d k r} | d  d k s t |  d k r| d  d	 k r| d
 d k r | d d !} n | d d !} t j d |  } | s d | GHn  t	 | j
 d
   |  _ | j
 d  |  _ |  j |  j k rjx+ t |  j |  j  D] } |  j j   qCW|  j j   n  |  j |  _ d |  _ d
 |  _  |  j j |  j j d   |  j d j d |  j  |  j d j d t j  |  j d j |  j d  q|  j | j t j d  j t j d  t j 7_ q4 |  j  d
 k r4 t |  d k r| d  d k rd |  _  d |  _ |  j |  j j d d   q|  j d k r| t j k rd |  _  d |  _ q|  j | 7_ q4 q4 Wd S(   s   Parse the string line by linei    R"   is   utf-8R\   i
   s
   \NewEntry i   s   \CurrentEntry i   t   Ns   (\d+) (.*)$s   %si   R@   RC   RD   is   </body></html>N(   t   curr_xml_statet   curr_node_namet   curr_node_contentt   curr_node_levelt   former_node_levelRa   R	   Rv   Rw   t   intRy   t   rangeR:   RG   R   R'   R9   RE   R   RF   R;   R   t   CHAR_CRR   R   t   curr_html_stateR`   (   R   R   t	   text_linet   text_to_parseRw   t   count(    (    s   modules/imports.pyt   parse_string_lines.  sN    					""  		7"			c         C   sy  |  j  d k r* | d k rud |  _  qunK| d k r=| d d d k r=d | d d k rn d |  j d <qud	 | d d k r d
 | d d k r d
 |  j d <qud | d d k r d | d d k r d |  j d <qud | d d k rut j d | d d  } | d k r:| j d  j   |  j d <q:qun8 | d k rY|  j d  n | d k ru|  j d  n  d S(   s"   Encountered the beginning of a tagi    Re   i   Rf   Rg   s   font-weightRh   Ri   s
   font-styleRj   s   text-decorationRk   Rl   Rm   s   (?<=^).+:(.+)(?=$)Rn   Rs   s   
Ru   s   
• N(   R   RS   Rv   Rw   Rx   Ry   Rz   R?   (   R   R   R   Rw   (    (    s   modules/imports.pyR   [  s$       ( (  %c         C   sv   |  j  d k r d S| d k r/ |  j d  nC | d k rr d |  j d <d |  j d <d |  j d	 <d |  j d
 <n  d S(   s   Encountered the end of a tagi    NR   s   
Rf   R"   Ri   Rg   Rk   Rn   (   R   R?   RS   (   R   R   (    (    s   modules/imports.pyR   m  s     c         C   sB   |  j  d k s | d k r d S| j d d  } |  j |  d S(   s
   Found Datai    s   
s   

NR"   (   s   
s   

(   R   R   R?   (   R   R-   (    (    s   modules/imports.pyR   y  s     c         C   sI   |  j  d k r d S| t j k rE t t j |  } |  j |  n  d S(   s"   Found Entity Reference like &name;i    N(   R   R   R   R   R?   (   R   RC   R   (    (    s   modules/imports.pyR     s
     c         C   s   t  j j j   |  _ |  j j d  g |  _ |  j j |  j d  i  |  _ x t j	 D] } d |  j | <qW Wd |  _
 |  j |  |  j j   S(   s7   Returns a CherryTree string Containing the Knowit NodesRI   i    R"   (   R&   R'   R(   RJ   R9   R:   R;   RS   R   RR   R   R  RK   (   R   R   RT   (    (    s   modules/imports.pyRL     s    	 	(   RM   RN   RO   R   R?   R  R   R   R   R   RL   (    (    (    s   modules/imports.pyR     s   		
	-				t   TreepadHandlerc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s'   The Handler of the Treepad File Parsingc         C   s   t  j |   |  _ d S(   s   Machine bootN(   R   R   R   (   R   (    (    s   modules/imports.pyR     s    c         C   sI   |  j  j d  } |  j d j |  |  j  j |  } | j |  d S(   s'   Appends a new part to the XML rich textR8   iN(   R'   R9   R:   R;   R<   (   R   R=   R2   R>   (    (    s   modules/imports.pyR?     s    c         C   s  d |  _  d |  _ d |  _ d |  _ d |  _ xi| D]a} | j d d  } |  j  d k r t |  d k r| d  d k rd	 |  _  qq4 |  j  d	 k r | j t j	 d  j t j
 d  |  _ d
 |  _  q4 |  j  d
 k rt j d |  rt |  |  _ |  j |  j k rNx+ t |  j |  j  D] } |  j j   q'W|  j j   n  |  j |  _ d |  _ d |  _  |  j j |  j j d   |  j d j d |  j  |  j d j d t j  |  j d j |  j d  q|  j | j t j	 d  j t j
 d  t j 7_ q4 |  j  d k r4 t |  d k r^| d  d k r^d |  _  |  j |  j  q|  j | j t j	 d  j t j
 d  t j
 7_ q4 q4 Wd S(   s   Parse the string line by linei    R"   is   utf-8R\   i   i   s   <node>i   i   s   \d+i   R@   RC   RD   ii	   i
   s
   <end node>N(   R]   R   R   R   R   Ra   R	   R   R   R   R   Rv   Rw   R   R   R:   RG   R   R'   R9   RE   RF   R;   R   R?   (   R   R   R   R  (    (    s   modules/imports.pyR    sB    					" '		7"	c         C   s^   t  j j j   |  _ |  j j d  g |  _ |  j j |  j d  |  j |  |  j j   S(   s8   Returns a CherryTree string Containing the Treepad NodesRI   i    (	   R&   R'   R(   RJ   R9   R:   R;   R  RK   (   R   R   (    (    s   modules/imports.pyRL     s
    (   RM   RN   RO   R   R?   R  RL   (    (    (    s   modules/imports.pyR    s
   		
	*t   NotecaseHandlerc           B   sM   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   s)   The Handler of the Notecase Files Parsingc         C   s&   t  j  j |   t j |   |  _ d S(   s   Machine bootN(   RQ   R   R   R   R   (   R   (    (    s   modules/imports.pyR     s    c         C   s   |  j  j d  } x> t j D]3 } |  j | d k r | j | |  j |  q q W|  j d j |  |  j  j |  } | j |  d S(   s'   Appends a new part to the XML rich textR8   R"   iN(	   R'   R9   R   RR   RS   RE   R:   R;   R<   (   R   R=   R2   RT   R>   (    (    s   modules/imports.pyR?     s    c         C   s  |  j  d k r* | d k rd |  _  qn|  j  d k r| d k r x1 |  j D]& } |  j j | |  j d |  j  qO Wg  |  _ d |  _ d |  _  q| d k rx1 |  j D]& } |  j j | |  j d |  j  q Wg  |  _ d |  _ |  j j   d |  _  q| d k rd |  j d	 <q| d
 k r:d |  j d <q| d k rVd |  j d <q| d k rrd |  j d <q| d k r8| d d d k r8t	 j
 d | d d  } | d, k r| j d  d k r| j d  j   |  j d <d |  _ q5| j d  d k r5| j d  j   |  j d <d |  _ q5qq| d k rt |  d k r| d d } t |  d k rt |  |  j d <qq| d k r|  j d  |  j d 7_ q| d k r|  j d  |  j d  7_ q| d! k rt |  d k rx| D]} | d d" k r
| d d#  d$ k r| d d# } t j j d%  } y | j t j |   WnI y | j t j | d&   Wq| j t j | d'   qXn X| j   | j   }	 |  j j |  j |	 d( g  |  j d 7_ q| d d)  d* k r| d d) }
 t j j d+  } y | j t j |
   WnI y | j t j |
 d&   Wq| j t j |
 d'   qXn X| j   | j   }	 |  j j |  j |	 d( g  |  j d 7_ qq
q
Wqn  d, S(-   s"   Encountered the beginning of a tagi    t   dti   i   t   dliR   Rh   Ri   R   Rj   Rg   R   Rl   Rk   t   sR   R   Rf   s   (?<=^)(.+):(.+)(?=$)Rm   Rn   s   background-colorR   Ro   i   Rp   Rs   s   
Ru   s   
• i   Rq   t   srci   s   data:image/jpeg;base64,s
   image/jpegt   =s   ==Rr   i   s   data:image/png;base64,s	   image/pngN(   R]   R^   R   Rb   R:   R'   R_   RG   RS   Rv   Rw   Rx   Ry   Rz   R   R	   R   R?   R~   R   t    pixbuf_loader_new_with_mime_typet   writeR   t	   b64decodeR   t
   get_pixbufR   (   R   R   R   Rd   Rw   R   t	   attributet	   jpeg_datat   pixbuf_loaderR   t   png_data(    (    s   modules/imports.pyR     s    $		$		        "
   "
c         C   s*  |  j  d k r | d k r&|  j j |  j j d   |  j d j d |  j  |  j d j d t j  |  j d j	 |  j d  d |  _ |  j
 d	 k r x1 |  j D]& } |  j j | |  j d |  j  q Wg  |  _ d	 |  _
 n  d
 |  _  q&n0|  j  d
 k r| d k rpx1 |  j D]& } |  j j | |  j d |  j  qWg  |  _ d	 |  _
 |  j j   d	 |  _  q&| d k rx1 |  j D]& } |  j j | |  j d |  j  qWg  |  _ d	 |  _
 |  j j   |  j j   d	 |  _  q&| d k rd |  j d <q&| d k r d |  j d <q&| d k r<d |  j d <q&| d k rXd |  j d <q&| d k r|  j d k rd |  j d <q|  j d k rd |  j d <qq&| d k r&d |  j d <q&nb | d k r&x1 |  j D]& } |  j j | |  j d |  j  qWg  |  _ d	 |  _
 |  j j   n  d S(   s   Encountered the end of a tagi   R  R@   iRC   RD   iR"   i    i   t   ddR  R   Ri   R   Rg   R   Rk   R  R   Rf   Rn   R   Ro   Rp   N(   R]   R:   R   R'   R9   RE   t
   curr_titleR   RF   R;   R_   R^   R   Rb   RG   RS   R   (   R   R   Rd   (    (    s   modules/imports.pyR   4  sd    	$	$		$		       $		c         C   s   |  j  d k s | d k r d S|  j  d k r@ |  j | 7_ nF |  j  d k r | j d d  } |  j |  |  j t |  7_ n  d S(	   s
   Found Datai    s   
s   

Ni   i   R"   (   s   
s   

(   R]   R  R   R?   R_   R	   (   R   R-   t
   clean_data(    (    s   modules/imports.pyR   k  s     c         C   s|   | t  j k r% t t  j |  } n d S|  j d k rJ |  j | 7_ n. |  j d k rx |  j |  |  j d 7_ n  d S(   s"   Found Entity Reference like &name;Ni   i   (   R   R   R   R]   R  R?   R_   (   R   RC   R   (    (    s   modules/imports.pyR   w  s    c         C   s   t  j j j   |  _ |  j j d  g |  _ |  j j |  j d  d |  _ d |  _ i  |  _	 x t
 j D] } d |  j	 | <qi Wd |  _ g  |  _ d |  _ |  j | j d d   |  j j   S(   sD   Parses the Given Notecase HTML String feeding the CherryTree XML domRI   i    R"   s   utf-8R\   (   R&   R'   R(   RJ   R9   R:   R;   R]   R  RS   R   RR   R   R^   R_   R`   Ra   RK   (   R   t   input_stringRT   (    (    s   modules/imports.pyRL     s    			 			(
   RM   RN   RO   R   R?   R   R   R   R   RL   (    (    (    s   modules/imports.pyR    s   		
	L	7		t   HTMLFromClipboardHandlerc           B   sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s/   The Handler of the HTML received from clipboardc      	   C   sA   | |  _  d d d d d d d d d	 g	 |  _ t j j |   d
 S(   s   Machine bootR   R   R   R   R  R   R   Rf   t   fontN(   R   t   monitored_tagsRQ   R   (   R   R   (    (    s   modules/imports.pyR     s    	$c         C   s   |  j  j d  } x> t j D]3 } |  j | d k r | j | |  j |  q q W|  j j |  |  j  j |  } | j |  d S(   s'   Appends a new part to the XML rich textR8   R"   N(	   R'   R9   R   RR   RS   RE   t   curr_dom_slotR;   R<   (   R   R=   R2   RT   R>   (    (    s   modules/imports.pyR?     s    c         C   s   | d d k r | Sd | k r t  j d |  } | r d t | j d   t | j d   t | j d   f } | Sn  d	 S(
   s)   Get RGB GTK attribute from HTML attributei    t   #t   rgbs   .*rgb\((\d+), (\d+), (\d+)\).*s   #%.2x%.2x%.2xi   i   i   N(   Rv   Rw   R   Ry   Rx   (   R   t   html_attributeRw   (    (    s   modules/imports.pyt   get_rgb_gtk_attribute  s    @c         C   s  | |  j  k r! |  j d 7_ n  |  j d k rK | d k rd |  _ qn|  j d k rC| d k r d |  _ g  |  _ g  |  _ t |  _ q| d k r d |  j d <q| d	 k r d
 |  j d <q| d k r d |  j d <q| d k r d |  j d <q| d k rd |  _ q| d k rx| D]} | d d k r(| d j d  } x| D]} t	 j
 d |  } | d< k rX| j d  d k r|  j | j d  j    } | r| |  j d <|  j j d  qq| j d  d= k r4|  j | j d  j    } | r| |  j d <|  j j d  qq| j d  d k r| j d  j   d> k rd |  j d <|  j j d  qq| j d  d k r| j d  j   d? k rd |  j d <|  j j d  qqqXqXWq(q(Wq| d k rVxF| D]Q } | d d k r|  j | d j    } | rO| |  j d <d |  _ qOqqWq| d@ k r|  j t j  | d k rd |  j d! <n d  |  j d! <x| D]6 } | d d" k r| d j   j   |  j d# <qqWq| d$ k r6t |  d k r6| d d } t |  d% k r@t |  |  j d& <q@q| d' k rU|  j t j  q| d( k rsd) d g |  _ q| d* k rd d g |  _ q| d+ k r|  j d d k r|  j d,  q@|  j d- |  j d  |  j d c d 7<q| d. k r(t |  d k r(| d d } y |  j j j |  j j t d/  d0 |  x t j   rct j    qJWt! j" | d1 d2 }	 |	 j#   }
 t j$ j%   } | j& |
  | j'   | j(   } |  j j) j* d | d3 g |  j+ |  j,  |  j j j- |  j j  Wq@d4 G| GH|  j j j- |  j j  q@Xq| d5 k rd6 |  _. qn |  j d k r| d7 k rq|  j j g   q| dA k rd: |  _/ d |  _0 x5 | D]- } | d d; k rt1 | d  |  _0 PqqW| d9 k rt2 |  _ qqn  d< S(B   s"   Encountered the beginning of a tagi   i    Re   t   tablei   R   Rh   Ri   R   Rj   Rg   R   Rl   Rk   R  R   R   Rf   t   ;s   (?<=^)(.+):(.+)(?=$)Rm   Rn   R   s   background-colors   text-decorations
   underline;s   font-weightt   boldert   700R  R   R   R   t   alignt   justificationRo   i   Rp   Rs   t   olt   ot   ulRu   s   • s   %s. Rq   t   Downloadings    %s ...t   timeouti   Rr   s   failed download oft   preR   t   trt   tdt   thR"   t   rowspanN(   s
   backgrounds   background-color(   s	   underlines
   underline;(   s   bolderR"  (   s   h1s   h2(   R,  s   th(3   R  t   in_a_tagR]   t
   curr_tablet   curr_rows_spanR
   t   curr_table_headerRS   t   splitRv   Rw   Rx   Ry   R  Rz   R   R   t   latest_fontR?   R   R   t   lowerR	   R   t   curr_list_typeR   t	   statusbart   pusht   statusbar_context_idt   _R~   t   events_pendingt   main_iterationt   urllib2t   urlopenR   R   t   PixbufLoaderR  R   R  R   Rb   R  R'   RG   t   pre_tagt	   curr_cellt   curr_rowspanR   R   (   R   R   R   t   attrR.   R  Rw   R   R   t   url_desct
   image_fileR  R   (    (    s   modules/imports.pyR     s      			     '  '    * 
(	   		 c         C   s  | |  j  k r! |  j d 8_ n  |  j d k rK | d k rK d |  _ qK n  |  j d k r:| d k ry |  j t j  q| d k r d |  j d <q| d k r d |  j d <q| d	 k r d |  j d
 <q| d k r d |  j d <q| d k r}d |  j k rd |  j d <n  d |  j k r3d |  j d <n  d
 |  j k rRd |  j d
 <n  d |  j k rqd |  j d <n  g  |  _ q| d k r|  j d k r7d |  j d <q7q| d- k rd |  j d <d |  j d <|  j t j  q| d k r d |  j d <q| d k r|  j t j  q| d k rd |  _	 qn|  j d k r| d. k r|  j
 d j |  j  t |  j
  d k r|  j j |  j  qt |  j
 d  d } |  j | d k r|  j |  j | <qd } x3| d k  r| s	|  j
 d j | d  n |  j
 d j d  |  j | c d 8<| d 7} | t |  j  k rSPn  |  j | d k r| d 7} | d k  r| d 7} | t |  j  k rPn  |  j | d k r| d 7} qqqqWq| d k rd |  _ t |  j
  d k rkt |  j
 d  d k rki d d 6d  d! 6t d" 6t j d# 6|  j
 d d d$ 6} |  j j j d | d% g |  j  n |  j s|  j
 j t d&  g t |  j
 d   n |  j
 j |  j
 j d   i d' d( 6d) d* 6|  j
 d+ 6} |  j j j d | d% g |  j  |  j t j  qn  d, S(/   s   Encountered the end of a tagi   i    Rg   R   R   R"   Ri   R   R   Rk   R  R   Rf   Rn   R   R  R   R   R   R$  Ro   Rp   Ru   R*  i   R,  R-  iR  i,  t   frame_widthi   t   frame_heightt   width_in_pixelst   syntax_highlightingR6   Rr   s   click mei(   t   col_mini  t   col_maxt   matrixN(   s   h1s   h2(   s   tds   th(   R  R/  R]   R?   R   R   RS   R   R4  R@  R0  R   RA  R	   R1  RB  t   insertR   RF   R   R   t   codebox_element_to_xmlR  R2  R:  RG   t   table_element_to_xml(   R   R   t   indext
   unos_foundt   codebox_dictt
   table_dict(    (    s   modules/imports.pyR     s                      
 

  	.
%	 -
"c         C   s   |  j  d k r d S|  j d k r3 |  j |  d S|  j rW | j t j t j  } n | j t j d  } | s | t j k r d S|  j  d k r |  j | j t j t j   n0 |  j  d k r |  j	 | j t j d  7_	 n  d S(   s
   Found Datai    NR   R"   i   i   (
   R]   R@  R?   R/  R   R   R   R   t   CHAR_TABRA  (   R   R-   R  (    (    s   modules/imports.pyR   Z  s     	   " c         C   s   |  j  d k r d S| t j k r8 t t j |  } n d S|  j  d k r[ |  j |  n! |  j  d k r| |  j | 7_ n  d S(   s"   Found Entity Reference like &name;i    Ni   i   (   R]   R   R   R   R?   RA  (   R   RC   R   (    (    s   modules/imports.pyR   f  s       c         C   s$  t  j j j   |  _ |  j j d  } |  j j |  |  j j d  |  _ | j |  j  d |  _ i  |  _ x t	 j
 D] } d |  j | <qx Wg  |  _ d |  _ d |  _ d |  _ d d g |  _ d |  _ | j d d  } t   j |  s
t	 j d | t	 j } n  |  j |  |  j j   S(   s0   Parses the Given HTML String feeding the XML domt   roott   sloti    R"   R   s   utf-8R\   (   R&   R'   R(   RJ   R9   R;   R  R]   RS   R   RR   R   R4  RA  R/  R6  R@  Ra   t	   HTMLCheckt
   is_html_okt   HTML_HEADERt   HTML_FOOTERR`   RK   (   R   R  RU  RT   (    (    s   modules/imports.pyt   get_clipboard_selection_xmlo  s(    		 					(   RM   RN   RO   R   R?   R  R   R   R   R   R[  (    (    (    s   modules/imports.pyR    s   		
		_	F			RW  c           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s   Check for Minimal Tagsc         C   s   t  j  j |   d S(   s   Machine bootN(   RQ   R   (   R   (    (    s   modules/imports.pyR     s    c         C   s   | d k r' |  j  d k r' d |  _  nu | d k rN |  j  d k rN d |  _  nN | d k ru |  j  d k ru d |  _  n' | d k r |  j  d	 k r d
 |  _  n  d S(   s"   Encountered the beginning of a tagR   i    i   t   headi   R   i   Re   i   i   N(   t   steps(   R   R   R   (    (    s   modules/imports.pyR     s        c         C   s   | d k r' |  j  d k r' d |  _  nN | d k rN |  j  d k rN d |  _  n' | d k ru |  j  d k ru d |  _  n  | d	 k r |  j  d k r d
 |  _  n  d S(   s   Encountered the end of a tagR   i   i   R\  i   Re   i   i   R   i   N(   R]  (   R   R   (    (    s   modules/imports.pyR     s        c         C   s#   d |  _  |  j |  |  j  d k S(   s    Checks for the minimal html tagsi    i   (   R]  R`   (   R   R  (    (    s   modules/imports.pyRX    s    	(   RM   RN   RO   R   R   R   RX  (    (    (    s   modules/imports.pyRW    s
   			(    (    (    (   RQ   R   R~   R{   t   xml.dom.minidomR&   Rv   R   R=  R   R   R   R   R   RP   R   R   R   R   R  R  R  RW  (    (    (    s   modules/imports.pyt   <module>   s   H		CvD