o >Ic@s.ddlZddlZGdddeZdddZdS)Nc@seZdZdZdS) PatchErrorz Error during the patch process N)__name__ __module__ __qualname____doc__rr@/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradePatcher.pyrsrcCs<td\}}t|dd }|}Wdn1swYd}}|} t|dd }|} Wdn1s;wY| D]} | |kr| } | dr| dd} | dd\} } | retd | d\}}}tj ||||dd \}}|||<qB| d }| dd d \}}}t |}|d8}|d kr|d}nt |}|dkr|||=|} |d8}qB|dkr|} qB|dkr|||=qBtd| | |kr| dkr|} qB|d7}| || qBd |}|rt }||d||krtdt|ddd}||WddS1swYdS)z python implementation of enough "ed" to apply ed-style patches. Note that this patches in memory so its *not* suitable for big files zUTF-8)encodingNrzs//zflags for s// not supported yet)count,cadzunknown command: '%s'z. z(the md5sum after patching is not correctwT)rangeopen readlinesstrip startswithrsplitr partitionresubnintinsertjoinhashlibmd5updateencode hexdigestwrite)origedpatch result_md5sumSTATE_EXPECT_COMMANDSTATE_EXPECT_DATAf orig_linesstartendstatelineslinesubsflagsregexpsepreplnewr command start_strend_strresultr"rrrpatchsr              r=)N)r!r Exceptionrr=rrrrs