
Y]                 @   sA   d  d l  Z  d  d l Z Gd d   d e  Z d d d  Z d S)    Nc               @   s   e  Z d  Z d Z d S)
PatchErrorz  Error during the patch process N)__name__
__module____qualname____doc__ r   r   @/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradePatcher.pyr      s   r   c             C   s  t  d  \ } } t |  d d  } | j   } Wd QRXd } } | }	 t | d d  } | j   }
 Wd QRXx|
 D]} |	 | k r| j   } | j d  r*| d d  } | j d d  \ } } | r t d	   | j d  \ } } } t j	 | | | | d
 d \ } } | | | <qy | d } | d d  j d  \ } } } t
 |  } | d 8} | d k r| d } n t
 |  } | d k r| | |  =| }	 | d 8} q<| d k r| }	 q<| d k r| | |  =q<t d |   qy |	 | k ry | d k r"| }	 qy | d 7} | j | |  qy Wd j |  } | rt j   } | j | j d   | j   | k rt d   t |  d d d  } | j |  Wd QRXd S)z python implementation of enough "ed" to apply ed-style
        patches. Note that this patches in memory so its *not*
        suitable for big files
       encodingzUTF-8Nr   zs//   zflags for s// not supported yetcount, cadzunknown command: '%s'z.
z(the md5sum after patching is not correctwTr   )rangeopen	readlinesstrip
startswithrsplitr   	partitionresubnintinsertjoinhashlibmd5updateencodeZ	hexdigestwrite)ZorigZedpatchZresult_md5sumZSTATE_EXPECT_COMMANDZSTATE_EXPECT_DATAfZ
orig_linesstartendstatelineslineZsubsflagsZregexpsepreplnewr   ZcommandZ	start_strZend_strresultr"   r   r   r   patch   sb    
%

"
		
r1   )r!   r   	Exceptionr   r1   r   r   r   r   <module>   s   