diff options
| author | Sebastian Thiel <byronimo@gmail.com> | 2014-11-13 18:46:49 +0100 |
|---|---|---|
| committer | Sebastian Thiel <byronimo@gmail.com> | 2014-11-13 18:46:49 +0100 |
| commit | 8ae4e9579a263684c6b760aec2869be480ff22ba (patch) | |
| tree | f0f3344ffb385a6d3202087a5cdebb7589792e37 | |
| parent | 641b64c9f48139cf06774805d32892012fb9b82d (diff) | |
| download | gitdb-8ae4e9579a263684c6b760aec2869be480ff22ba.tar.gz | |
reduced usage of force_bytes as clients are expected to pass bytes.
It was useful for debugging though, maybe an explicit type assertions would
help others ?
As 'others' will be gitpython, I suppose I can handle it myself
| -rw-r--r-- | gitdb/stream.py | 6 | ||||
| -rw-r--r-- | gitdb/test/db/lib.py | 7 | ||||
| -rw-r--r-- | gitdb/test/db/test_ref.py | 8 | ||||
| -rw-r--r-- | gitdb/utils/encoding.py | 6 |
4 files changed, 10 insertions, 17 deletions
diff --git a/gitdb/stream.py b/gitdb/stream.py index 43aa8e3..e32fcf3 100644 --- a/gitdb/stream.py +++ b/gitdb/stream.py @@ -543,9 +543,9 @@ class Sha1Writer(object): def write(self, data): """:raise IOError: If not all bytes could be written + :param data: byte object :return: length of incoming data""" - data = force_bytes(data) self.sha1.update(data) return len(data) @@ -590,8 +590,6 @@ class ZippedStoreShaWriter(Sha1Writer): return getattr(self.buf, attr) def write(self, data): - data = force_bytes(data) - alen = Sha1Writer.write(self, data) self.buf.write(self.zip.compress(data)) @@ -634,8 +632,6 @@ class FDCompressedSha1Writer(Sha1Writer): def write(self, data): """:raise IOError: If not all bytes could be written :return: lenght of incoming data""" - data = force_bytes(data) - self.sha1.update(data) cdata = self.zip.compress(data) bytes_written = write(self.fd, cdata) diff --git a/gitdb/test/db/lib.py b/gitdb/test/db/lib.py index 962d4bc..af6d9e0 100644 --- a/gitdb/test/db/lib.py +++ b/gitdb/test/db/lib.py @@ -23,7 +23,6 @@ from gitdb.base import ( from gitdb.exc import BadObject from gitdb.typ import str_blob_type -from gitdb.utils.encoding import force_bytes from gitdb.utils.compat import xrange from io import BytesIO @@ -37,7 +36,7 @@ class TestDBBase(TestBase): """Base class providing testing routines on databases""" # data - two_lines = "1234\nhello world" + two_lines = b'1234\nhello world' all_data = (two_lines, ) def _assert_object_writing_simple(self, db): @@ -83,7 +82,7 @@ class TestDBBase(TestBase): prev_ostream = db.set_ostream(ostream) assert type(prev_ostream) in ostreams or prev_ostream in ostreams - istream = IStream(str_blob_type, len(data), BytesIO(data.encode("ascii"))) + istream = IStream(str_blob_type, len(data), BytesIO(data)) # store returns same istream instance, with new sha set my_istream = db.store(istream) @@ -99,7 +98,7 @@ class TestDBBase(TestBase): assert info.size == len(data) ostream = db.stream(sha) - assert ostream.read() == force_bytes(data) + assert ostream.read() == data assert ostream.type == str_blob_type assert ostream.size == len(data) else: diff --git a/gitdb/test/db/test_ref.py b/gitdb/test/db/test_ref.py index a1387ee..db93082 100644 --- a/gitdb/test/db/test_ref.py +++ b/gitdb/test/db/test_ref.py @@ -2,7 +2,11 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from gitdb.test.db.lib import * +from gitdb.test.db.lib import ( + TestDBBase, + with_rw_directory, + fixture_path +) from gitdb.db import ReferenceDB from gitdb.util import ( @@ -24,8 +28,6 @@ class TestReferenceDB(TestDBBase): @with_rw_directory def test_writing(self, path): - NULL_BIN_SHA = '\0'.encode("ascii") * 20 - alt_path = os.path.join(path, 'alternates') rdb = ReferenceDB(alt_path) assert len(rdb.databases()) == 0 diff --git a/gitdb/utils/encoding.py b/gitdb/utils/encoding.py index 617b51c..2d03ad3 100644 --- a/gitdb/utils/encoding.py +++ b/gitdb/utils/encoding.py @@ -7,7 +7,7 @@ else: string_types = (basestring, ) text_type = unicode -def force_bytes(data, encoding="utf-8"): +def force_bytes(data, encoding="ascii"): if isinstance(data, bytes): return data @@ -23,10 +23,6 @@ def force_text(data, encoding="utf-8"): if isinstance(data, string_types): return data.decode(encoding) - if not isinstance(data, bytes): - assert False, "Shouldn't be here" - data = force_bytes(data, encoding) - if compat.PY3: return text_type(data, encoding) else: |
