ó
QşNc           @   sJ   d  d l  Z  d  d l Z d  d l Z d e f d     YZ d d  Z d S(   i˙˙˙˙Nt
   PatchErrorc           B   s   e  Z d  Z RS(   s     Error during the patch process (   t   __name__t
   __module__t   __doc__(    (    (    sB   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradePatcher.pyR       s   c         C   st  t  d  \ } } t |   j   } d } } | } xŃt |  D]Ă}	 | | k rĆ|	 j   }	 |	 j d  rű |	 d }	 t j |	 d d d d \ }
 } | rŽ t d   n  |
 j d  \ } } } t	 j
 | | | | d	 d \ } } | | | <qA n  |	 d
 } |	 d
  j d  \ } } } t |  } | d 8} | d k rP| d } n t |  } | d k r| | | 5| } | d 8} q| d k r| } q| d k rł| | | 5qt d |	   qA | | k rA |	 d k rç| } q| d 7} | j | |	  qA qA Wd j |  } | rZt j   } | j |  | j   | k rZt d   qZn  t |  d  j |  t S(   s    python implementation of enough "ed" to apply ed-style
        patches. Note that this patches in memory so its *not*
        suitable for big files
    i   i    s   s/t   sept   /t   maxspliti   s   flags for s// not supported yett   counti˙˙˙˙t   ,t    t   ct   at   ds   unknown command: '%s's   .
s(   the md5sum after patching is not correctt   w(   t   ranget   opent	   readlinest   stript
   startswitht   stringt   rsplitR    t	   partitiont   ret   subnt   intt   insertt   joint   hashlibt   md5t   updatet	   hexdigestt   writet   True(   t   origt   edpatcht   result_md5sumt   STATE_EXPECT_COMMANDt   STATE_EXPECT_DATAt
   orig_linest   startt   endt   statet   linet   subst   flagst   regexpR   t   replt   newR   t   commandt	   start_strt   end_strt   resultR   (    (    sB   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradePatcher.pyt   patch   sZ    

!%



		
(   R   R   R   t	   ExceptionR    t   NoneR4   (    (    (    sB   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradePatcher.pyt   <module>   s   