Skip to content

Commit

Permalink
Updating exception variable naming to be Python3 compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
pferate committed Dec 24, 2014
1 parent bbad4f0 commit f1542f7
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion googleapiclient/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def build(serviceName,

try:
service = json.loads(content)
except ValueError, e:
except ValueError as e:
logger.error('Failed to parse as JSON: ' + content)
raise InvalidJsonError()

Expand Down
2 changes: 1 addition & 1 deletion googleapiclient/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ def execute(self, http=None):
if resp.status >= 300:
raise HttpError(resp, content, uri=request.uri)
response = request.postproc(resp, content)
except HttpError, e:
except HttpError as e:
exception = e

if callback is not None:
Expand Down
4 changes: 2 additions & 2 deletions samples/analytics/core_reporting_v3_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ def main(argv):
results = get_api_query(service, flags.table_id).execute()
print_results(results)

except TypeError, error:
except TypeError as error:
# Handle errors in constructing a query.
print ('There was an error in constructing your query : %s' % error)

except HttpError, error:
except HttpError as error:
# Handle API errors.
print ('Arg, there was an API error : %s : %s' %
(error.resp.status, error._get_reason()))
Expand Down
4 changes: 2 additions & 2 deletions samples/analytics/hello_analytics_api_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def main(argv):
results = get_top_keywords(service, first_profile_id)
print_results(results)

except TypeError, error:
except TypeError as error:
# Handle errors in constructing a query.
print ('There was an error in constructing your query : %s' % error)

except HttpError, error:
except HttpError as error:
# Handle API errors.
print ('Arg, there was an API error : %s : %s' %
(error.resp.status, error._get_reason()))
Expand Down
4 changes: 2 additions & 2 deletions samples/analytics/management_v3_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def main(argv):
try:
traverse_hiearchy(service)

except TypeError, error:
except TypeError as error:
# Handle errors in constructing a query.
print ('There was an error in constructing your query : %s' % error)

except HttpError, error:
except HttpError as error:
# Handle API errors.
print ('Arg, there was an API error : %s : %s' %
(error.resp.status, error._get_reason()))
Expand Down
2 changes: 1 addition & 1 deletion samples/coordinate/coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def main(argv):

pprint.pprint(update_result)

except AccessTokenRefreshError, e:
except AccessTokenRefreshError as e:
print ('The credentials have been revoked or expired, please re-run'
'the application to re-authorize')

Expand Down
18 changes: 9 additions & 9 deletions tests/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def test_userip_is_added_to_discovery_uri(self):
zoo = build('zoo', 'v1', http=http, developerKey='foo',
discoveryServiceUrl='http://example.com')
self.fail('Should have raised an exception.')
except HttpError, e:
except HttpError as e:
self.assertEqual(e.uri, 'http://example.com?userIp=10.0.0.1')

def test_userip_missing_is_not_added_to_discovery_uri(self):
Expand All @@ -381,7 +381,7 @@ def test_userip_missing_is_not_added_to_discovery_uri(self):
zoo = build('zoo', 'v1', http=http, developerKey=None,
discoveryServiceUrl='http://example.com')
self.fail('Should have raised an exception.')
except HttpError, e:
except HttpError as e:
self.assertEqual(e.uri, 'http://example.com')


Expand All @@ -395,28 +395,28 @@ def test_method_error_checking(self):
try:
plus.activities().list()
self.fail()
except TypeError, e:
except TypeError as e:
self.assertTrue('Missing' in str(e))

# Missing required parameters even if supplied as None.
try:
plus.activities().list(collection=None, userId=None)
self.fail()
except TypeError, e:
except TypeError as e:
self.assertTrue('Missing' in str(e))

# Parameter doesn't match regex
try:
plus.activities().list(collection='not_a_collection_name', userId='me')
self.fail()
except TypeError, e:
except TypeError as e:
self.assertTrue('not an allowed value' in str(e))

# Unexpected parameter
try:
plus.activities().list(flubber=12)
self.fail()
except TypeError, e:
except TypeError as e:
self.assertTrue('unexpected' in str(e))

def _check_query_types(self, request):
Expand Down Expand Up @@ -785,7 +785,7 @@ def test_resumable_media_fail_unknown_response_code_first_request(self):
try:
request.execute(http=http)
self.fail('Should have raised ResumableUploadError.')
except ResumableUploadError, e:
except ResumableUploadError as e:
self.assertEqual(400, e.resp.status)

def test_resumable_media_fail_unknown_response_code_subsequent_request(self):
Expand Down Expand Up @@ -885,7 +885,7 @@ def test_media_io_base_stream_chunksize_resume(self):

try:
body = request.execute(http=http)
except HttpError, e:
except HttpError as e:
self.assertEqual('01234', e.content)

except ImportError:
Expand Down Expand Up @@ -1040,7 +1040,7 @@ def test_resumable_media_handle_resume_of_upload_of_unknown_size(self):
try:
# Should resume the upload by first querying the status of the upload.
request.next_chunk(http=http)
except HttpError, e:
except HttpError as e:
expected = {
'Content-Range': 'bytes */14',
'content-length': '0'
Expand Down
2 changes: 1 addition & 1 deletion tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def test_execute_request_body(self):
try:
batch.execute(http=http)
self.fail('Should raise exception')
except BatchError, e:
except BatchError as e:
boundary, _ = e.content.split(None, 1)
self.assertEqual('--', boundary[:2])
parts = e.content.split(boundary)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_json_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ def test_bad_response(self):
try:
content = model.response(resp, content)
self.fail('Should have thrown an exception')
except HttpError, e:
except HttpError as e:
self.assertTrue('not authorized' in str(e))

resp['content-type'] = 'application/json'

try:
content = model.response(resp, content)
self.fail('Should have thrown an exception')
except HttpError, e:
except HttpError as e:
self.assertTrue('not authorized' in str(e))

def test_good_response(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_errors(self):
try:
activity = plus.activities().list(collection='public', userId='me').execute()
self.fail('An exception should have been thrown')
except HttpError, e:
except HttpError as e:
self.assertEqual('{}', e.content)
self.assertEqual(500, e.resp.status)
self.assertEqual('Server Error', e.resp.reason)
Expand Down
10 changes: 9 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[tox]
envlist = py26, py27
;envlist = py26, py27, py33, py34
envlist = py27, py33, py34
;skipsdist = True

[testenv]
deps = keyring
Expand All @@ -16,3 +18,9 @@ commands = nosetests --ignore-files=test_oauth2client_appengine\.py

[testenv:py27]
commands = nosetests

[testenv:py33]
commands = nosetests

[testenv:py34]
commands = nosetests

0 comments on commit f1542f7

Please sign in to comment.