diff options
| author | Mika Mäenpää <mika.j.maenpaa@tut.fi> | 2014-10-13 16:40:09 +0300 |
|---|---|---|
| committer | Mika Mäenpää <mika.j.maenpaa@tut.fi> | 2014-10-14 13:50:33 +0300 |
| commit | 431e4bdf089354534f6877d39631ff23038e8866 (patch) | |
| tree | 9ab369d25c72491e91369cb2bbd45deb3c1599ad /gitlab.py | |
| parent | d714c4d35bc627d9113a4925f843c54d6123e621 (diff) | |
| download | gitlab-431e4bdf089354534f6877d39631ff23038e8866.tar.gz | |
Py3 compatibility with six
Diffstat (limited to 'gitlab.py')
| -rw-r--r-- | gitlab.py | 24 |
1 files changed, 9 insertions, 15 deletions
@@ -17,19 +17,12 @@ from __future__ import print_function, division, absolute_import -from itertools import chain +import six import json import requests import sys -if sys.version_info[0] < 3: - PY2=True - str_types = (str, unicode,) -else: - PY2=False - str_types = (str,) - __title__ = 'python-gitlab' __version__ = '0.7' __author__ = 'Gauvain Pocentek' @@ -292,7 +285,7 @@ class Gitlab(object): url = obj._url % args url = '%s%s' % (self._url, url) - for k, v in obj.__dict__.items(): + for k, v in list(obj.__dict__.items()): if type(v) == bool: obj.__dict__[k] = 1 if v else 0 @@ -318,12 +311,12 @@ class Gitlab(object): # build a dict of data that can really be sent to server d = {} - for k, v in obj.__dict__.items(): + for k, v in list(obj.__dict__.items()): if type(v) in (int, str): d[k] = str(v) elif type(v) == bool: d[k] = 1 if v else 0 - elif PY2 and type(v) == unicode: + elif six.PY2 and type(v) == six.text_type: d[k] = str(v.encode(self.gitlab_encoding, "replace")) try: @@ -473,7 +466,7 @@ def _get_display_encoding(): def _sanitize(value): - if type(value) in str_types: + if isinstance(value, six.string_types): return value.replace('/', '%2F') return value @@ -573,7 +566,8 @@ class GitlabObject(object): def __init__(self, gl, data=None, **kwargs): self.gitlab = gl - if data is None or type(data) in chain((int,), str_types): + if data is None or isinstance(data, six.integer_types) or\ + isinstance(data, six.string_types): data = self.gitlab.get(self.__class__, data, **kwargs) self._setFromDict(data) @@ -609,7 +603,7 @@ class GitlabObject(object): elif isinstance(obj, list): s = ", ".join([GitlabObject._obj_to_str(x) for x in obj]) return "[ %s ]" % s - elif PY2 and isinstance(obj, unicode): + elif six.PY2 and isinstance(obj, six.text_type): return obj.encode(_get_display_encoding(), "replace") else: return str(obj) @@ -622,7 +616,7 @@ class GitlabObject(object): continue v = self.__dict__[k] pretty_k = k.replace('_', '-') - if PY2: + if six.PY2: pretty_k = pretty_k.encode(_get_display_encoding(), "replace") if isinstance(v, GitlabObject): if depth == 0: |
