@@ -114,11 +114,11 @@ def __init__(self, options=None):
114
114
self .lines = []
115
115
self .options = options or CogOptions ()
116
116
117
- def parseMarker (self , l ):
118
- self .markers .append (l )
117
+ def parseMarker (self , line ):
118
+ self .markers .append (line )
119
119
120
- def parseLine (self , l ):
121
- self .lines .append (l .strip ("\n " ))
120
+ def parseLine (self , line ):
121
+ self .lines .append (line .strip ("\n " ))
122
122
123
123
def getCode (self ):
124
124
"""Extract the executable Python code from the generator."""
@@ -127,8 +127,8 @@ def getCode(self):
127
127
# then remove it from all the lines.
128
128
prefIn = commonPrefix (self .markers + self .lines )
129
129
if prefIn :
130
- self .markers = [l .replace (prefIn , "" , 1 ) for l in self .markers ]
131
- self .lines = [l .replace (prefIn , "" , 1 ) for l in self .lines ]
130
+ self .markers = [line .replace (prefIn , "" , 1 ) for line in self .markers ]
131
+ self .lines = [line .replace (prefIn , "" , 1 ) for line in self .lines ]
132
132
133
133
return reindentBlock (self .lines , "" )
134
134
@@ -160,7 +160,7 @@ def evaluate(self, cog, globals, fname):
160
160
eval (code , globals )
161
161
except CogError :
162
162
raise
163
- except :
163
+ except : # noqa: E722 (we're just wrapping in CogUserException and rethrowing)
164
164
typ , err , tb = sys .exc_info ()
165
165
frames = (tuple (fr ) for fr in traceback .extract_tb (tb .tb_next ))
166
166
frames = find_cog_source (frames , prologue )
@@ -433,106 +433,106 @@ def processFile(self, fIn, fOut, fname=None, globals=None):
433
433
globals .update (self .options .defines )
434
434
435
435
# loop over generator chunks
436
- l = fIn .readline ()
437
- while l :
436
+ line = fIn .readline ()
437
+ while line :
438
438
# Find the next spec begin
439
- while l and not self .isBeginSpecLine (l ):
440
- if self .isEndSpecLine (l ):
439
+ while line and not self .isBeginSpecLine (line ):
440
+ if self .isEndSpecLine (line ):
441
441
raise CogError (
442
442
f"Unexpected { self .options .sEndSpec !r} " ,
443
443
file = sFileIn ,
444
444
line = fIn .linenumber (),
445
445
)
446
- if self .isEndOutputLine (l ):
446
+ if self .isEndOutputLine (line ):
447
447
raise CogError (
448
448
f"Unexpected { self .options .sEndOutput !r} " ,
449
449
file = sFileIn ,
450
450
line = fIn .linenumber (),
451
451
)
452
- fOut .write (l )
453
- l = fIn .readline ()
454
- if not l :
452
+ fOut .write (line )
453
+ line = fIn .readline ()
454
+ if not line :
455
455
break
456
456
if not self .options .bDeleteCode :
457
- fOut .write (l )
457
+ fOut .write (line )
458
458
459
459
# l is the begin spec
460
460
gen = CogGenerator (options = self .options )
461
461
gen .setOutput (stdout = self .stdout )
462
- gen .parseMarker (l )
462
+ gen .parseMarker (line )
463
463
firstLineNum = fIn .linenumber ()
464
464
self .cogmodule .firstLineNum = firstLineNum
465
465
466
466
# If the spec begin is also a spec end, then process the single
467
467
# line of code inside.
468
- if self .isEndSpecLine (l ):
469
- beg = l .find (self .options .sBeginSpec )
470
- end = l .find (self .options .sEndSpec )
468
+ if self .isEndSpecLine (line ):
469
+ beg = line .find (self .options .sBeginSpec )
470
+ end = line .find (self .options .sEndSpec )
471
471
if beg > end :
472
472
raise CogError (
473
473
"Cog code markers inverted" , file = sFileIn , line = firstLineNum
474
474
)
475
475
else :
476
- sCode = l [beg + len (self .options .sBeginSpec ) : end ].strip ()
476
+ sCode = line [beg + len (self .options .sBeginSpec ) : end ].strip ()
477
477
gen .parseLine (sCode )
478
478
else :
479
479
# Deal with an ordinary code block.
480
- l = fIn .readline ()
480
+ line = fIn .readline ()
481
481
482
482
# Get all the lines in the spec
483
- while l and not self .isEndSpecLine (l ):
484
- if self .isBeginSpecLine (l ):
483
+ while line and not self .isEndSpecLine (line ):
484
+ if self .isBeginSpecLine (line ):
485
485
raise CogError (
486
486
f"Unexpected { self .options .sBeginSpec !r} " ,
487
487
file = sFileIn ,
488
488
line = fIn .linenumber (),
489
489
)
490
- if self .isEndOutputLine (l ):
490
+ if self .isEndOutputLine (line ):
491
491
raise CogError (
492
492
f"Unexpected { self .options .sEndOutput !r} " ,
493
493
file = sFileIn ,
494
494
line = fIn .linenumber (),
495
495
)
496
496
if not self .options .bDeleteCode :
497
- fOut .write (l )
498
- gen .parseLine (l )
499
- l = fIn .readline ()
500
- if not l :
497
+ fOut .write (line )
498
+ gen .parseLine (line )
499
+ line = fIn .readline ()
500
+ if not line :
501
501
raise CogError (
502
502
"Cog block begun but never ended." ,
503
503
file = sFileIn ,
504
504
line = firstLineNum ,
505
505
)
506
506
507
507
if not self .options .bDeleteCode :
508
- fOut .write (l )
509
- gen .parseMarker (l )
508
+ fOut .write (line )
509
+ gen .parseMarker (line )
510
510
511
- l = fIn .readline ()
511
+ line = fIn .readline ()
512
512
513
513
# Eat all the lines in the output section. While reading past
514
514
# them, compute the md5 hash of the old output.
515
515
previous = []
516
516
hasher = md5 ()
517
- while l and not self .isEndOutputLine (l ):
518
- if self .isBeginSpecLine (l ):
517
+ while line and not self .isEndOutputLine (line ):
518
+ if self .isBeginSpecLine (line ):
519
519
raise CogError (
520
520
f"Unexpected { self .options .sBeginSpec !r} " ,
521
521
file = sFileIn ,
522
522
line = fIn .linenumber (),
523
523
)
524
- if self .isEndSpecLine (l ):
524
+ if self .isEndSpecLine (line ):
525
525
raise CogError (
526
526
f"Unexpected { self .options .sEndSpec !r} " ,
527
527
file = sFileIn ,
528
528
line = fIn .linenumber (),
529
529
)
530
- previous .append (l )
531
- hasher .update (l .encode ("utf-8" ))
532
- l = fIn .readline ()
530
+ previous .append (line )
531
+ hasher .update (line .encode ("utf-8" ))
532
+ line = fIn .readline ()
533
533
curHash = hasher .hexdigest ()
534
534
535
- if not l and not self .options .bEofCanBeEnd :
535
+ if not line and not self .options .bEofCanBeEnd :
536
536
# We reached end of file before we found the end output line.
537
537
raise CogError (
538
538
f"Missing { self .options .sEndOutput !r} before end of file." ,
@@ -557,7 +557,7 @@ def processFile(self, fIn, fOut, fname=None, globals=None):
557
557
bSawCog = True
558
558
559
559
# Write the ending output line
560
- hashMatch = self .reEndOutput .search (l )
560
+ hashMatch = self .reEndOutput .search (line )
561
561
if self .options .bHashOutput :
562
562
if hashMatch :
563
563
oldHash = hashMatch ["hash" ]
@@ -568,20 +568,20 @@ def processFile(self, fIn, fOut, fname=None, globals=None):
568
568
line = fIn .linenumber (),
569
569
)
570
570
# Create a new end line with the correct hash.
571
- endpieces = l .split (hashMatch .group (0 ), 1 )
571
+ endpieces = line .split (hashMatch .group (0 ), 1 )
572
572
else :
573
573
# There was no old hash, but we want a new hash.
574
- endpieces = l .split (self .options .sEndOutput , 1 )
575
- l = (self .sEndFormat % newHash ).join (endpieces )
574
+ endpieces = line .split (self .options .sEndOutput , 1 )
575
+ line = (self .sEndFormat % newHash ).join (endpieces )
576
576
else :
577
577
# We don't want hashes output, so if there was one, get rid of
578
578
# it.
579
579
if hashMatch :
580
- l = l .replace (hashMatch ["hashsect" ], "" , 1 )
580
+ line = line .replace (hashMatch ["hashsect" ], "" , 1 )
581
581
582
582
if not self .options .bDeleteCode :
583
- fOut .write (l )
584
- l = fIn .readline ()
583
+ fOut .write (line )
584
+ line = fIn .readline ()
585
585
586
586
if not bSawCog and self .options .bWarnEmpty :
587
587
self .showWarning (f"no cog code found in { sFileIn } " )
@@ -712,9 +712,9 @@ def processFileList(self, sFileList):
712
712
flist = self .openInputFile (sFileList )
713
713
lines = flist .readlines ()
714
714
flist .close ()
715
- for l in lines :
715
+ for line in lines :
716
716
# Use shlex to parse the line like a shell.
717
- lex = shlex .shlex (l , posix = True )
717
+ lex = shlex .shlex (line , posix = True )
718
718
lex .whitespace_split = True
719
719
lex .commenters = "#"
720
720
# No escapes, so that backslash can be part of the path
0 commit comments