summaryrefslogtreecommitdiff
path: root/gitlab/utils.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2018-08-24 17:09:55 +0200
committerGauvain Pocentek <gauvain@pocentek.net>2018-08-24 17:09:55 +0200
commita221d7b35bc20da758e7467fe789e16613c54275 (patch)
treea3d669b74286f4185b28d9cd5d7e2722b08ce58f /gitlab/utils.py
parent80a68f9258422d5d74f05a20234070ce3d6f5559 (diff)
downloadgitlab-a221d7b35bc20da758e7467fe789e16613c54275.tar.gz
Raise an exception on https redirects for PUT/POST
POST and PUT requests are modified by clients when redirections happen. A common problem with python-gitlab is a misconfiguration of the server URL: the http to https redirection breaks some requests. With this change python-gitlab should detect problematic redirections, and raise a proper exception instead of failing with a cryptic error. Closes #565
Diffstat (limited to 'gitlab/utils.py')
-rw-r--r--gitlab/utils.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/gitlab/utils.py b/gitlab/utils.py
index a449f81..49e2c88 100644
--- a/gitlab/utils.py
+++ b/gitlab/utils.py
@@ -15,6 +15,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/>.
+import six
+
class _StdoutStream(object):
def __call__(self, chunk):
@@ -31,3 +33,21 @@ def response_content(response, streamed, action, chunk_size):
for chunk in response.iter_content(chunk_size=chunk_size):
if chunk:
action(chunk)
+
+
+def copy_dict(dest, src):
+ for k, v in src.items():
+ if isinstance(v, dict):
+ # Transform dict values to new attributes. For example:
+ # custom_attributes: {'foo', 'bar'} =>
+ # "custom_attributes['foo']": "bar"
+ for dict_k, dict_v in v.items():
+ dest['%s[%s]' % (k, dict_k)] = dict_v
+ else:
+ dest[k] = v
+
+
+def sanitized_url(url):
+ parsed = six.moves.urllib.parse.urlparse(url)
+ new_path = parsed.path.replace('.', '%2E')
+ return parsed._replace(path=new_path).geturl()