ó
àú\c           @   st   d  Z  d d l Z d d l m Z y d d l m Z Wn! e k
 rY d d l m Z n Xd e	 f d     YZ
 d S(   s  
    sphinxcontrib.websupport.storage.differ
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    A differ for creating an HTML representations of proposal diffs

    :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
i˙˙˙˙N(   t   Differ(   t   escapet   CombinedHtmlDiffc           B   sM   e  Z d  Z e j d  Z d   Z d   Z d   Z d d  Z
 d   Z RS(   sU   Create an HTML representation of the differences between two pieces
    of text.
    s   ([\+\-\^]+)c         C   sF   t  |  } t   } t | j | j d  | j d    |  _ d  S(   Ni   (   t
   htmlescapeR    t   listt   comparet
   splitlinest   diff(   t   selft   sourcet   proposalt   differ(    (    sF   lib/python2.7/site-packages/sphinxcontrib/websupport/storage/differ.pyt   __init__   s    	c         C   s   d j  |  j  S(   Ns   
(   t   joinR   (   R   (    (    sF   lib/python2.7/site-packages/sphinxcontrib/websupport/storage/differ.pyt	   make_text"   s    c         C   sĞ   g  } |  j  } | j d  } | j d  } xg t r | j |  j | |   | } y | j d  } Wq1 t k
 r | j |  j |   Pq1 Xq1 Wd j |  j   S(   s¸   Return the HTML representation of the differences between
        `source` and `proposal`.

        :param source: the original text
        :param proposal: the proposed text
        i    t    (   R   t   popt   Truet   appendt   _handle_linet
   IndexErrorR   t   rstrip(   R   t   htmlR   t   linet   next(    (    sF   lib/python2.7/site-packages/sphinxcontrib/websupport/storage/differ.pyt	   make_html%   s    
		c         C   sĴ   | d } | d } | d k r$ | S| d k r4 d S| d k	 r | d d k r | d k rb d pe d } |  j | | |  } n  | d k r d	 p d
 } d | | j   f S(   s$   Handle an individual line in a diff.i    i   t    t   ?R   t   +t   inst   dels
   prop-addeds   prop-removeds   <span class="%s">%s</span>
N(   t   Nonet   _highlight_textR   (   R   R   R   t   prefixt   textt   tagt	   css_class(    (    sF   lib/python2.7/site-packages/sphinxcontrib/websupport/storage/differ.pyR   :   s    

c         C   sı   | d } g  } d } x |  j  j |  D]n } | j | | | j   ! | j d |  | j | | j   | j   ! | j d |  | j   } q) W| j | |  d j |  S(   s^   Highlight the specific changes made to a line by adding
        <ins> and <del> tags.
        i   i    s   <%s>s   </%s>R   (   t   highlight_regext   finditerR   t   startt   endR   (   R   R"   R   R#   t   new_textR'   t   match(    (    sF   lib/python2.7/site-packages/sphinxcontrib/websupport/storage/differ.pyR    K   s    
 N(   t   __name__t
   __module__t   __doc__t   ret   compileR%   R   R   R   R   R   R    (    (    (    sF   lib/python2.7/site-packages/sphinxcontrib/websupport/storage/differ.pyR      s   			(   R-   R.   t   difflibR    R   R   R   t   ImportErrort   cgit   objectR   (    (    (    sF   lib/python2.7/site-packages/sphinxcontrib/websupport/storage/differ.pyt   <module>
   s   