Blame 6109ad5a54359262010d01f2e0175d928bd70962.patch

1cb78d1
From 6109ad5a54359262010d01f2e0175d928bd70962 Mon Sep 17 00:00:00 2001
1cb78d1
From: Alex DeJarnatt <adejarnatt@gmail.com>
1cb78d1
Date: Fri, 7 Jun 2019 11:16:50 -0400
1cb78d1
Subject: [PATCH] Fix Issue #21
1cb78d1
1cb78d1
---
1cb78d1
 puz.py   | 9 ++++++---
1cb78d1
 tests.py | 4 ++++
1cb78d1
 2 files changed, 10 insertions(+), 3 deletions(-)
1cb78d1
1cb78d1
diff --git a/puz.py b/puz.py
1cb78d1
index 99a6a71..bbe32a4 100644
1cb78d1
--- a/puz.py
1cb78d1
+++ b/puz.py
1cb78d1
@@ -282,6 +282,9 @@ def tobytes(self):
1cb78d1
 
1cb78d1
         return s.tobytes()
1cb78d1
 
1cb78d1
+    def version_tuple(self):
1cb78d1
+      return tuple(map(int, self.version.decode(ENCODING).split('.')))
1cb78d1
+
1cb78d1
     def has_rebus(self):
1cb78d1
         return self.rebus().has_rebus()
1cb78d1
 
1cb78d1
@@ -341,7 +344,7 @@ def header_cksum(self, cksum=0):
1cb78d1
     def text_cksum(self, cksum=0):
1cb78d1
         # for the checksum to work these fields must be added in order with
1cb78d1
         # null termination, followed by all non-empty clues without null
1cb78d1
-        # termination, followed by notes (but only for version 1.3)
1cb78d1
+        # termination, followed by notes (but only for version >= 1.3)
1cb78d1
         if self.title:
1cb78d1
             cksum = data_cksum(self.title.encode(ENCODING) + b'\0', cksum)
1cb78d1
         if self.author:
1cb78d1
@@ -353,8 +356,8 @@ def text_cksum(self, cksum=0):
1cb78d1
             if clue:
1cb78d1
                 cksum = data_cksum(clue.encode(ENCODING), cksum)
1cb78d1
 
1cb78d1
-        # notes included in global cksum only in v1.3 of format
1cb78d1
-        if self.version.decode(ENCODING) == '1.3' and self.notes:
1cb78d1
+        # notes included in global cksum starting v1.3 of format
1cb78d1
+        if self.version_tuple() >= (1,3) and self.notes:
1cb78d1
             cksum = data_cksum(self.notes.encode(ENCODING) + b'\0', cksum)
1cb78d1
 
1cb78d1
         return cksum
1cb78d1
diff --git a/tests.py b/tests.py
1cb78d1
index e5862e8..8c00a77 100755
1cb78d1
--- a/tests.py
1cb78d1
+++ b/tests.py
1cb78d1
@@ -73,6 +73,10 @@ def test_junk_at_end_of_puzzle(self):
1cb78d1
         p.load(data)
1cb78d1
         self.assertEqual(p.postscript, b'\r\n\r\n')
1cb78d1
 
1cb78d1
+    def test_v1_4(self):
1cb78d1
+      p = puz.read('testfiles/nyt_v1_4.puz')
1cb78d1
+      p.tobytes()
1cb78d1
+
1cb78d1
     def test_save_empty_puzzle(self):
1cb78d1
         ''' confirm an empty Puzzle() can be saved to a file '''
1cb78d1
         p = puz.Puzzle()