patchutils.py: Allow to pass io object to read_patch and _FileReader class.

This commit is contained in:
Sebastian Lackner 2016-04-03 06:34:06 +02:00
parent 9aba381edd
commit c4a321904d
3 changed files with 8 additions and 11 deletions

View File

@ -57,7 +57,7 @@ upstream_commit()
# Show version information
version()
{
echo "Wine Staging 1.9.7"
echo "Wine Staging 1.9.8 (unreleased)"
echo "Copyright (C) 2014-2016 the Wine Staging project authors."
echo ""
echo "Patchset to be applied on upstream Wine:"

View File

@ -1 +1 @@
Wine Staging 1.9.7
Wine Staging 1.9.8 (unreleased)

View File

@ -92,15 +92,11 @@ class PatchObject(object):
return "".join(chunk for chunk in self.read_chunks())
class _FileReader(object):
def __init__(self, filename, content=None):
def __init__(self, filename, fp=None):
self.filename = filename
self.fp = fp if fp is not None else open(filename)
self.peeked = None
if content is not None:
self.fp = StringIO(content)
else:
self.fp = open(filename)
def close(self):
self.fp.close()
@ -320,11 +316,11 @@ def _parse_subject(subject):
if r is not None: return r.group(1).strip(), 1
return subject, 1
def read_patch(filename, content=None):
def read_patch(filename, fp=None):
"""Iterates over all patches contained in a file, and returns PatchObject objects."""
header = {}
with _FileReader(filename, content) as fp:
with _FileReader(filename, fp) as fp:
while True:
line = fp.peek()
if line is None:
@ -834,7 +830,8 @@ if __name__ == "__main__":
self.assertEqual(lines, expected)
# Test with StringIO buffer
patches = list(read_patch("unknown.patch", "\n".join(source + [""])))
fp = StringIO("\n".join(source + [""]))
patches = list(read_patch("unknown.patch", fp))
self.assertEqual(len(patches), 1)
self.assertEqual(patches[0].patch_author, None)
self.assertEqual(patches[0].patch_email, None)