From 79f0e4315b288e56b1de2703153c98f8cbf65d2b Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Sun, 28 May 2017 19:03:42 +0100 Subject: [PATCH 1/2] import urlencode() from six.moves.urllib.parse instead of from urllib Fixes AttributeError on Python 3, as `urlencode` function has been moved to `urllib.parse` module. `six.moves.urllib.parse.urlencode()` is an py2.py3 compatible alias of `urllib.parse.urlencode()` on Python 3, and of `urllib.urlencode()` on Python 2. --- gitlab/v3/objects.py | 6 +++--- gitlab/v4/objects.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gitlab/v3/objects.py b/gitlab/v3/objects.py index b2fd18044..822af8b2a 100644 --- a/gitlab/v3/objects.py +++ b/gitlab/v3/objects.py @@ -20,10 +20,10 @@ from __future__ import absolute_import import base64 import json -import urllib import warnings import six +from six.moves.urllib.parse import urlencode import gitlab from gitlab.base import * # noqa @@ -1841,7 +1841,7 @@ def repository_tree(self, path='', ref_name='', **kwargs): url = "/projects/%s/repository/tree" % (self.id) params = [] if path: - params.append(urllib.urlencode({'path': path})) + params.append(urlencode({'path': path})) if ref_name: params.append("ref_name=%s" % ref_name) if params: @@ -1872,7 +1872,7 @@ def repository_blob(self, sha, filepath, streamed=False, action=None, GitlabGetError: If the server fails to perform the request. """ url = "/projects/%s/repository/blobs/%s" % (self.id, sha) - url += '?%s' % (urllib.urlencode({'filepath': filepath})) + url += '?%s' % (urlencode({'filepath': filepath})) r = self.gitlab._raw_get(url, streamed=streamed, **kwargs) raise_error_from_response(r, GitlabGetError) return utils.response_content(r, streamed, action, chunk_size) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 83790bfac..c111ab810 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -20,9 +20,9 @@ from __future__ import absolute_import import base64 import json -import urllib import six +from six.moves.urllib.parse import urlencode import gitlab from gitlab.base import * # noqa @@ -1846,7 +1846,7 @@ def repository_tree(self, path='', ref='', **kwargs): url = "/projects/%s/repository/tree" % (self.id) params = [] if path: - params.append(urllib.urlencode({'path': path})) + params.append(urlencode({'path': path})) if ref: params.append("ref=%s" % ref) if params: From 62e269f341805d7474f1b8d0bb73434ed00e802d Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Sun, 28 May 2017 19:16:38 +0100 Subject: [PATCH 2/2] [pep8] fix "does not import a module" --- gitlab/v3/objects.py | 6 +++--- gitlab/v4/objects.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gitlab/v3/objects.py b/gitlab/v3/objects.py index 822af8b2a..84b9cb558 100644 --- a/gitlab/v3/objects.py +++ b/gitlab/v3/objects.py @@ -23,7 +23,7 @@ import warnings import six -from six.moves.urllib.parse import urlencode +from six.moves import urllib import gitlab from gitlab.base import * # noqa @@ -1841,7 +1841,7 @@ def repository_tree(self, path='', ref_name='', **kwargs): url = "/projects/%s/repository/tree" % (self.id) params = [] if path: - params.append(urlencode({'path': path})) + params.append(urllib.parse.urlencode({'path': path})) if ref_name: params.append("ref_name=%s" % ref_name) if params: @@ -1872,7 +1872,7 @@ def repository_blob(self, sha, filepath, streamed=False, action=None, GitlabGetError: If the server fails to perform the request. """ url = "/projects/%s/repository/blobs/%s" % (self.id, sha) - url += '?%s' % (urlencode({'filepath': filepath})) + url += '?%s' % (urllib.parse.urlencode({'filepath': filepath})) r = self.gitlab._raw_get(url, streamed=streamed, **kwargs) raise_error_from_response(r, GitlabGetError) return utils.response_content(r, streamed, action, chunk_size) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index c111ab810..628314994 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -22,7 +22,7 @@ import json import six -from six.moves.urllib.parse import urlencode +from six.moves import urllib import gitlab from gitlab.base import * # noqa @@ -1846,7 +1846,7 @@ def repository_tree(self, path='', ref='', **kwargs): url = "/projects/%s/repository/tree" % (self.id) params = [] if path: - params.append(urlencode({'path': path})) + params.append(urllib.parse.urlencode({'path': path})) if ref: params.append("ref=%s" % ref) if params: