| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ Changelog | |||
| 5 | 5 | 0.3.4 - python 3 support | |
| 6 | 6 | ======================== | |
| 7 | 7 | * Internally, hexadecimal SHA1 are treated as ascii encoded strings. Binary SHA1 are treated as bytes. | |
| 8 | + * Id attribute of Commit objects is now `hexsha`, instead of `binsha`. The latter makes no sense in python 3 and I see no application of it anyway besides its artificial usage in test cases. | ||
| 8 | 9 | ||
| 9 | 10 | 0.3.3 | |
| 10 | 11 | ===== | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -320,6 +320,7 @@ def execute(self, command, | |||
| 320 | 320 | always be created with a pipe due to issues with subprocess. | |
| 321 | 321 | This merely is a workaround as data will be copied from the | |
| 322 | 322 | output pipe to the given output stream directly. | |
| 323 | + Judging from the implementation, you shouldn't use this flag ! | ||
| 323 | 324 | ||
| 324 | 325 | :param subprocess_kwargs: | |
| 325 | 326 | Keyword arguments to be passed to subprocess.Popen. Please note that | |
@@ -411,9 +412,13 @@ def execute(self, command, | |||
| 411 | 412 | else: | |
| 412 | 413 | raise GitCommandError(command, status, stderr_value) | |
| 413 | 414 | ||
| 415 | + | ||
| 416 | + if isinstance(stdout_value, bytes): # could also be output_stream | ||
| 417 | + stdout_value = stdout_value.decode(defenc) | ||
| 418 | + | ||
| 414 | 419 | # Allow access to the command's status code | |
| 415 | 420 | if with_extended_output: | |
| 416 | - return (status, stdout_value, stderr_value) | ||
| 421 | + return (status, stdout_value, stderr_value.decode(defenc)) | ||
| 417 | 422 | else: | |
| 418 | 423 | return stdout_value | |
| 419 | 424 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,6 +201,11 @@ def __del__(self): | |||
| 201 | 201 | self.write() | |
| 202 | 202 | except IOError: | |
| 203 | 203 | log.error("Exception during destruction of GitConfigParser", exc_info=True) | |
| 204 | + except ReferenceError: | ||
| 205 | + # This happens in PY3 ... and usually means that some state cannot be written | ||
| 206 | + # as the sections dict cannot be iterated | ||
| 207 | + # Usually when shutting down the interpreter, don'y know how to fix this | ||
| 208 | + pass | ||
| 204 | 209 | finally: | |
| 205 | 210 | self._lock._release_lock() | |
| 206 | 211 | ||
@@ -345,7 +350,7 @@ def write(self): | |||
| 345 | 350 | # END get lock for physical files | |
| 346 | 351 | ||
| 347 | 352 | if not hasattr(fp, "seek"): | |
| 348 | - fp = open(self._file_or_files, "w") | ||
| 353 | + fp = open(self._file_or_files, "wb") | ||
| 349 | 354 | close_fp = True | |
| 350 | 355 | else: | |
| 351 | 356 | fp.seek(0) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -195,7 +195,7 @@ class Diff(object): | |||
| 195 | 195 | """, re.VERBOSE | re.MULTILINE) | |
| 196 | 196 | # can be used for comparisons | |
| 197 | 197 | NULL_HEX_SHA = "0" * 40 | |
| 198 | - NULL_BIN_SHA = "\0" * 20 | ||
| 198 | + NULL_BIN_SHA = b"\0" * 20 | ||
| 199 | 199 | ||
| 200 | 200 | __slots__ = ("a_blob", "b_blob", "a_mode", "b_mode", "new_file", "deleted_file", | |
| 201 | 201 | "rename_from", "rename_to", "diff") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,7 +21,7 @@ class Object(LazyMixin): | |||
| 21 | 21 | ||
| 22 | 22 | """Implements an Object which may be Blobs, Trees, Commits and Tags""" | |
| 23 | 23 | NULL_HEX_SHA = '0' * 40 | |
| 24 | - NULL_BIN_SHA = '\0' * 20 | ||
| 24 | + NULL_BIN_SHA = b'\0' * 20 | ||
| 25 | 25 | ||
| 26 | 26 | TYPES = (dbtyp.str_blob_type, dbtyp.str_tree_type, dbtyp.str_commit_type, dbtyp.str_tag_type) | |
| 27 | 27 | __slots__ = ("repo", "binsha", "size") | |
@@ -94,7 +94,7 @@ def __hash__(self): | |||
| 94 | 94 | ||
| 95 | 95 | def __str__(self): | |
| 96 | 96 | """:return: string of our SHA1 as understood by all git commands""" | |
| 97 | - return bin_to_hex(self.binsha) | ||
| 97 | + return self.hexsha | ||
| 98 | 98 | ||
| 99 | 99 | def __repr__(self): | |
| 100 | 100 | """:return: string with pythonic representation of our object""" | |
@@ -103,7 +103,8 @@ def __repr__(self): | |||
| 103 | 103 | @property | |
| 104 | 104 | def hexsha(self): | |
| 105 | 105 | """:return: 40 byte hex version of our 20 byte binary sha""" | |
| 106 | - return bin_to_hex(self.binsha) | ||
| 106 | + # b2a_hex produces bytes | ||
| 107 | + return bin_to_hex(self.binsha).decode('ascii') | ||
| 107 | 108 | ||
| 108 | 109 | @property | |
| 109 | 110 | def data_stream(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,7 +62,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): | |||
| 62 | 62 | "author", "authored_date", "author_tz_offset", | |
| 63 | 63 | "committer", "committed_date", "committer_tz_offset", | |
| 64 | 64 | "message", "parents", "encoding", "gpgsig") | |
| 65 | - _id_attribute_ = "binsha" | ||
| 65 | + _id_attribute_ = "hexsha" | ||
| 66 | 66 | ||
| 67 | 67 | def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, author_tz_offset=None, | |
| 68 | 68 | committer=None, committed_date=None, committer_tz_offset=None, | |
@@ -395,7 +395,7 @@ def _serialize(self, stream): | |||
| 395 | 395 | write(("encoding %s\n" % self.encoding).encode('ascii')) | |
| 396 | 396 | ||
| 397 | 397 | if self.gpgsig: | |
| 398 | - write("gpgsig") | ||
| 398 | + write(b"gpgsig") | ||
| 399 | 399 | for sigline in self.gpgsig.rstrip("\n").split("\n"): | |
| 400 | 400 | write((" " + sigline + "\n").encode('ascii')) | |
| 401 | 401 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,6 @@ | |||
| 2 | 2 | from stat import S_ISDIR | |
| 3 | 3 | from git.compat import ( | |
| 4 | 4 | byte_ord, | |
| 5 | - force_bytes, | ||
| 6 | 5 | defenc, | |
| 7 | 6 | xrange, | |
| 8 | 7 | text_type | |
@@ -37,7 +36,7 @@ def tree_to_stream(entries, write): | |||
| 37 | 36 | # takes the input literally, which appears to be utf8 on linux. | |
| 38 | 37 | if isinstance(name, text_type): | |
| 39 | 38 | name = name.encode(defenc) | |
| 40 | - write(b''.join(mode_str, b' ', name, b'\0', binsha)) | ||
| 39 | + write(b''.join((mode_str, b' ', name, b'\0', binsha))) | ||
| 41 | 40 | # END for each item | |
| 42 | 41 | ||
| 43 | 42 | def tree_entries_from_data(data): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -308,7 +308,7 @@ def set_reference(self, ref, logmsg=None): | |||
| 308 | 308 | ||
| 309 | 309 | lfd = LockedFD(fpath) | |
| 310 | 310 | fd = lfd.open(write=True, stream=True) | |
| 311 | - fd.write(write_value) | ||
| 311 | + fd.write(write_value.encode('ascii')) | ||
| 312 | 312 | lfd.commit() | |
| 313 | 313 | ||
| 314 | 314 | # Adjust the reflog | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,7 +47,10 @@ | |||
| 47 | 47 | read_gitfile, | |
| 48 | 48 | touch, | |
| 49 | 49 | ) | |
| 50 | - from git.compat import text_type | ||
| 50 | + from git.compat import ( | ||
| 51 | + text_type, | ||
| 52 | + defenc | ||
| 53 | + ) | ||
| 51 | 54 | ||
| 52 | 55 | import os | |
| 53 | 56 | import sys | |
@@ -177,11 +180,11 @@ def __hash__(self): | |||
| 177 | 180 | # Description property | |
| 178 | 181 | def _get_description(self): | |
| 179 | 182 | filename = join(self.git_dir, 'description') | |
| 180 | - return open(filename).read().rstrip() | ||
| 183 | + return open(filename, 'rb').read().rstrip().decode(defenc) | ||
| 181 | 184 | ||
| 182 | 185 | def _set_description(self, descr): | |
| 183 | 186 | filename = join(self.git_dir, 'description') | |
| 184 | - open(filename, 'w').write(descr + '\n') | ||
| 187 | + open(filename, 'wb').write((descr + '\n').encode(defenc)) | ||
| 185 | 188 | ||
| 186 | 189 | description = property(_get_description, _set_description, | |
| 187 | 190 | doc="the project's description") | |
@@ -464,8 +467,8 @@ def _get_alternates(self): | |||
| 464 | 467 | ||
| 465 | 468 | if os.path.exists(alternates_path): | |
| 466 | 469 | try: | |
| 467 | - f = open(alternates_path) | ||
| 468 | - alts = f.read() | ||
| 470 | + f = open(alternates_path, 'rb') | ||
| 471 | + alts = f.read().decode(defenc) | ||
| 469 | 472 | finally: | |
| 470 | 473 | f.close() | |
| 471 | 474 | return alts.strip().splitlines() | |
@@ -489,8 +492,8 @@ def _set_alternates(self, alts): | |||
| 489 | 492 | os.remove(alternates_path) | |
| 490 | 493 | else: | |
| 491 | 494 | try: | |
| 492 | - f = open(alternates_path, 'w') | ||
| 493 | - f.write("\n".join(alts)) | ||
| 495 | + f = open(alternates_path, 'wb') | ||
| 496 | + f.write("\n".join(alts).encode(defenc)) | ||
| 494 | 497 | finally: | |
| 495 | 498 | f.close() | |
| 496 | 499 | # END file handling | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,7 @@ def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False) | |||
| 51 | 51 | stream.seek(0) | |
| 52 | 52 | ||
| 53 | 53 | istream = rwrepo.odb.store(IStream(Commit.type, streamlen, stream)) | |
| 54 | - assert istream.hexsha == cm.hexsha | ||
| 54 | + assert istream.hexsha == cm.hexsha.encode('ascii') | ||
| 55 | 55 | ||
| 56 | 56 | nc = Commit(rwrepo, Commit.NULL_BIN_SHA, cm.tree, | |
| 57 | 57 | cm.author, cm.authored_date, cm.author_tz_offset, | |
@@ -129,7 +129,7 @@ def check_entries(d): | |||
| 129 | 129 | ||
| 130 | 130 | def test_unicode_actor(self): | |
| 131 | 131 | # assure we can parse unicode actors correctly | |
| 132 | - name = "Üäöß ÄußÉ".decode("utf-8") | ||
| 132 | + name = u"Üäöß ÄußÉ" | ||
| 133 | 133 | assert len(name) == 9 | |
| 134 | 134 | special = Actor._from_string(u"%s <something@this.com>" % name) | |
| 135 | 135 | assert special.name == name | |
@@ -146,13 +146,13 @@ def test_traversal(self): | |||
| 146 | 146 | # basic branch first, depth first | |
| 147 | 147 | dfirst = start.traverse(branch_first=False) | |
| 148 | 148 | bfirst = start.traverse(branch_first=True) | |
| 149 | - assert dfirst.next() == p0 | ||
| 150 | - assert dfirst.next() == p00 | ||
| 149 | + assert next(dfirst) == p0 | ||
| 150 | + assert next(dfirst) == p00 | ||
| 151 | 151 | ||
| 152 | - assert bfirst.next() == p0 | ||
| 153 | - assert bfirst.next() == p1 | ||
| 154 | - assert bfirst.next() == p00 | ||
| 155 | - assert bfirst.next() == p10 | ||
| 152 | + assert next(bfirst) == p0 | ||
| 153 | + assert next(bfirst) == p1 | ||
| 154 | + assert next(bfirst) == p00 | ||
| 155 | + assert next(bfirst) == p10 | ||
| 156 | 156 | ||
| 157 | 157 | # at some point, both iterations should stop | |
| 158 | 158 | assert list(bfirst)[-1] == first | |
@@ -161,19 +161,19 @@ def test_traversal(self): | |||
| 161 | 161 | assert len(l[0]) == 2 | |
| 162 | 162 | ||
| 163 | 163 | # ignore self | |
| 164 | - assert start.traverse(ignore_self=False).next() == start | ||
| 164 | + assert next(start.traverse(ignore_self=False)) == start | ||
| 165 | 165 | ||
| 166 | 166 | # depth | |
| 167 | 167 | assert len(list(start.traverse(ignore_self=False, depth=0))) == 1 | |
| 168 | 168 | ||
| 169 | 169 | # prune | |
| 170 | - assert start.traverse(branch_first=1, prune=lambda i, d: i == p0).next() == p1 | ||
| 170 | + assert next(start.traverse(branch_first=1, prune=lambda i, d: i == p0)) == p1 | ||
| 171 | 171 | ||
| 172 | 172 | # predicate | |
| 173 | - assert start.traverse(branch_first=1, predicate=lambda i, d: i == p1).next() == p1 | ||
| 173 | + assert next(start.traverse(branch_first=1, predicate=lambda i, d: i == p1)) == p1 | ||
| 174 | 174 | ||
| 175 | 175 | # traversal should stop when the beginning is reached | |
| 176 | - self.failUnlessRaises(StopIteration, first.traverse().next) | ||
| 176 | + self.failUnlessRaises(StopIteration, next, first.traverse()) | ||
| 177 | 177 | ||
| 178 | 178 | # parents of the first commit should be empty ( as the only parent has a null | |
| 179 | 179 | # sha ) | |
@@ -210,7 +210,7 @@ def test_rev_list_bisect_all(self): | |||
| 210 | 210 | first_parent=True, | |
| 211 | 211 | bisect_all=True) | |
| 212 | 212 | ||
| 213 | - commits = Commit._iter_from_process_or_stream(self.rorepo, StringProcessAdapter(revs)) | ||
| 213 | + commits = Commit._iter_from_process_or_stream(self.rorepo, StringProcessAdapter(revs.encode('ascii'))) | ||
| 214 | 214 | expected_ids = ( | |
| 215 | 215 | '7156cece3c49544abb6bf7a0c218eb36646fad6d', | |
| 216 | 216 | '1f66cfbbce58b4b552b041707a12d437cc5f400a', | |
@@ -224,8 +224,10 @@ def test_count(self): | |||
| 224 | 224 | assert self.rorepo.tag('refs/tags/0.1.5').commit.count() == 143 | |
| 225 | 225 | ||
| 226 | 226 | def test_list(self): | |
| 227 | + # This doesn't work anymore, as we will either attempt getattr with bytes, or compare 20 byte string | ||
| 228 | + # with actual 20 byte bytes. This usage makes no sense anyway | ||
| 227 | 229 | assert isinstance(Commit.list_items(self.rorepo, '0.1.5', max_count=5)[ | |
| 228 | - hex_to_bin('5117c9c8a4d3af19a9958677e45cda9269de1541')], Commit) | ||
| 230 | + '5117c9c8a4d3af19a9958677e45cda9269de1541'], Commit) | ||
| 229 | 231 | ||
| 230 | 232 | def test_str(self): | |
| 231 | 233 | commit = Commit(self.rorepo, Commit.NULL_BIN_SHA) | |
@@ -247,12 +249,12 @@ def test_iter_parents(self): | |||
| 247 | 249 | c = self.rorepo.commit('0.1.5') | |
| 248 | 250 | for skip in (0, 1): | |
| 249 | 251 | piter = c.iter_parents(skip=skip) | |
| 250 | - first_parent = piter.next() | ||
| 252 | + first_parent = next(piter) | ||
| 251 | 253 | assert first_parent != c | |
| 252 | 254 | assert first_parent == c.parents[0] | |
| 253 | 255 | # END for each | |
| 254 | 256 | ||
| 255 | - def test_base(self): | ||
| 257 | + def test_name_rev(self): | ||
| 256 | 258 | name_rev = self.rorepo.head.commit.name_rev | |
| 257 | 259 | assert isinstance(name_rev, string_types) | |
| 258 | 260 | ||
@@ -270,10 +272,10 @@ def test_serialization_unicode_support(self): | |||
| 270 | 272 | assert isinstance(cmt.message, text_type) # it automatically decodes it as such | |
| 271 | 273 | assert isinstance(cmt.author.name, text_type) # same here | |
| 272 | 274 | ||
| 273 | - cmt.message = "üäêèß".decode("utf-8") | ||
| 275 | + cmt.message = u"üäêèß" | ||
| 274 | 276 | assert len(cmt.message) == 5 | |
| 275 | 277 | ||
| 276 | - cmt.author.name = "äüß".decode("utf-8") | ||
| 278 | + cmt.author.name = u"äüß" | ||
| 277 | 279 | assert len(cmt.author.name) == 3 | |
| 278 | 280 | ||
| 279 | 281 | cstream = BytesIO() | |
@@ -292,7 +294,7 @@ def test_serialization_unicode_support(self): | |||
| 292 | 294 | ||
| 293 | 295 | def test_gpgsig(self): | |
| 294 | 296 | cmt = self.rorepo.commit() | |
| 295 | - cmt._deserialize(open(fixture_path('commit_with_gpgsig'))) | ||
| 297 | + cmt._deserialize(open(fixture_path('commit_with_gpgsig'), 'rb')) | ||
| 296 | 298 | ||
| 297 | 299 | fixture_sig = """-----BEGIN PGP SIGNATURE----- | |
| 298 | 300 | Version: GnuPG v1.4.11 (GNU/Linux) | |
@@ -318,7 +320,7 @@ def test_gpgsig(self): | |||
| 318 | 320 | ||
| 319 | 321 | cstream = BytesIO() | |
| 320 | 322 | cmt._serialize(cstream) | |
| 321 | - assert re.search(r"^gpgsig <test\n dummy\n sig>$", cstream.getvalue(), re.MULTILINE) | ||
| 323 | + assert re.search(r"^gpgsig <test\n dummy\n sig>$", cstream.getvalue().decode('ascii'), re.MULTILINE) | ||
| 322 | 324 | ||
| 323 | 325 | cstream.seek(0) | |
| 324 | 326 | cmt.gpgsig = None | |
@@ -328,4 +330,4 @@ def test_gpgsig(self): | |||
| 328 | 330 | cmt.gpgsig = None | |
| 329 | 331 | cstream = BytesIO() | |
| 330 | 332 | cmt._serialize(cstream) | |
| 331 | - assert not re.search(r"^gpgsig ", cstream.getvalue(), re.MULTILINE) | ||
| 333 | + assert not re.search(r"^gpgsig ", cstream.getvalue().decode('ascii'), re.MULTILINE) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments