Skip to content

Commit 2d72442

Browse files
committed
Updated patch.py to avoid deprecation and pyflakes warnings.
- Legacy-Id: 17346
1 parent 095c3a2 commit 2d72442

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

ietf/utils/patch.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
try:
2929
import urllib2 as urllib_request
3030
except ImportError:
31-
import urllib.request as urllib_request
31+
import urllib.request as urllib_request # type: ignore
3232

3333
from os.path import exists, isfile, abspath
3434
import os
@@ -339,7 +339,7 @@ def lineno(self):
339339
hunkparsed = False # state after successfully parsed hunk
340340

341341
# regexp to match start of hunk, used groups - 1,3,4,6
342-
re_hunk_start = re.compile(b"^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@")
342+
re_hunk_start = re.compile(br"^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@")
343343

344344
self.errors = 0
345345
# temp buffers for header and filenames info
@@ -479,7 +479,7 @@ def lineno(self):
479479
# XXX header += srcname
480480
# double source filename line is encountered
481481
# attempt to restart from this second line
482-
re_filename = b"^--- ([^\t]+)"
482+
re_filename = br"^--- ([^\t]+)"
483483
match = re.match(re_filename, line)
484484
# todo: support spaces in filenames
485485
if match:
@@ -518,7 +518,7 @@ def lineno(self):
518518
filenames = False
519519
headscan = True
520520
else:
521-
re_filename = b"^\+\+\+ ([^\t]+)"
521+
re_filename = br"^\+\+\+ ([^\t]+)"
522522
match = re.match(re_filename, line)
523523
if not match:
524524
warning("skipping invalid patch - no target filename at line %d" % (lineno+1))
@@ -544,7 +544,7 @@ def lineno(self):
544544
continue
545545

546546
if hunkhead:
547-
match = re.match(b"^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@(.*)", line)
547+
match = re.match(br"^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@(.*)", line)
548548
if not match:
549549
if not p.hunks:
550550
warning("skipping invalid patch with no hunks for file %s" % p.source)
@@ -873,16 +873,13 @@ def apply(self, strip=0, root=None):
873873
hunkno = 0
874874
hunk = p.hunks[hunkno]
875875
hunkfind = []
876-
hunkreplace = []
877876
validhunks = 0
878877
canpatch = False
879878
for lineno, line in enumerate(f2fp):
880879
if lineno+1 < hunk.startsrc:
881880
continue
882881
elif lineno+1 == hunk.startsrc:
883882
hunkfind = [x[1:].rstrip(b"\r\n") for x in hunk.text if x[0] in b" -"]
884-
hunkreplace = [x[1:].rstrip(b"\r\n") for x in hunk.text if x[0] in b" +"]
885-
#pprint(hunkreplace)
886883
hunklineno = 0
887884

888885
# todo \ No newline at end of file

0 commit comments

Comments
 (0)