Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions googleapiclient/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

A client library for Google's discovery based APIs.
"""
from __future__ import absolute_import

__author__ = '[email protected] (Joe Gregorio)'
__all__ = [
Expand Down Expand Up @@ -48,7 +49,7 @@

# Third-party imports
import httplib2
import mimeparse
from . import mimeparse
import uritemplate

# Local imports
Expand Down Expand Up @@ -205,7 +206,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 Expand Up @@ -329,13 +330,13 @@ def _media_size_to_long(maxSize):
The size as an integer value.
"""
if len(maxSize) < 2:
return 0L
return 0
units = maxSize[-2:].upper()
bit_shift = _MEDIA_SIZE_BIT_SHIFTS.get(units)
if bit_shift is not None:
return long(maxSize[:-2]) << bit_shift
return int(maxSize[:-2]) << bit_shift
else:
return long(maxSize)
return int(maxSize)


def _media_path_url_from_info(root_desc, path_url):
Expand Down
19 changes: 10 additions & 9 deletions googleapiclient/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
object supporting an execute() method that does the
actuall HTTP request.
"""
from __future__ import absolute_import

__author__ = '[email protected] (Joe Gregorio)'

Expand All @@ -28,7 +29,7 @@
import httplib2
import json
import logging
import mimeparse
from . import mimeparse
import mimetypes
import os
import random
Expand All @@ -42,13 +43,13 @@
from email.mime.multipart import MIMEMultipart
from email.mime.nonmultipart import MIMENonMultipart
from email.parser import FeedParser
from errors import BatchError
from errors import HttpError
from errors import InvalidChunkSizeError
from errors import ResumableUploadError
from errors import UnexpectedBodyError
from errors import UnexpectedMethodError
from model import JsonModel
from .errors import BatchError
from .errors import HttpError
from .errors import InvalidChunkSizeError
from .errors import ResumableUploadError
from .errors import UnexpectedBodyError
from .errors import UnexpectedMethodError
from .model import JsonModel
from oauth2client import util


Expand Down Expand Up @@ -1328,7 +1329,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
5 changes: 3 additions & 2 deletions googleapiclient/mimeparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- best_match(): Choose the mime-type with the highest quality ('q')
from a list of candidates.
"""
from functools import reduce

__version__ = '0.1.3'
__author__ = 'Joe Gregorio'
Expand Down Expand Up @@ -68,7 +69,7 @@ def parse_media_range(range):
necessary.
"""
(type, subtype, params) = parse_mime_type(range)
if not params.has_key('q') or not params['q'] or \
if 'q' not in params or not params['q'] or \
not float(params['q']) or float(params['q']) > 1\
or float(params['q']) < 0:
params['q'] = '1'
Expand Down Expand Up @@ -99,7 +100,7 @@ def fitness_and_quality_parsed(mime_type, parsed_ranges):
if type_match and subtype_match:
param_matches = reduce(lambda x, y: x + y, [1 for (key, value) in \
target_params.iteritems() if key != 'q' and \
params.has_key(key) and value == params[key]], 0)
key in params and value == params[key]], 0)
fitness = (type == target_type) and 100 or 0
fitness += (subtype == target_subtype) and 10 or 0
fitness += param_matches
Expand Down
3 changes: 2 additions & 1 deletion googleapiclient/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
for converting between the wire format and the Python
object representation.
"""
from __future__ import absolute_import

__author__ = '[email protected] (Joe Gregorio)'

Expand All @@ -29,7 +30,7 @@
import urllib

from googleapiclient import __version__
from errors import HttpError
from .errors import HttpError


dump_request_response = False
Expand Down
3 changes: 2 additions & 1 deletion samples-index.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

The rest of the file is ignored when it comes to building the index.
"""
from __future__ import print_function

import httplib2
import itertools
Expand Down Expand Up @@ -239,7 +240,7 @@ def main():
</tr>""" % context)
page.append('</table>\n')

print ''.join(page)
print(''.join(page))


if __name__ == '__main__':
Expand Down
9 changes: 5 additions & 4 deletions samples/adexchangeseller/generate_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

Tags: reports.generate
"""
from __future__ import print_function

__author__ = '[email protected] (Sérgio Gomes)'

Expand Down Expand Up @@ -68,14 +69,14 @@ def main(argv):
sys.exit(1)
# Display headers.
for header in result['headers']:
print '%25s' % header['name'],
print
print('%25s' % header['name'], end=' ')
print()

# Display results.
for row in result['rows']:
for column in row:
print '%25s' % column,
print
print('%25s' % column, end=' ')
print()

except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
Expand Down
9 changes: 5 additions & 4 deletions samples/adexchangeseller/generate_report_with_paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

Tags: reports.generate
"""
from __future__ import print_function

__author__ = '[email protected] (Sérgio Gomes)'

Expand Down Expand Up @@ -70,14 +71,14 @@ def main(argv):
# If this is the first page, display the headers.
if start_index == 0:
for header in result['headers']:
print '%25s' % header['name'],
print
print('%25s' % header['name'], end=' ')
print()

# Display results for this page.
for row in result['rows']:
for column in row:
print '%25s' % column,
print
print('%25s' % column, end=' ')
print()

start_index += len(result['rows'])

Expand Down
9 changes: 5 additions & 4 deletions samples/adexchangeseller/get_all_ad_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

Tags: adclients.list
"""
from __future__ import print_function

__author__ = '[email protected] (Sérgio Gomes)'

Expand All @@ -43,11 +44,11 @@ def main(argv):
result = request.execute()
ad_clients = result['items']
for ad_client in ad_clients:
print ('Ad client for product "%s" with ID "%s" was found. '
% (ad_client['productCode'], ad_client['id']))
print(('Ad client for product "%s" with ID "%s" was found. '
% (ad_client['productCode'], ad_client['id'])))

print ('\tSupports reporting: %s' %
(ad_client['supportsReporting'] and 'Yes' or 'No'))
print(('\tSupports reporting: %s' %
(ad_client['supportsReporting'] and 'Yes' or 'No')))

request = service.adclients().list_next(request, result)

Expand Down
5 changes: 3 additions & 2 deletions samples/adexchangeseller/get_all_ad_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

Tags: adunits.list
"""
from __future__ import print_function

__author__ = '[email protected] (Sérgio Gomes)'

Expand Down Expand Up @@ -54,8 +55,8 @@ def main(argv):
result = request.execute()
ad_units = result['items']
for ad_unit in ad_units:
print ('Ad unit with code "%s", name "%s" and status "%s" was found. ' %
(ad_unit['code'], ad_unit['name'], ad_unit['status']))
print(('Ad unit with code "%s", name "%s" and status "%s" was found. ' %
(ad_unit['code'], ad_unit['name'], ad_unit['status'])))

request = service.adunits().list_next(request, result)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

Tags: customchannels.adunits.list
"""
from __future__ import print_function

__author__ = '[email protected] (Sérgio Gomes)'

Expand Down Expand Up @@ -59,8 +60,8 @@ def main(argv):
result = request.execute()
ad_units = result['items']
for ad_unit in ad_units:
print ('Ad unit with code "%s", name "%s" and status "%s" was found. ' %
(ad_unit['code'], ad_unit['name'], ad_unit['status']))
print(('Ad unit with code "%s", name "%s" and status "%s" was found. ' %
(ad_unit['code'], ad_unit['name'], ad_unit['status'])))

request = service.adunits().list_next(request, result)

Expand Down
7 changes: 4 additions & 3 deletions samples/adexchangeseller/get_all_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

Tags: alerts.list
"""
from __future__ import print_function

__author__ = '[email protected] (Sérgio Gomes)'

Expand All @@ -43,10 +44,10 @@ def main(argv):
if 'items' in result:
alerts = result['items']
for alert in alerts:
print ('Alert id "%s" with severity "%s" and type "%s" was found. '
% (alert['id'], alert['severity'], alert['type']))
print(('Alert id "%s" with severity "%s" and type "%s" was found. '
% (alert['id'], alert['severity'], alert['type'])))
else:
print 'No alerts found!'
print('No alerts found!')
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
Expand Down
15 changes: 8 additions & 7 deletions samples/adexchangeseller/get_all_custom_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

Tags: customchannels.list
"""
from __future__ import print_function

__author__ = '[email protected] (Sérgio Gomes)'

Expand Down Expand Up @@ -54,20 +55,20 @@ def main(argv):
result = request.execute()
custom_channels = result['items']
for custom_channel in custom_channels:
print ('Custom channel with id "%s" and name "%s" was found. '
% (custom_channel['id'], custom_channel['name']))
print(('Custom channel with id "%s" and name "%s" was found. '
% (custom_channel['id'], custom_channel['name'])))

if 'targetingInfo' in custom_channel:
print ' Targeting info:'
print(' Targeting info:')
targeting_info = custom_channel['targetingInfo']
if 'adsAppearOn' in targeting_info:
print ' Ads appear on: %s' % targeting_info['adsAppearOn']
print(' Ads appear on: %s' % targeting_info['adsAppearOn'])
if 'location' in targeting_info:
print ' Location: %s' % targeting_info['location']
print(' Location: %s' % targeting_info['location'])
if 'description' in targeting_info:
print ' Description: %s' % targeting_info['description']
print(' Description: %s' % targeting_info['description'])
if 'siteLanguage' in targeting_info:
print ' Site language: %s' % targeting_info['siteLanguage']
print(' Site language: %s' % targeting_info['siteLanguage'])

request = service.customchannels().list_next(request, result)

Expand Down
15 changes: 8 additions & 7 deletions samples/adexchangeseller/get_all_custom_channels_for_ad_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

Tags: customchannels.list
"""
from __future__ import print_function

__author__ = '[email protected] (Sérgio Gomes)'

Expand Down Expand Up @@ -62,20 +63,20 @@ def main(argv):
result = request.execute()
custom_channels = result['items']
for custom_channel in custom_channels:
print ('Custom channel with code "%s" and name "%s" was found. '
% (custom_channel['code'], custom_channel['name']))
print(('Custom channel with code "%s" and name "%s" was found. '
% (custom_channel['code'], custom_channel['name'])))

if 'targetingInfo' in custom_channel:
print ' Targeting info:'
print(' Targeting info:')
targeting_info = custom_channel['targetingInfo']
if 'adsAppearOn' in targeting_info:
print ' Ads appear on: %s' % targeting_info['adsAppearOn']
print(' Ads appear on: %s' % targeting_info['adsAppearOn'])
if 'location' in targeting_info:
print ' Location: %s' % targeting_info['location']
print(' Location: %s' % targeting_info['location'])
if 'description' in targeting_info:
print ' Description: %s' % targeting_info['description']
print(' Description: %s' % targeting_info['description'])
if 'siteLanguage' in targeting_info:
print ' Site language: %s' % targeting_info['siteLanguage']
print(' Site language: %s' % targeting_info['siteLanguage'])

request = service.customchannels().list_next(request, result)

Expand Down
7 changes: 4 additions & 3 deletions samples/adexchangeseller/get_all_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

Tags: metadata.dimensions.list
"""
from __future__ import print_function

__author__ = '[email protected] (Sérgio Gomes)'

Expand All @@ -43,10 +44,10 @@ def main(argv):
if 'items' in result:
dimensions = result['items']
for dimension in dimensions:
print ('Dimension id "%s" for product(s): [%s] was found. '
% (dimension['id'], ', '.join(dimension['supportedProducts'])))
print(('Dimension id "%s" for product(s): [%s] was found. '
% (dimension['id'], ', '.join(dimension['supportedProducts']))))
else:
print 'No dimensions found!'
print('No dimensions found!')
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
Expand Down
Loading