o
    >Ic                     @   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 d   n1 sw   Y  d }}|}	t|dd}| }
W d   n1 s;w   Y  |
D ]}|	|kr| }|dr|dd }|dd\}}|retd	|d\}}}tj	|||| dd
\}}|||< qB|d }|dd d\}}}t
|}|d8 }|dkr|d }nt
|}|dkr|||= |}	|d8 }qB|dkr|}	qB|dkr|||= qBtd| |	|kr|dkr|}	qB|d7 }||| qBd|}|rt }||d | |krtdt| ddd}|| W d   dS 1 sw   Y  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)encodingNr   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wT)rangeopen	readlinesstrip
startswithrsplitr   	partitionresubnintinsertjoinhashlibmd5updateencode	hexdigestwrite)origedpatchresult_md5sumSTATE_EXPECT_COMMANDSTATE_EXPECT_DATAf
orig_linesstartendstatelineslinesubsflagsregexpsepreplnewr   command	start_strend_strresultr"   r   r   r   patch   sr   







r=   )N)r!   r   	Exceptionr   r=   r   r   r   r   <module>   s   