Fix http.py: Exception -> exception, lint errors, unit test. (#724)
* Exception -> exception.
* Assign exception = None
* Fix lint errors.
* Fix test_media_file_upload_closes_fd_in__del__
diff --git a/googleapiclient/http.py b/googleapiclient/http.py
index a57f83d..9733aa3 100644
--- a/googleapiclient/http.py
+++ b/googleapiclient/http.py
@@ -149,6 +149,7 @@
"""
resp = None
content = None
+ exception = None
for retry_num in range(num_retries + 1):
if retry_num > 0:
# Sleep before retrying.
@@ -156,7 +157,7 @@
LOGGER.warning(
'Sleeping %.2f seconds before retry %d of %d for %s: %s %s, after %s',
sleep_time, retry_num, num_retries, req_type, method, uri,
- resp.status if resp else Exception)
+ resp.status if resp else exception)
sleep(sleep_time)
try:
diff --git a/samples/coordinate/coordinate.py b/samples/coordinate/coordinate.py
index e177f6d..e569e3f 100644
--- a/samples/coordinate/coordinate.py
+++ b/samples/coordinate/coordinate.py
@@ -45,6 +45,8 @@
from oauth2client import client
from googleapiclient import sample_tools
+from googleapiclient.discovery import build
+from googleapiclient.discovery import http
# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
@@ -61,7 +63,7 @@
try:
# List all the jobs for a team
- jobs_result = service.jobs().list(teamId=FLAGS.teamId).execute(http=http)
+ jobs_result = service.jobs().list(teamId=flags.teamId).execute(http=http)
print('List of Jobs:')
pprint.pprint(jobs_result)
diff --git a/tests/test_http.py b/tests/test_http.py
index edaef6d..5aaada6 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -213,8 +213,12 @@
def test_media_file_upload_closes_fd_in___del__(self):
file_desc = mock.Mock(spec=io.TextIOWrapper)
opener = mock.mock_open(file_desc)
- with mock.patch('__builtin__.open', return_value=opener):
- upload = MediaFileUpload(datafile('test_close'), mimetype='text/plain')
+ if PY3:
+ with mock.patch('builtins.open', return_value=opener):
+ upload = MediaFileUpload(datafile('test_close'), mimetype='text/plain')
+ else:
+ with mock.patch('__builtin__.open', return_value=opener):
+ upload = MediaFileUpload(datafile('test_close'), mimetype='text/plain')
self.assertIs(upload.stream(), file_desc)
del upload
file_desc.close.assert_called_once_with()