Skip to content

Commit 1eccc3b

Browse files
author
Gauvain Pocentek
committed
Merge pull request #40 from mjmaenpaa/py3
Python3 compatibility
2 parents 221f418 + 431e4bd commit 1eccc3b

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

gitlab

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818

19+
from __future__ import print_function, division, absolute_import
20+
1921
import os
2022
import sys
2123
import re

gitlab.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18+
from __future__ import print_function, division, absolute_import
19+
20+
import six
21+
1822
import json
1923
import requests
2024
import sys
@@ -292,7 +296,7 @@ def create(self, obj):
292296

293297
url = self.constructUrl(id_=None, obj=obj, parameters=obj.__dict__)
294298

295-
for k, v in obj.__dict__.items():
299+
for k, v in list(obj.__dict__.items()):
296300
if type(v) == bool:
297301
obj.__dict__[k] = 1 if v else 0
298302

@@ -317,12 +321,12 @@ def update(self, obj):
317321

318322
# build a dict of data that can really be sent to server
319323
d = {}
320-
for k, v in obj.__dict__.items():
324+
for k, v in list(obj.__dict__.items()):
321325
if type(v) in (int, str):
322326
d[k] = str(v)
323327
elif type(v) == bool:
324328
d[k] = 1 if v else 0
325-
elif type(v) == unicode:
329+
elif six.PY2 and type(v) == six.text_type:
326330
d[k] = str(v.encode(self.gitlab_encoding, "replace"))
327331

328332
try:
@@ -473,7 +477,7 @@ def _get_display_encoding():
473477

474478

475479
def _sanitize(value):
476-
if type(value) in (str, unicode):
480+
if isinstance(value, six.string_types):
477481
return value.replace('/', '%2F')
478482
return value
479483

@@ -573,7 +577,8 @@ def delete(self):
573577
def __init__(self, gl, data=None, **kwargs):
574578
self.gitlab = gl
575579

576-
if data is None or type(data) in [int, str, unicode]:
580+
if data is None or isinstance(data, six.integer_types) or\
581+
isinstance(data, six.string_types):
577582
data = self.gitlab.get(self.__class__, data, **kwargs)
578583

579584
self._setFromDict(data)
@@ -609,7 +614,7 @@ def _obj_to_str(obj):
609614
elif isinstance(obj, list):
610615
s = ", ".join([GitlabObject._obj_to_str(x) for x in obj])
611616
return "[ %s ]" % s
612-
elif isinstance(obj, unicode):
617+
elif six.PY2 and isinstance(obj, six.text_type):
613618
return obj.encode(_get_display_encoding(), "replace")
614619
else:
615620
return str(obj)
@@ -622,7 +627,8 @@ def pretty_print(self, depth=0):
622627
continue
623628
v = self.__dict__[k]
624629
pretty_k = k.replace('_', '-')
625-
pretty_k = pretty_k.encode(_get_display_encoding(), "replace")
630+
if six.PY2:
631+
pretty_k = pretty_k.encode(_get_display_encoding(), "replace")
626632
if isinstance(v, GitlabObject):
627633
if depth == 0:
628634
print("%s:" % pretty_k)

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
requests>1.0
2+
six

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_version():
2222
url='https://github.com/gpocentek/python-gitlab',
2323
py_modules=['gitlab'],
2424
scripts=['gitlab'],
25-
install_requires=['requests'],
25+
install_requires=['requests', 'six'],
2626
classifiers=[
2727
'Development Status :: 5 - Production/Stable',
2828
'Environment :: Console',

0 commit comments

Comments
 (0)