Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gitlab
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function, division, absolute_import

import os
import sys
import re
Expand Down
20 changes: 13 additions & 7 deletions gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function, division, absolute_import

import six

import json
import requests
import sys
Expand Down Expand Up @@ -281,7 +285,7 @@ def create(self, obj):
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

Expand All @@ -307,12 +311,12 @@ def update(self, obj):

# 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 type(v) == unicode:
elif six.PY2 and type(v) == six.text_type:
d[k] = str(v.encode(self.gitlab_encoding, "replace"))

try:
Expand Down Expand Up @@ -462,7 +466,7 @@ def _get_display_encoding():


def _sanitize(value):
if type(value) in (str, unicode):
if isinstance(value, six.string_types):
return value.replace('/', '%2F')
return value

Expand Down Expand Up @@ -562,7 +566,8 @@ def delete(self):
def __init__(self, gl, data=None, **kwargs):
self.gitlab = gl

if data is None or type(data) in [int, str, unicode]:
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)
Expand Down Expand Up @@ -598,7 +603,7 @@ def _obj_to_str(obj):
elif isinstance(obj, list):
s = ", ".join([GitlabObject._obj_to_str(x) for x in obj])
return "[ %s ]" % s
elif isinstance(obj, unicode):
elif six.PY2 and isinstance(obj, six.text_type):
return obj.encode(_get_display_encoding(), "replace")
else:
return str(obj)
Expand All @@ -611,7 +616,8 @@ def pretty_print(self, depth=0):
continue
v = self.__dict__[k]
pretty_k = k.replace('_', '-')
pretty_k = pretty_k.encode(_get_display_encoding(), "replace")
if six.PY2:
pretty_k = pretty_k.encode(_get_display_encoding(), "replace")
if isinstance(v, GitlabObject):
if depth == 0:
print("%s:" % pretty_k)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
requests>1.0
six
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_version():
url='https://github.com/gpocentek/python-gitlab',
py_modules=['gitlab'],
scripts=['gitlab'],
install_requires=['requests'],
install_requires=['requests', 'six'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
Expand Down