Python 3.6 compatibility: bytes vs strings stuff

These changes mostly revolve around the change in ObjectId constructor
when running on Python 3.6. Where on 2.7 the constructor would accept
12- and 24-byte strings, now only 12-byte bytes and 24-character strings
are accepted. Good thing, but required some changes in our code.

Other changes include hashing of strings, which isn't supported, so they
are converted to bytes first, and sometimes converted back afterwards.
This commit is contained in:
2017-03-03 14:14:36 +01:00
parent 6fb58a3f26
commit a9e40ccf10
12 changed files with 62 additions and 46 deletions

View File

@@ -15,12 +15,12 @@ class IsValidIdTest(unittest.TestCase):
self.assertTrue(utils.is_valid_id('deadbeefbeefcacedeadcace'))
self.assertTrue(utils.is_valid_id('deadbeefbeefcacedeadcace'))
# 12-byte arbitrary ASCII strings
self.assertTrue(utils.is_valid_id('DeadBeefCake'))
self.assertTrue(utils.is_valid_id('DeadBeefCake'))
# 12-byte arbitrary ASCII bytes
self.assertTrue(utils.is_valid_id(b'DeadBeefCake'))
self.assertTrue(utils.is_valid_id(b'DeadBeefCake'))
# 12-byte str object
self.assertTrue(utils.is_valid_id('beef€67890'))
# 12-byte object
self.assertTrue(utils.is_valid_id('beef€67890'.encode()))
def test_bad_length(self):
self.assertFalse(utils.is_valid_id(23 * 'a'))