Skip to content

Commit b80290a

Browse files
authored
Update urllib to use six package (#117)
* Use six to make urllib py2 and py3 compatible * Update release to 1.0.9 * Update release to 1.0.9 * Update change log
1 parent 324478e commit b80290a

5 files changed

Lines changed: 25 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## 1.0.9
4+
5+
**Date** - 02/04/2020
6+
7+
**Release Tag** - [v1.0.9](https://github.com/datacommonsorg/api-python/releases/tag/v1.0.9)
8+
9+
**Release Status** - Current head of branch [`master`](https://github.com/datacommonsorg/api-python/tree/master)
10+
11+
New features added to the Python Client API
12+
13+
- Use six package for urllib.
14+
315
## 1.0.7
416

517
**Date** - 02/04/2020

datacommons/query.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
import json
2727
import os
28-
import urllib.request
28+
import six.moves.urllib.error
29+
import six.moves.urllib.request
2930

3031
# ----------------------------- WRAPPER FUNCTIONS -----------------------------
3132

@@ -95,14 +96,14 @@ def query(query_string, select=None):
9596
'x-api-key': os.environ[_ENV_VAR_API_KEY],
9697
'Content-Type': 'application/json'
9798
}
98-
req = urllib.request.Request(
99+
req = six.moves.urllib.request.Request(
99100
req_url,
100101
data=json.dumps({'sparql': query_string}).encode("utf-8"),
101102
headers=headers)
102103

103104
try:
104-
res = urllib.request.urlopen(req)
105-
except urllib.error.HTTPError as e:
105+
res = six.moves.urllib.request.urlopen(req)
106+
except six.moves.urllib.error.HTTPError as e:
106107
raise ValueError(
107108
'Response error: An HTTP {} code was returned by the mixer. Printing '
108109
'response\n\n{}'.format(e.code, e.read()))

datacommons/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import base64
2626
import json
2727
import os
28-
import urllib.request
28+
import six.moves.urllib.error
29+
import six.moves.urllib.request
2930
import zlib
3031

3132

@@ -98,14 +99,14 @@ def _send_request(req_url, req_json={}, compress=False, post=True):
9899

99100
# Send the request and verify the request succeeded
100101
if post:
101-
req = urllib.request.Request(
102+
req = six.moves.urllib.request.Request(
102103
req_url,
103104
data=json.dumps(req_json).encode('utf-8'),
104105
headers=headers)
105106
else:
106-
req = urllib.request.Request(req_url, headers=headers)
107+
req = six.moves.urllib.request.Request(req_url, headers=headers)
107108
try:
108-
res = urllib.request.urlopen(req)
109+
res = six.moves.urllib.request.urlopen(req)
109110
except urllib.error.HTTPError as e:
110111
raise ValueError(
111112
'Response error: An HTTP {} code was returned by the mixer. Printing '

requirements.bazel.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
six
12
mock
23
httplib2
34
sphinx

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
EMAIL = 'support@datacommons.org'
2626
AUTHOR = 'datacommons.org'
2727
REQUIRES_PYTHON = '>=2.7'
28-
VERSION = '1.0.7'
28+
VERSION = '1.0.9'
2929

3030
REQUIRED = [
31+
'six',
3132
'httplib2',
3233
'sphinx',
3334
'sphinxcontrib-napoleon',

0 commit comments

Comments
 (0)