Skip to content

Commit 7bd49a1

Browse files
committed
python3 compability fixes
1 parent 3c07404 commit 7bd49a1

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ python:
44
- "3.2"
55
- "3.3"
66
- "3.4"
7+
- "3.5"
78
install:
89
- pip install .
910
- pip install -r requirements-dev.txt

cloudconvert/api.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import json
2-
import urllib
2+
3+
try:
4+
from urllib.parse import quote, unquote
5+
except ImportError:
6+
from urllib import quote, unquote
7+
8+
9+
import io
310

411
from requests import request, Session
512
from requests.exceptions import RequestException
@@ -103,16 +110,24 @@ def rawCall(self, method, path, content=None, is_authenticated=False, stream=Fal
103110

104111
## check if we upload anything
105112
isupload = False
113+
114+
try:
115+
fileInstance=file # python 2
116+
except NameError:
117+
fileInstance=io.BufferedReader # python 3
118+
106119
for key, value in content.items():
107-
if isinstance(value, file):
120+
if key == 'file':
121+
x= ""
122+
if isinstance(value, fileInstance):
108123
## if it is file: remove from content dict and add it to files dict
109124
isupload = True
110125
files = {key: value}
111126
del content[key]
112127
break
113128

114129
if isupload:
115-
url += "?" + urllib.unquote(urlencode(content))
130+
url += "?" + unquote(urlencode(content))
116131
else:
117132
headers['Content-type'] = 'application/json'
118133
body = json.dumps(content)

tests/test_process.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_02_if_process_with_input_upload_works(self):
5151
'input': 'upload',
5252
'outputformat': 'jpg',
5353
'wait': True,
54-
'file': open('input.png', 'rb')
54+
'file': open('tests/input.png', 'rb')
5555
})
5656
self.assertEqual(process['step'],'finished')
5757
self.assertEqual(process['output']['ext'],'jpg')
@@ -70,7 +70,7 @@ def test_03_if_process_with_input_upload_and_custom_options_works(self):
7070
'input': 'upload',
7171
'outputformat': 'jpg',
7272
'wait': True,
73-
'file': open('input.png', 'rb'),
73+
'file': open('tests/input.png', 'rb'),
7474
'converteroptions': {
7575
'quality': 10
7676
}
@@ -92,7 +92,7 @@ def test_04_if_download_of_output_file_works(self):
9292
process.start({
9393
'input': 'upload',
9494
'outputformat': 'pdf',
95-
'file': open('input.png', 'rb')
95+
'file': open('tests/input.png', 'rb')
9696
})
9797
process.wait()
9898
process.download("output.pdf")
@@ -112,7 +112,7 @@ def test_05_if_download_of_multiple_output_file_works(self):
112112
process.start({
113113
'input': 'upload',
114114
'outputformat': 'jpg',
115-
'file': open('input.pdf', 'rb'),
115+
'file': open('tests/input.pdf', 'rb'),
116116
'converteroptions': {
117117
'page_range': '1-2'
118118
}
@@ -134,7 +134,7 @@ def test_06_if_convert_shortcut_works(self):
134134
'inputformat': 'png',
135135
'outputformat': 'jpg',
136136
'input': 'upload',
137-
'file': open('input.png', 'rb')
137+
'file': open('tests/input.png', 'rb')
138138
}).wait()
139139
self.assertEqual(process['step'],'finished')
140140
self.assertEqual(process['output']['ext'],'jpg')

0 commit comments

Comments
 (0)