U
    XXb²  ã                   @   s.   d dl Z d dlZG d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}| ¡ }W 5 Q R X d }}|}	t|dd}| ¡ }
W 5 Q R X |
D ]J}|	|kr|| ¡ }| d¡rÚ|dd… }| dd¡\}}|r¦td	ƒ‚| d¡\}}}tj	|||| dd
\}}|||< q\|d }|dd…  d¡\}}}t
|ƒ}|d8 }|dkr|d }nt
|ƒ}|dkrH|||…= |}	|d8 }n2|dkrX|}	n"|dkrn|||…= ntd| ƒ‚q\|	|kr\|dkr”|}	q\|d7 }| ||¡ q\d |¡}|rèt ¡ }| | d¡¡ | ¡ |krètdƒ‚t| ddd}| |¡ W 5 Q R X d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
    é   zUTF-8)Úencodingr   zs/Nú/é   zflags for s// not supported yet)Úcountéÿÿÿÿú,Ú ÚcÚaÚdzunknown command: '%s'z.
z(the md5sum after patching is not correctÚwT)Ú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   sf    ÿ











r1   )N)r!   r   Ú	Exceptionr   r1   r   r   r   r   Ú<module>   s   