Skip to content

Commit 3c07404

Browse files
committed
fix dependency "multidimensional_urlencode" for python 3
1 parent 6a9b6fa commit 3c07404

4 files changed

Lines changed: 111 additions & 60 deletions

File tree

cloudconvert/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from requests import request, Session
55
from requests.exceptions import RequestException
6-
from multidimensional_urlencode import urlencode
6+
from .urlencoder import urlencode
77

88
from .process import Process
99
from .exceptions import (

cloudconvert/urlencoder.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""
2+
source: https://github.com/udemy/multidimensional_urlencode
3+
should be changed to install requirement of "multidimensional_urlencode" as soon as https://github.com/uber/multidimensional_urlencode/pull/5 is merged
4+
5+
"""
6+
7+
8+
try:
9+
from urllib.parse import urlencode as urllib_urlencode
10+
except ImportError:
11+
from urllib import urlencode as urllib_urlencode
12+
13+
14+
def flatten(d):
15+
"""Return a dict as a list of lists.
16+
>>> flatten({"a": "b"})
17+
[['a', 'b']]
18+
>>> flatten({"a": [1, 2, 3]})
19+
[['a', [1, 2, 3]]]
20+
>>> flatten({"a": {"b": "c"}})
21+
[['a', 'b', 'c']]
22+
>>> flatten({"a": {"b": {"c": "e"}}})
23+
[['a', 'b', 'c', 'e']]
24+
>>> sorted(flatten({"a": {"b": "c", "d": "e"}}))
25+
[['a', 'b', 'c'], ['a', 'd', 'e']]
26+
>>> sorted(flatten({"a": {"b": "c", "d": "e"}, "b": {"c": "d"}}))
27+
[['a', 'b', 'c'], ['a', 'd', 'e'], ['b', 'c', 'd']]
28+
"""
29+
30+
if not isinstance(d, dict):
31+
return [[d]]
32+
33+
returned = []
34+
for key, value in list(d.items()):
35+
# Each key, value is treated as a row.
36+
nested = flatten(value)
37+
for nest in nested:
38+
current_row = [key]
39+
current_row.extend(nest)
40+
returned.append(current_row)
41+
42+
return returned
43+
44+
45+
def parametrize(params):
46+
"""Return list of params as params.
47+
>>> parametrize(['a'])
48+
'a'
49+
>>> parametrize(['a', 'b'])
50+
'a[b]'
51+
>>> parametrize(['a', 'b', 'c'])
52+
'a[b][c]'
53+
"""
54+
returned = str(params[0])
55+
returned += "".join("[" + str(p) + "]" for p in params[1:])
56+
return returned
57+
58+
59+
def urlencode(params):
60+
"""Urlencode a multidimensional dict."""
61+
62+
# Not doing duck typing here. Will make debugging easier.
63+
if not isinstance(params, dict):
64+
raise TypeError("Only dicts are supported.")
65+
66+
params = flatten(params)
67+
68+
url_params = {}
69+
for param in params:
70+
value = param.pop()
71+
72+
name = parametrize(param)
73+
if isinstance(value, (list, tuple)):
74+
name += "[]"
75+
76+
url_params[name] = value
77+
78+
return urllib_urlencode(url_params, doseq=True)

setup.cfg

Lines changed: 0 additions & 45 deletions
This file was deleted.

setup.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
1-
#!/usr/bin/env python
21

3-
try:
4-
from setuptools import setup
5-
except ImportError:
6-
from distribute_setup import use_setuptools
7-
use_setuptools()
8-
from setuptools import setup
2+
3+
from __future__ import print_function
4+
5+
from setuptools import setup
6+
97

108
setup(
11-
setup_requires=['d2to1'],
12-
d2to1=True,
13-
tests_require=[
14-
"coverage==3.7.1",
15-
"nose==1.3.3",
16-
"yanc==0.2.4",
17-
],
9+
name='cloudconvert',
10+
version='1.0.0',
11+
url='https://github.com/cloudconvert/cloudconvert-python',
12+
license='MIT',
13+
author='Josias Montag',
14+
tests_require=['nosetests'],
15+
author_email='info@cloudconvert.com',
16+
description='Official CloudConvert API wrapper',
17+
packages=['cloudconvert'],
18+
include_package_data=True,
19+
platforms='any',
20+
zip_safe=False,
21+
keywords=["cloudconvert", "convert"],
22+
install_requires = ['requests>=2.3.0'],
23+
classifiers=[
24+
"License :: OSI Approved :: BSD License",
25+
"Development Status :: 4 - Beta",
26+
"Intended Audience :: Developers",
27+
"Operating System :: OS Independent",
28+
"Programming Language :: Python",
29+
"Programming Language :: Python :: 2.7",
30+
"Programming Language :: Python :: 3.2",
31+
"Programming Language :: Python :: 3.3",
32+
"Programming Language :: Python :: 3.4",
33+
"Topic :: Software Development :: Libraries :: Python Modules",
34+
"Topic :: System :: Archiving :: Packaging",
35+
],
1836
)

0 commit comments

Comments
 (0)