summaryrefslogtreecommitdiff
path: root/fastimport/helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'fastimport/helpers.py')
-rw-r--r--fastimport/helpers.py47
1 files changed, 17 insertions, 30 deletions
diff --git a/fastimport/helpers.py b/fastimport/helpers.py
index 67072be..b1451f7 100644
--- a/fastimport/helpers.py
+++ b/fastimport/helpers.py
@@ -14,20 +14,22 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Miscellaneous useful stuff."""
-import sys
def _common_path_and_rest(l1, l2, common=[]):
# From http://code.activestate.com/recipes/208993/
- if len(l1) < 1: return (common, l1, l2)
- if len(l2) < 1: return (common, l1, l2)
- if l1[0] != l2[0]: return (common, l1, l2)
+ if len(l1) < 1:
+ return (common, l1, l2)
+ if len(l2) < 1:
+ return (common, l1, l2)
+ if l1[0] != l2[0]:
+ return (common, l1, l2)
return _common_path_and_rest(
l1[1:],
l2[1:],
common + [
- l1[0:1] # return a byte string in python 3 unlike l1[0] that
- # would return an integer.
+ l1[0:1] # return a byte string in python 3 unlike l1[0] that
+ # would return an integer.
]
)
@@ -45,6 +47,7 @@ def common_directory(paths):
otherwise the common directory with a trailing / is returned.
"""
import posixpath
+
def get_dir_with_slash(path):
if path == b'' or path.endswith(b'/'):
return path
@@ -100,24 +103,10 @@ def is_inside_any(dir_list, fname):
def utf8_bytes_string(s):
"""Convert a string to a bytes string (if necessary, encode in utf8)"""
- if sys.version_info[0] == 2:
- if isinstance(s, str):
- return s
- else:
- return s.encode('utf8')
+ if isinstance(s, str):
+ return bytes(s, encoding='utf8')
else:
- if isinstance(s, str):
- return bytes(s, encoding='utf8')
- else:
- return s
-
-
-def repr_bytes(obj):
- """Return a bytes representation of the object"""
- if sys.version_info[0] == 2:
- return repr(obj)
- else:
- return bytes(obj)
+ return s
class newobject(object):
@@ -145,7 +134,7 @@ class newobject(object):
s = type(self).__str__(self)
else:
s = str(self)
- if isinstance(s, unicode):
+ if isinstance(s, unicode): # noqa: F821
return s
else:
return s.decode('utf-8')
@@ -177,8 +166,9 @@ class newobject(object):
# d = {}
# for k, v in iterable:
# d[k] = v
- # dict(**kwargs) -> new dictionary initialized with the name=value pairs
- # in the keyword argument list. For example: dict(one=1, two=2)
+ # dict(**kwargs) -> new dictionary initialized with the name=value
+ # pairs in the keyword argument list.
+ # For example: dict(one=1, two=2)
# """
# if len(args) == 0:
@@ -216,7 +206,7 @@ def binary_stream(stream):
def invert_dictset(d):
- """Invert a dictionary with keys matching a set of values, turned into lists."""
+ """Invert a dict with keys matching a set of values, turned into lists."""
# Based on recipe from ASPN
result = {}
for k, c in d.items():
@@ -260,6 +250,3 @@ def get_source_stream(source):
else:
stream = open(source, "rb")
return stream
-
-
-