???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................3
v:U](  ã               @   s    d dl Zd dlmZ dd„ ejjƒ 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dd„ Zdd„ Zdd„ Zd#dd„Zdd„ Zd$d!d"„ZdS )%é    N)Úconfigc             C   s&   i | ]\}}|d kr|t jj| “qS )Znbsp)ÚhtmlZentitiesZname2codepoint)Ú.0ÚkÚv© r   ú/usr/lib/python3.6/utils.pyú
<dictcomp>   s   r	   c             C   sD   | d dkr@t | ƒdkr@| d }d|  k o2dkn  r@t|ƒS dS )Nr   Úhé   é   Ú0Ú9)ÚlenÚint)ÚtagÚnr   r   r   Úhn   s
    r   c             C   s   dd„ dd„ | j dƒD ƒD ƒS )z,
    :returns: A hash of css attributes
    c             S   s&   i | ]\}}|j ƒ jƒ |j ƒ jƒ “qS r   )ÚstripÚlower)r   ÚxÚyr   r   r   r	      s   z&dumb_property_dict.<locals>.<dictcomp>c             S   s    g | ]}d |kr|j d dƒ‘qS )ú:r   )Úsplit)r   Úzr   r   r   ú
<listcomp>   s    z&dumb_property_dict.<locals>.<listcomp>ú;)r   )Ústyler   r   r   Údumb_property_dict   s    r   c             C   s’   | d7 } | j dƒ}x:|dkrL| d|… | | j d|ƒd d…  } | j dƒ}qW dd„ | jdƒD ƒ}yd	d
„ |D ƒ}W n tk
rŒ   i }Y nX |S )z‡
    :type data: str

    :returns: A hash of css selectors, each of which contains a hash of
    css attributes.
    :rtype: dict
    r   z@importr   r   Nc             S   s"   g | ]}d |j ƒ kr|jd ƒ‘qS )ú{)r   r   )r   r   r   r   r   r   /   s    z#dumb_css_parser.<locals>.<listcomp>ú}c             S   s   i | ]\}}t |ƒ|jƒ “qS r   )r   r   )r   ÚaÚbr   r   r   r	   1   s    z#dumb_css_parser.<locals>.<dictcomp>éÿÿÿÿ)Úfindr   Ú
ValueError)ÚdataZimportIndexÚelementsr   r   r   Údumb_css_parser   s    	

$
r(   c             C   sb   |j ƒ }d| kr@x.| d jƒ D ]}|jd| i ƒ}|j|ƒ qW d| kr^t| d ƒ}|j|ƒ |S )z¥
    :type attrs: dict
    :type style_def: dict
    :type style_def: dict

    :returns: A hash of the 'final' style attributes of the element
    :rtype: dict
    ÚclassÚ.r   )Úcopyr   ÚgetÚupdater   )ÚattrsZ	style_defZparent_styler   Z	css_classZ	css_styleZimmediate_styler   r   r   Úelement_style8   s    	
r/   c             C   s    d| kr| d }|dkrdS dS )	zh
    Finds out whether this is an ordered or unordered list

    :type style: dict

    :rtype: str
    zlist-style-typeÚdiscÚcircleÚsquareÚnoneZulZol)r0   r1   r2   r3   r   )r   Z
list_styler   r   r   Úgoogle_list_styleM   s
    r4   c             C   s   d| kS )z†
    Check if the style of the element has the 'height' attribute
    explicitly defined

    :type style: dict

    :rtype: bool
    Zheightr   )r   r   r   r   Úgoogle_has_height]   s    	r5   c             C   sJ   g }d| kr|j | d ƒ d| kr0|j | d ƒ d| krF|j | d ƒ |S )zk
    :type style: dict

    :returns: A list of all emphasis modifiers of the element
    :rtype: list
    ztext-decorationz
font-stylezfont-weight)Úappend)r   Zemphasisr   r   r   Úgoogle_text_emphasisi   s    r7   c             C   s$   d}d| kr| d }d|kp"d|kS )zu
    Check if the css of the current element defines a fixed width font

    :type style: dict

    :rtype: bool
    Ú zfont-familyzcourier newZconsolasr   )r   Zfont_familyr   r   r   Úgoogle_fixed_width_font{   s    r9   c             C   s2   d| kr.yt | d ƒd S  tk
r,   Y nX dS )zh
    Extract numbering from list element attributes

    :type attrs: dict

    :rtype: int or None
    Ústartr   r   )r   r%   )r.   r   r   r   Úlist_numbering_start‰   s    r;   c             C   s¶   t tjj| ƒƒdkr| rdS | dd… dks:| d dkr>dS | jƒ }|dd… dkrrt |ƒdkrr|d dkrrd	S |dd
… dkrš|dd… dk rš| S ttjj|ƒp²tjj|ƒƒS )Nr   Té   z    ú	r   z--ú-Fr   Ú*z**)r>   r?   )	r   r   ZRE_LINKÚfindallÚlstripÚboolZRE_ORDERED_LIST_MATCHERÚmatchZRE_UNORDERED_LIST_MATCHER)ZparaZ
wrap_linksZwrap_list_itemsÚstrippedr   r   r   Úskipwrapš   s    ("rE   c             C   s   t jjd| ƒS )zU
    Escapes markdown-sensitive characters within other markdown
    constructs.
    z\\\1)r   ZRE_MD_CHARS_MATCHERÚsub)Útextr   r   r   Ú	escape_md¹   s    rH   Fc             C   sN   t jjd| ƒ} |r t jjd| ƒ} t jjd| ƒ} t jjd| ƒ} t jjd| ƒ} | S )zO
    Escapes markdown-sensitive characters across whole document sections.
    z\\\1z\1\\\2)r   ZRE_MD_BACKSLASH_MATCHERrF   ZRE_MD_CHARS_MATCHER_ALLZRE_MD_DOT_MATCHERZRE_MD_PLUS_MATCHERZRE_MD_DASH_MATCHER)rG   Zsnobr   r   r   Úescape_md_sectionÁ   s    rI   c       	         s<  ‡fdd„| d j dƒD ƒ}t|ƒ}xŒ| D ]„}dd„ |j dƒD ƒ}t|ƒ}||k rf|dg||  7 }n0||k r–|‡fdd„|||  d… D ƒ7 }|}‡fd	d„t||ƒD ƒ}q*W g }x€| D ]x}d
d„ |j dƒD ƒ}t|jƒ ƒtdƒkrd‰ ‡ fdd„t||ƒD ƒ}nd‰ ‡ fdd„t||ƒD ƒ}|jdj|ƒƒ q¼W |S )zR
    Given the lines of a table
    padds the cells and returns the new lines
    c                s   g | ]}t |jƒ ƒˆ  ‘qS r   )r   Úrstrip)r   r   )Úright_marginr   r   r   ×   s    z"reformat_table.<locals>.<listcomp>r   ú|c             S   s   g | ]}|j ƒ ‘qS r   )rJ   )r   r   r   r   r   r   Ú   s    r8   c                s   g | ]}t |ƒˆ  ‘qS r   )r   )r   r   )rK   r   r   r   á   s    Nc                s"   g | ]\}}t t|ƒˆ  |ƒ‘qS r   )Úmaxr   )r   r   Zold_len)rK   r   r   r   å   s    c             S   s   g | ]}|j ƒ ‘qS r   )rJ   )r   r   r   r   r   r   ë   s    z-|r>   c                s,   g | ]$\}}|j ƒ ˆ |t|j ƒ ƒ   ‘qS r   )rJ   r   )r   r   ÚM)Úfillerr   r   r   ï   s   ú c                s,   g | ]$\}}|j ƒ ˆ |t|j ƒ ƒ   ‘qS r   )rJ   r   )r   r   rN   )rO   r   r   r   õ   s   )r   r   ÚzipÚsetr   r6   Újoin)	ÚlinesrK   Z	max_widthZmax_colsÚlineZcolsZnum_colsÚ	new_linesZnew_colsr   )rO   rK   r   Úreformat_tableÑ   s.    
$


rW   r   c             C   s‚   | j dƒ}g d }}g }x^|D ]V}tj|krZ| }|st||ƒ}|j|ƒ g }|jdƒ q|rj|j|ƒ q|j|ƒ qW dj|ƒS )z0
    Provide padding for tables in the text
    Ú
Fr8   )r   r   ZTABLE_MARKER_FOR_PADrW   Úextendr6   rS   )rG   rK   rT   Ztable_bufferZtable_startedrV   rU   Útabler   r   r   Úpad_tables_in_textü   s     






r[   )F)r   )Zhtml.entitiesr   Z	html2textr   Z	UNIFIABLEÚitemsZunifiable_nr   r   r(   r/   r4   r5   r7   r9   r;   rE   rH   rI   rW   r[   r   r   r   r   Ú<module>   s"   

+