title: Pure Python way to apply a unified diff to a file?
body: <p>I've got a unified diff file (let's call it a patch). I need to open it, apply to a specified file and save the result back to the file. Same way as Unix <code>patch</code> tool does. I need a Python solution that I could easily call from my .py script, and so far I can't find any.</p>
  
  <p>I've looked at <a href="https://code.google.com/p/google-diff-match-patch/wiki/API" rel="noreferrer">https://code.google.com/p/google-diff-match-patch/wiki/API</a>, and it looks like it can't do what I need. I also looked at <a href="https://github.com/techtonik/python-patch" rel="noreferrer">https://github.com/techtonik/python-patch</a> and <a href="https://github.com/matiasb/python-unidiff" rel="noreferrer">https://github.com/matiasb/python-unidiff</a>. <code>python-patch</code> seems to emulate the Unix <code>patch</code> util, but it's a command line tool and I don't understand how to call it from my .py script.</p>