| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,7 @@ | |||
| 19 | 19 | stream_copy | |
| 20 | 20 | ) | |
| 21 | 21 | from .exc import GitCommandError | |
| 22 | - | ||
| 22 | + from git.compat import text_type | ||
| 23 | 23 | ||
| 24 | 24 | execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output', | |
| 25 | 25 | 'with_exceptions', 'as_process', | |
@@ -435,15 +435,15 @@ def transform_kwargs(self, split_single_char_options=False, **kwargs): | |||
| 435 | 435 | @classmethod | |
| 436 | 436 | def __unpack_args(cls, arg_list): | |
| 437 | 437 | if not isinstance(arg_list, (list, tuple)): | |
| 438 | - if isinstance(arg_list, unicode): | ||
| 438 | + if isinstance(arg_list, text_type): | ||
| 439 | 439 | return [arg_list.encode('utf-8')] | |
| 440 | 440 | return [str(arg_list)] | |
| 441 | 441 | ||
| 442 | 442 | outlist = list() | |
| 443 | 443 | for arg in arg_list: | |
| 444 | 444 | if isinstance(arg_list, (list, tuple)): | |
| 445 | 445 | outlist.extend(cls.__unpack_args(arg)) | |
| 446 | - elif isinstance(arg_list, unicode): | ||
| 446 | + elif isinstance(arg_list, text_type): | ||
| 447 | 447 | outlist.append(arg_list.encode('utf-8')) | |
| 448 | 448 | # END recursion | |
| 449 | 449 | else: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,15 +5,22 @@ | |||
| 5 | 5 | # This module is part of GitPython and is released under | |
| 6 | 6 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php | |
| 7 | 7 | """utilities to help provide compatibility with python 3""" | |
| 8 | + # flake8: noqa | ||
| 8 | 9 | ||
| 9 | - from gitdb.utils.compat import ( # noqa | ||
| 10 | + from gitdb.utils.compat import ( | ||
| 10 | 11 | PY3, | |
| 11 | 12 | xrange, | |
| 12 | 13 | MAXSIZE, | |
| 13 | 14 | izip, | |
| 14 | 15 | ) | |
| 15 | 16 | ||
| 16 | - from gitdb.utils.encoding import ( # noqa | ||
| 17 | + from gitdb.utils.encoding import ( | ||
| 17 | 18 | string_types, | |
| 18 | 19 | text_type | |
| 19 | 20 | ) | |
| 21 | + | ||
| 22 | + if PY3: | ||
| 23 | + import io | ||
| 24 | + FileType = io.IOBase | ||
| 25 | + else: | ||
| 26 | + FileType = file | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,10 @@ | |||
| 17 | 17 | ||
| 18 | 18 | from git.odict import OrderedDict | |
| 19 | 19 | from git.util import LockFile | |
| 20 | + from git.compat import ( | ||
| 21 | + string_types, | ||
| 22 | + FileType | ||
| 23 | + ) | ||
| 20 | 24 | ||
| 21 | 25 | __all__ = ('GitConfigParser', 'SectionConstraint') | |
| 22 | 26 | ||
@@ -175,7 +179,7 @@ def __init__(self, file_or_files, read_only=True): | |||
| 175 | 179 | "Write-ConfigParsers can operate on a single file only, multiple files have been passed") | |
| 176 | 180 | # END single file check | |
| 177 | 181 | ||
| 178 | - if not isinstance(file_or_files, basestring): | ||
| 182 | + if not isinstance(file_or_files, string_types): | ||
| 179 | 183 | file_or_files = file_or_files.name | |
| 180 | 184 | # END get filename from handle/stream | |
| 181 | 185 | # initialize lock base - we want to write | |
@@ -333,7 +337,7 @@ def write(self): | |||
| 333 | 337 | close_fp = False | |
| 334 | 338 | ||
| 335 | 339 | # we have a physical file on disk, so get a lock | |
| 336 | - if isinstance(fp, (basestring, file)): | ||
| 340 | + if isinstance(fp, string_types + (FileType, )): | ||
| 337 | 341 | self._lock._obtain_lock() | |
| 338 | 342 | # END get lock for physical files | |
| 339 | 343 | ||
@@ -391,7 +395,7 @@ def get_value(self, section, option, default=None): | |||
| 391 | 395 | return default | |
| 392 | 396 | raise | |
| 393 | 397 | ||
| 394 | - types = (long, float) | ||
| 398 | + types = (int, float) | ||
| 395 | 399 | for numtype in types: | |
| 396 | 400 | try: | |
| 397 | 401 | val = numtype(valuestr) | |
@@ -412,7 +416,7 @@ def get_value(self, section, option, default=None): | |||
| 412 | 416 | if vl == 'true': | |
| 413 | 417 | return True | |
| 414 | 418 | ||
| 415 | - if not isinstance(valuestr, basestring): | ||
| 419 | + if not isinstance(valuestr, string_types): | ||
| 416 | 420 | raise TypeError("Invalid value type: only int, long, float and str are allowed", valuestr) | |
| 417 | 421 | ||
| 418 | 422 | return valuestr | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,7 +39,11 @@ | |||
| 39 | 39 | ) | |
| 40 | 40 | ||
| 41 | 41 | from git.objects.util import Serializable | |
| 42 | - from git.compat import izip | ||
| 42 | + from git.compat import ( | ||
| 43 | + izip, | ||
| 44 | + xrange, | ||
| 45 | + string_types, | ||
| 46 | + ) | ||
| 43 | 47 | ||
| 44 | 48 | from git.util import ( | |
| 45 | 49 | LazyMixin, | |
@@ -541,7 +545,7 @@ def _preprocess_add_items(self, items): | |||
| 541 | 545 | entries = list() | |
| 542 | 546 | ||
| 543 | 547 | for item in items: | |
| 544 | - if isinstance(item, basestring): | ||
| 548 | + if isinstance(item, string_types): | ||
| 545 | 549 | paths.append(self._to_relative_path(item)) | |
| 546 | 550 | elif isinstance(item, (Blob, Submodule)): | |
| 547 | 551 | entries.append(BaseIndexEntry.from_blob(item)) | |
@@ -752,7 +756,7 @@ def _items_to_rela_paths(self, items): | |||
| 752 | 756 | for item in items: | |
| 753 | 757 | if isinstance(item, (BaseIndexEntry, (Blob, Submodule))): | |
| 754 | 758 | paths.append(self._to_relative_path(item.path)) | |
| 755 | - elif isinstance(item, basestring): | ||
| 759 | + elif isinstance(item, string_types): | ||
| 756 | 760 | paths.append(self._to_relative_path(item)) | |
| 757 | 761 | else: | |
| 758 | 762 | raise TypeError("Invalid item type: %r" % item) | |
@@ -1004,7 +1008,7 @@ def handle_stderr(proc, iter_checked_out_files): | |||
| 1004 | 1008 | handle_stderr(proc, rval_iter) | |
| 1005 | 1009 | return rval_iter | |
| 1006 | 1010 | else: | |
| 1007 | - if isinstance(paths, basestring): | ||
| 1011 | + if isinstance(paths, string_types): | ||
| 1008 | 1012 | paths = [paths] | |
| 1009 | 1013 | ||
| 1010 | 1014 | # make sure we have our entries loaded before we start checkout_index | |
@@ -1140,7 +1144,7 @@ def diff(self, other=diff.Diffable.Index, paths=None, create_patch=False, **kwar | |||
| 1140 | 1144 | # index against anything but None is a reverse diff with the respective | |
| 1141 | 1145 | # item. Handle existing -R flags properly. Transform strings to the object | |
| 1142 | 1146 | # so that we can call diff on it | |
| 1143 | - if isinstance(other, basestring): | ||
| 1147 | + if isinstance(other, string_types): | ||
| 1144 | 1148 | other = self.repo.rev_parse(other) | |
| 1145 | 1149 | # END object conversion | |
| 1146 | 1150 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ | |||
| 23 | 23 | altz_to_utctz_str, | |
| 24 | 24 | parse_actor_and_date | |
| 25 | 25 | ) | |
| 26 | + from git.compat import text_type | ||
| 26 | 27 | ||
| 27 | 28 | from time import ( | |
| 28 | 29 | time, | |
@@ -378,7 +379,7 @@ def _serialize(self, stream): | |||
| 378 | 379 | ||
| 379 | 380 | a = self.author | |
| 380 | 381 | aname = a.name | |
| 381 | - if isinstance(aname, unicode): | ||
| 382 | + if isinstance(aname, text_type): | ||
| 382 | 383 | aname = aname.encode(self.encoding) | |
| 383 | 384 | # END handle unicode in name | |
| 384 | 385 | ||
@@ -390,7 +391,7 @@ def _serialize(self, stream): | |||
| 390 | 391 | ||
| 391 | 392 | # encode committer | |
| 392 | 393 | aname = c.name | |
| 393 | - if isinstance(aname, unicode): | ||
| 394 | + if isinstance(aname, text_type): | ||
| 394 | 395 | aname = aname.encode(self.encoding) | |
| 395 | 396 | # END handle unicode in name | |
| 396 | 397 | write(fmt % ("committer", aname, c.email, | |
@@ -408,7 +409,7 @@ def _serialize(self, stream): | |||
| 408 | 409 | write("\n") | |
| 409 | 410 | ||
| 410 | 411 | # write plain bytes, be sure its encoded according to our encoding | |
| 411 | - if isinstance(self.message, unicode): | ||
| 412 | + if isinstance(self.message, text_type): | ||
| 412 | 413 | write(self.message.encode(self.encoding)) | |
| 413 | 414 | else: | |
| 414 | 415 | write(self.message) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,9 @@ | |||
| 1 | 1 | """Module with functions which are supposed to be as fast as possible""" | |
| 2 | 2 | from stat import S_ISDIR | |
| 3 | + from git.compat import ( | ||
| 4 | + xrange, | ||
| 5 | + text_type | ||
| 6 | + ) | ||
| 3 | 7 | ||
| 4 | 8 | __all__ = ('tree_to_stream', 'tree_entries_from_data', 'traverse_trees_recursive', | |
| 5 | 9 | 'traverse_tree_recursive') | |
@@ -28,7 +32,7 @@ def tree_to_stream(entries, write): | |||
| 28 | 32 | # hence we must convert to an utf8 string for it to work properly. | |
| 29 | 33 | # According to my tests, this is exactly what git does, that is it just | |
| 30 | 34 | # takes the input literally, which appears to be utf8 on linux. | |
| 31 | - if isinstance(name, unicode): | ||
| 35 | + if isinstance(name, text_type): | ||
| 32 | 36 | name = name.encode("utf8") | |
| 33 | 37 | write("%s %s\0%s" % (mode_str, name, binsha)) | |
| 34 | 38 | # END for each item | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ | |||
| 22 | 22 | InvalidGitRepositoryError, | |
| 23 | 23 | NoSuchPathError | |
| 24 | 24 | ) | |
| 25 | + from git.compat import string_types | ||
| 25 | 26 | ||
| 26 | 27 | import stat | |
| 27 | 28 | import git | |
@@ -93,7 +94,7 @@ def __init__(self, repo, binsha, mode=None, path=None, name=None, parent_commit= | |||
| 93 | 94 | if url is not None: | |
| 94 | 95 | self._url = url | |
| 95 | 96 | if branch_path is not None: | |
| 96 | - assert isinstance(branch_path, basestring) | ||
| 97 | + assert isinstance(branch_path, string_types) | ||
| 97 | 98 | self._branch_path = branch_path | |
| 98 | 99 | if name is not None: | |
| 99 | 100 | self._name = name | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ | |||
| 11 | 11 | from .base import IndexObject | |
| 12 | 12 | from .blob import Blob | |
| 13 | 13 | from .submodule.base import Submodule | |
| 14 | + from git.compat import string_types | ||
| 14 | 15 | ||
| 15 | 16 | from .fun import ( | |
| 16 | 17 | tree_entries_from_data, | |
@@ -232,7 +233,7 @@ def __getitem__(self, item): | |||
| 232 | 233 | info = self._cache[item] | |
| 233 | 234 | return self._map_id_to_type[info[1] >> 12](self.repo, info[0], info[1], join_path(self.path, info[2])) | |
| 234 | 235 | ||
| 235 | - if isinstance(item, basestring): | ||
| 236 | + if isinstance(item, string_types): | ||
| 236 | 237 | # compatability | |
| 237 | 238 | return self.__div__(item) | |
| 238 | 239 | # END index is basestring | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,10 @@ | |||
| 17 | 17 | Serializable, | |
| 18 | 18 | altz_to_utctz_str, | |
| 19 | 19 | ) | |
| 20 | + from git.compat import ( | ||
| 21 | + xrange, | ||
| 22 | + string_types | ||
| 23 | + ) | ||
| 20 | 24 | ||
| 21 | 25 | import time | |
| 22 | 26 | import re | |
@@ -170,7 +174,7 @@ def iter_entries(cls, stream): | |||
| 170 | 174 | :param stream: file-like object containing the revlog in its native format | |
| 171 | 175 | or basestring instance pointing to a file to read""" | |
| 172 | 176 | new_entry = RefLogEntry.from_line | |
| 173 | - if isinstance(stream, basestring): | ||
| 177 | + if isinstance(stream, string_types): | ||
| 174 | 178 | stream = file_contents_ro_filepath(stream) | |
| 175 | 179 | # END handle stream type | |
| 176 | 180 | while True: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,7 @@ | |||
| 19 | 19 | hex_to_bin, | |
| 20 | 20 | LockedFD | |
| 21 | 21 | ) | |
| 22 | + from git.compat import string_types | ||
| 22 | 23 | ||
| 23 | 24 | from .log import RefLog | |
| 24 | 25 | ||
@@ -274,7 +275,7 @@ def set_reference(self, ref, logmsg=None): | |||
| 274 | 275 | elif isinstance(ref, Object): | |
| 275 | 276 | obj = ref | |
| 276 | 277 | write_value = ref.hexsha | |
| 277 | - elif isinstance(ref, basestring): | ||
| 278 | + elif isinstance(ref, string_types): | ||
| 278 | 279 | try: | |
| 279 | 280 | obj = self.repo.rev_parse(ref + "^{}") # optionally deref tags | |
| 280 | 281 | write_value = obj.hexsha | |
| Back | FazBrowse Home | New Git URL |
0 commit comments