Skip to content

Commit 55db096

Browse files
author
Thomas Grainger
committed
fix lint errors in src
1 parent 74468d4 commit 55db096

File tree

1 file changed

+84
-75
lines changed

1 file changed

+84
-75
lines changed

whatthepatch/patch.py

Lines changed: 84 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
from .snippets import split_by_regex, findall_regex
77

8-
header = namedtuple('header',
9-
'index_path old_path old_version new_path new_version')
8+
header = namedtuple(
9+
'header',
10+
'index_path old_path old_version new_path new_version',
11+
)
1012

1113
diffobj = namedtuple('diff', 'header changes text')
1214

@@ -71,17 +73,17 @@ def parse_patch(text):
7173
lines = text
7274

7375
# maybe use this to nuke all of those line endings?
74-
#lines = [x.splitlines()[0] for x in lines]
76+
# lines = [x.splitlines()[0] for x in lines]
7577
lines = [x if len(x) == 0 else x.splitlines()[0] for x in lines]
7678

7779
check = [
78-
unified_header_index,
79-
diffcmd_header,
80-
cvs_header_rcs,
81-
git_header_index,
82-
context_header_old_line,
83-
unified_header_old_line,
84-
]
80+
unified_header_index,
81+
diffcmd_header,
82+
cvs_header_rcs,
83+
git_header_index,
84+
context_header_old_line,
85+
unified_header_old_line,
86+
]
8587

8688
for c in check:
8789
diffs = split_by_regex(lines, c)
@@ -95,12 +97,14 @@ def parse_patch(text):
9597
if h or d:
9698
yield diffobj(header=h, changes=d, text=difftext)
9799

100+
98101
def parse_header(text):
99102
h = parse_scm_header(text)
100103
if h is None:
101104
h = parse_diff_header(text)
102105
return h
103106

107+
104108
def parse_scm_header(text):
105109
try:
106110
lines = text.splitlines()
@@ -130,41 +134,42 @@ def parse_scm_header(text):
130134
new_path = new_path[2:]
131135

132136
return header(
133-
index_path=res.index_path,
134-
old_path = old_path,
135-
old_version = res.old_version,
136-
new_path = new_path,
137-
new_version = res.new_version
138-
)
137+
index_path=res.index_path,
138+
old_path=old_path,
139+
old_version=res.old_version,
140+
new_path=new_path,
141+
new_version=res.new_version
142+
)
139143
else:
140144
res = parser(lines)
141145

142146
return res
143147

144148
return None
145149

150+
146151
def parse_diff_header(text):
147152
try:
148153
lines = text.splitlines()
149154
except AttributeError:
150155
lines = text
151156

152157
check = [
153-
(unified_header_new_line, parse_unified_header),
154-
(context_header_old_line, parse_context_header),
155-
(diffcmd_header, parse_diffcmd_header),
156-
# TODO:
157-
# git_header can handle version-less unified headers, but
158-
# will trim a/ and b/ in the paths if they exist...
159-
(git_header_new_line, parse_git_header),
160-
]
158+
(unified_header_new_line, parse_unified_header),
159+
(context_header_old_line, parse_context_header),
160+
(diffcmd_header, parse_diffcmd_header),
161+
# TODO:
162+
# git_header can handle version-less unified headers, but
163+
# will trim a/ and b/ in the paths if they exist...
164+
(git_header_new_line, parse_git_header),
165+
]
161166

162167
for regex, parser in check:
163168
diffs = findall_regex(lines, regex)
164169
if len(diffs) > 0:
165170
return parser(lines)
166171

167-
return None # no header?
172+
return None # no header?
168173

169174

170175
def parse_diff(text):
@@ -174,18 +179,19 @@ def parse_diff(text):
174179
lines = text
175180

176181
check = [
177-
(unified_hunk_start, parse_unified_diff),
178-
(context_hunk_start, parse_context_diff),
179-
(default_hunk_start, parse_default_diff),
180-
(ed_hunk_start, parse_ed_diff),
181-
(rcs_ed_hunk_start, parse_rcs_ed_diff),
182-
]
182+
(unified_hunk_start, parse_unified_diff),
183+
(context_hunk_start, parse_context_diff),
184+
(default_hunk_start, parse_default_diff),
185+
(ed_hunk_start, parse_ed_diff),
186+
(rcs_ed_hunk_start, parse_rcs_ed_diff),
187+
]
183188

184189
for hunk, parser in check:
185190
diffs = findall_regex(lines, hunk)
186191
if len(diffs) > 0:
187192
return parser(lines)
188193

194+
189195
def parse_git_header(text):
190196
try:
191197
lines = text.splitlines()
@@ -223,14 +229,16 @@ def parse_git_header(text):
223229
if new_path.startswith('b/'):
224230
new_path = new_path[2:]
225231
return header(
226-
index_path = None,
227-
old_path = old_path,
228-
old_version = over,
229-
new_path = new_path,
230-
new_version = nver)
232+
index_path=None,
233+
old_path=old_path,
234+
old_version=over,
235+
new_path=new_path,
236+
new_version=nver
237+
)
231238

232239
return None
233240

241+
234242
def parse_svn_header(text):
235243
try:
236244
lines = text.splitlines()
@@ -250,11 +258,11 @@ def parse_svn_header(text):
250258
diff_header = parse_diff_header(lines)
251259
if not diff_header:
252260
return header(
253-
index_path = i.group(1),
254-
old_path = i.group(1),
255-
old_version = None,
256-
new_path = i.group(1),
257-
new_version = None,
261+
index_path=i.group(1),
262+
old_path=i.group(1),
263+
old_version=None,
264+
new_path=i.group(1),
265+
new_version=None,
258266
)
259267

260268
opath = diff_header.old_path
@@ -292,16 +300,16 @@ def parse_svn_header(text):
292300
nver = None
293301

294302
return header(
295-
index_path = i.group(1),
296-
old_path = opath,
297-
old_version = over,
298-
new_path = npath,
299-
new_version = nver,
303+
index_path=i.group(1),
304+
old_path=opath,
305+
old_version=over,
306+
new_path=npath,
307+
new_version=nver,
300308
)
301309

302-
303310
return None
304311

312+
305313
def parse_cvs_header(text):
306314
try:
307315
lines = text.splitlines()
@@ -340,18 +348,18 @@ def parse_cvs_header(text):
340348
nver = nend_c.group(1)
341349

342350
return header(
343-
index_path = i.group(1),
344-
old_path = diff_header.old_path,
345-
old_version = over,
346-
new_path = diff_header.new_path,
347-
new_version = nver,
351+
index_path=i.group(1),
352+
old_path=diff_header.old_path,
353+
old_version=over,
354+
new_path=diff_header.new_path,
355+
new_version=nver,
348356
)
349357
return header(
350-
index_path = i.group(1),
351-
old_path = i.group(1),
352-
old_version = None,
353-
new_path = i.group(1),
354-
new_version = None,
358+
index_path=i.group(1),
359+
old_path=i.group(1),
360+
old_version=None,
361+
new_path=i.group(1),
362+
new_version=None,
355363
)
356364
elif headers_old:
357365
# parse old style headers
@@ -364,27 +372,28 @@ def parse_cvs_header(text):
364372
d = old_cvs_diffcmd_header.match(lines[0])
365373
if not d:
366374
return header(
367-
index_path = i.group(1),
368-
old_path = i.group(1),
369-
old_version = None,
370-
new_path = i.group(1),
371-
new_version = None,
375+
index_path=i.group(1),
376+
old_path=i.group(1),
377+
old_version=None,
378+
new_path=i.group(1),
379+
new_version=None,
372380
)
373381

374382
# will get rid of the useless stuff for us
375-
_ = parse_diff_header(lines)
383+
parse_diff_header(lines)
376384
over = d.group(2) if d.group(2) else None
377385
nver = d.group(4) if d.group(4) else None
378386
return header(
379-
index_path = i.group(1),
380-
old_path = d.group(1),
381-
old_version = over,
382-
new_path = d.group(3),
383-
new_version = nver,
387+
index_path=i.group(1),
388+
old_path=d.group(1),
389+
old_version=over,
390+
new_path=d.group(3),
391+
new_version=nver,
384392
)
385393

386394
return None
387395

396+
388397
def parse_diffcmd_header(text):
389398
try:
390399
lines = text.splitlines()
@@ -400,15 +409,15 @@ def parse_diffcmd_header(text):
400409
del lines[0]
401410
if d:
402411
return header(
403-
index_path = None,
404-
old_path = d.group(1),
405-
old_version = None,
406-
new_path = d.group(2),
407-
new_version = None,
408-
)
409-
412+
index_path=None,
413+
old_path=d.group(1),
414+
old_version=None,
415+
new_path=d.group(2),
416+
new_version=None,
417+
)
410418
return None
411419

420+
412421
def parse_unified_header(text):
413422
try:
414423
lines = text.splitlines()

0 commit comments

Comments
 (0)