python3 compatibility

fixed unicode/byte string issues for python3
This commit is contained in:
Nico von Geyso 2012-05-15 11:24:03 +02:00
parent 632750565b
commit c04ba3ac2b
2 changed files with 6 additions and 7 deletions

@ -38,7 +38,7 @@ from . import utils
__author__ = 'dborowitz@google.com (Dave Borowitz)'
BLOB_SHA = 'af431f20fc541ed6d5afede3e2dc7160f6f01f16'
BLOB_NEW_CONTENT = 'foo bar\n'
BLOB_NEW_CONTENT = b'foo bar\n'
class BlobTest(utils.BareRepoTestCase):
@ -67,7 +67,7 @@ class BlobTest(utils.BareRepoTestCase):
)
self.assertEqual(BLOB_NEW_CONTENT, blob.data)
self.assertEqual(BLOB_NEW_CONTENT.decode('ascii'), blob.read_raw())
self.assertEqual(BLOB_NEW_CONTENT, blob.read_raw())
if __name__ == '__main__':

@ -52,13 +52,12 @@ def oid_to_hex(oid):
return b2a_hex(oid).decode('ascii')
def gen_blob_sha1(data):
m = hashlib.sha1()
# http://stackoverflow.com/questions/552659/assigning-git-sha1s-without-git
git_sha1_format = 'blob %d\0%s' % (len(data), data)
m.update(git_sha1_format)
m = hashlib.sha1()
m.update(('blob %d\0' % len(data)).encode())
m.update(data)
return m.hexdigest().decode('ascii')
return m.hexdigest()
def rmtree(path):
"""In Windows a read-only file cannot be removed, and shutil.rmtree fails.