From 2d724427cfe37d5c572184f97aac3bb8932f381b Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Wed, 26 Feb 2020 17:22:12 +0000 Subject: [PATCH] Updated patch.py to avoid deprecation and pyflakes warnings. - Legacy-Id: 17346 --- ietf/utils/patch.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/ietf/utils/patch.py b/ietf/utils/patch.py index 1828aebee..0c1952f3f 100644 --- a/ietf/utils/patch.py +++ b/ietf/utils/patch.py @@ -28,7 +28,7 @@ except ImportError: try: import urllib2 as urllib_request except ImportError: - import urllib.request as urllib_request + import urllib.request as urllib_request # type: ignore from os.path import exists, isfile, abspath import os @@ -339,7 +339,7 @@ class PatchSet(object): hunkparsed = False # state after successfully parsed hunk # regexp to match start of hunk, used groups - 1,3,4,6 - re_hunk_start = re.compile(b"^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@") + re_hunk_start = re.compile(br"^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@") self.errors = 0 # temp buffers for header and filenames info @@ -479,7 +479,7 @@ class PatchSet(object): # XXX header += srcname # double source filename line is encountered # attempt to restart from this second line - re_filename = b"^--- ([^\t]+)" + re_filename = br"^--- ([^\t]+)" match = re.match(re_filename, line) # todo: support spaces in filenames if match: @@ -518,7 +518,7 @@ class PatchSet(object): filenames = False headscan = True else: - re_filename = b"^\+\+\+ ([^\t]+)" + re_filename = br"^\+\+\+ ([^\t]+)" match = re.match(re_filename, line) if not match: warning("skipping invalid patch - no target filename at line %d" % (lineno+1)) @@ -544,7 +544,7 @@ class PatchSet(object): continue if hunkhead: - match = re.match(b"^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@(.*)", line) + match = re.match(br"^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@(.*)", line) if not match: if not p.hunks: warning("skipping invalid patch with no hunks for file %s" % p.source) @@ -873,7 +873,6 @@ class PatchSet(object): hunkno = 0 hunk = p.hunks[hunkno] hunkfind = [] - hunkreplace = [] validhunks = 0 canpatch = False for lineno, line in enumerate(f2fp): @@ -881,8 +880,6 @@ class PatchSet(object): continue elif lineno+1 == hunk.startsrc: hunkfind = [x[1:].rstrip(b"\r\n") for x in hunk.text if x[0] in b" -"] - hunkreplace = [x[1:].rstrip(b"\r\n") for x in hunk.text if x[0] in b" +"] - #pprint(hunkreplace) hunklineno = 0 # todo \ No newline at end of file