Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ba1ca4

Browse files
authored
Fix http.py: Exception -> exception, lint errors, unit test. (googleapis#724)
* Exception -> exception. * Assign exception = None * Fix lint errors. * Fix test_media_file_upload_closes_fd_in__del__
1 parent 317f6ab commit 0ba1ca4

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

googleapiclient/http.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,15 @@ def _retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args,
149149
"""
150150
resp = None
151151
content = None
152+
exception = None
152153
for retry_num in range(num_retries + 1):
153154
if retry_num > 0:
154155
# Sleep before retrying.
155156
sleep_time = rand() * 2 ** retry_num
156157
LOGGER.warning(
157158
'Sleeping %.2f seconds before retry %d of %d for %s: %s %s, after %s',
158159
sleep_time, retry_num, num_retries, req_type, method, uri,
159-
resp.status if resp else Exception)
160+
resp.status if resp else exception)
160161
sleep(sleep_time)
161162

162163
try:

samples/coordinate/coordinate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545

4646
from oauth2client import client
4747
from googleapiclient import sample_tools
48+
from googleapiclient.discovery import build
49+
from googleapiclient.discovery import http
4850

4951
# Declare command-line flags.
5052
argparser = argparse.ArgumentParser(add_help=False)
@@ -61,7 +63,7 @@ def main(argv):
6163

6264
try:
6365
# List all the jobs for a team
64-
jobs_result = service.jobs().list(teamId=FLAGS.teamId).execute(http=http)
66+
jobs_result = service.jobs().list(teamId=flags.teamId).execute(http=http)
6567

6668
print('List of Jobs:')
6769
pprint.pprint(jobs_result)

tests/test_http.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,12 @@ class TestMediaUpload(unittest.TestCase):
213213
def test_media_file_upload_closes_fd_in___del__(self):
214214
file_desc = mock.Mock(spec=io.TextIOWrapper)
215215
opener = mock.mock_open(file_desc)
216-
with mock.patch('__builtin__.open', return_value=opener):
217-
upload = MediaFileUpload(datafile('test_close'), mimetype='text/plain')
216+
if PY3:
217+
with mock.patch('builtins.open', return_value=opener):
218+
upload = MediaFileUpload(datafile('test_close'), mimetype='text/plain')
219+
else:
220+
with mock.patch('__builtin__.open', return_value=opener):
221+
upload = MediaFileUpload(datafile('test_close'), mimetype='text/plain')
218222
self.assertIs(upload.stream(), file_desc)
219223
del upload
220224
file_desc.close.assert_called_once_with()

0 commit comments

Comments
 (0)