Skip to content

Commit a863dfb

Browse files
committed
refactor: a little new-hashing pre-work
1 parent 6dbbc3e commit a863dfb

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

cogapp/cogapp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ def __init__(self):
349349

350350
def _fix_end_output_patterns(self):
351351
end_output = re.escape(self.options.end_output)
352-
self.re_end_output = re.compile(
353-
end_output + r"(?P<hashsect> *\(checksum: (?P<hash>[a-f0-9]+)\))"
352+
self.re_end_output_with_hash = re.compile(
353+
end_output + r"(?P<hashsect> *\(checksum: (?P<hash>[a-f0-9]{32})\))"
354354
)
355355
self.end_format = self.options.end_output + " (checksum: %s)"
356356

@@ -458,7 +458,7 @@ def process_file(self, file_in, file_out, fname=None, globals=None):
458458
if not self.options.delete_code:
459459
file_out.write(line)
460460

461-
# l is the begin spec
461+
# `line` is the begin spec
462462
gen = CogGenerator(options=self.options)
463463
gen.set_output(stdout=self.stdout)
464464
gen.parse_marker(line)
@@ -561,7 +561,7 @@ def process_file(self, file_in, file_out, fname=None, globals=None):
561561
saw_cog = True
562562

563563
# Write the ending output line
564-
hash_match = self.re_end_output.search(line)
564+
hash_match = self.re_end_output_with_hash.search(line)
565565
if self.options.hash_output:
566566
if hash_match:
567567
old_hash = hash_match["hash"]

cogapp/test_cogapp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,15 +2314,15 @@ def test_create_checksum_output(self):
23142314
cog.outl("This line was generated.")
23152315
//]]]
23162316
This line was generated.
2317-
//[[[end]]]
2317+
//[[[end]]] what
23182318
This line was not.
23192319
""",
23202320
"cog1.out": """\
23212321
//[[[cog
23222322
cog.outl("This line was generated.")
23232323
//]]]
23242324
This line was generated.
2325-
//[[[end]]] (checksum: 8adb13fb59b996a1c7f0065ea9f3d893)
2325+
//[[[end]]] (checksum: 8adb13fb59b996a1c7f0065ea9f3d893) what
23262326
This line was not.
23272327
""",
23282328
}
@@ -2340,7 +2340,7 @@ def test_check_checksum_output(self):
23402340
cog.outl("blah blah.")
23412341
//]]]
23422342
This line was generated.
2343-
//[[[end]]] (checksum: 8adb13fb59b996a1c7f0065ea9f3d893)
2343+
//[[[end]]] (checksum: 8adb13fb59b996a1c7f0065ea9f3d893) end
23442344
""",
23452345
"cog1.out": """\
23462346
//[[[cog
@@ -2351,7 +2351,7 @@ def test_check_checksum_output(self):
23512351
This line was newly
23522352
generated by cog
23532353
blah blah.
2354-
//[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346)
2354+
//[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346) end
23552355
""",
23562356
}
23572357

0 commit comments

Comments
 (0)