diff --git a/apiclient/discovery.py b/apiclient/discovery.py index b307a53..bbd9d68 100644 --- a/apiclient/discovery.py +++ b/apiclient/discovery.py @@ -164,7 +164,7 @@ def build_from_document( auth_discovery = {} if model is None: - features = service.get('features', ['dataWrapper']) + features = service.get('features', []) model = JsonModel('dataWrapper' in features) resource = createResource(http, base, model, requestBuilder, developerKey, service, future) @@ -192,7 +192,10 @@ def _cast(value, schema_type): A string representation of 'value' based on the schema_type. """ if schema_type == 'string': - return str(value) + if type(value) == type('') or type(value) == type(u''): + return value + else: + return str(value) elif schema_type == 'integer': return str(int(value)) elif schema_type == 'number': @@ -200,7 +203,10 @@ def _cast(value, schema_type): elif schema_type == 'boolean': return str(bool(value)).lower() else: - return str(value) + if type(value) == type('') or type(value) == type(u''): + return value + else: + return str(value) def createResource(http, baseUrl, model, requestBuilder, diff --git a/samples/moderator/moderator.py b/samples/moderator/moderator.py index 93e3ff6..bdada76 100644 --- a/samples/moderator/moderator.py +++ b/samples/moderator/moderator.py @@ -28,7 +28,7 @@ def main(): storage = Storage('moderator.dat') credentials = storage.get() if credentials is None or credentials.invalid == True: - moderator_discovery = build("moderator", "v1").auth_discovery() + moderator_discovery = build('moderator', 'v1').auth_discovery() flow = FlowThreeLegged(moderator_discovery, consumer_key='anonymous', @@ -44,53 +44,45 @@ def main(): http = httplib2.Http() http = credentials.authorize(http) - p = build("moderator", "v1", http=http) + p = build('moderator', 'v1', http=http) series_body = { - "data": { - "description": "Share and rank tips for eating healthy and cheap!", - "name": "Eating Healthy & Cheap", - "videoSubmissionAllowed": False - } + 'description': 'Share and rank tips for eating healthy and cheap!', + 'name': 'Eating Healthy & Cheap', + 'videoSubmissionAllowed': False } try: series = p.series().insert(body=series_body).execute() - print "Created a new series" + print 'Created a new series' topic_body = { - "data": { - "description": "Share your ideas on eating healthy!", - "name": "Ideas", - "presenter": "liz" - } + 'description': 'Share your ideas on eating healthy!', + 'name': 'Ideas', + 'presenter': 'liz' } topic = p.topics().insert(seriesId=series['id']['seriesId'], body=topic_body).execute() - print "Created a new topic" + print 'Created a new topic' submission_body = { - "data": { - "attachmentUrl": "http://www.youtube.com/watch?v=1a1wyc5Xxpg", - "attribution": { - "displayName": "Bashan", - "location": "Bainbridge Island, WA" - }, - "text": "Charlie Ayers @ Google" - } + 'attachmentUrl': 'http://www.youtube.com/watch?v=1a1wyc5Xxpg', + 'attribution': { + 'displayName': 'Bashan', + 'location': 'Bainbridge Island, WA' + }, + 'text': 'Charlie Ayers @ Google' } submission = p.submissions().insert(seriesId=topic['id']['seriesId'], topicId=topic['id']['topicId'], body=submission_body).execute() - print "Inserted a new submisson on the topic" + print 'Inserted a new submisson on the topic' vote_body = { - "data": { - "vote": "PLUS" - } + 'vote': 'PLUS' } p.votes().insert(seriesId=topic['id']['seriesId'], submissionId=submission['id']['submissionId'], body=vote_body) - print "Voted on the submission" + print 'Voted on the submission' except CredentialsInvalidError: print 'Your credentials are no longer valid.' print 'Please re-run this application to re-authorize.' diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 2e0104c..f682a11 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -1,4 +1,5 @@ #!/usr/bin/python2.4 +# -*- coding: utf-8 -*- # # Copyright 2010 Google Inc. # @@ -100,6 +101,7 @@ class Discovery(unittest.TestCase): self._check_query_types(request) request = zoo.query(q="foo", i=1, n=1, b=False, a=[1,2,3], o={'a':1}, e='bar') self._check_query_types(request) + request = zoo.query(q="foo", i="1", n="1", b="", a=[1,2,3], o={'a':1}, e='bar') self._check_query_types(request) @@ -134,7 +136,8 @@ class Discovery(unittest.TestCase): self.http = HttpMock(datafile('zoo.json'), {'status': '200'}) zoo = build('zoo', 'v1', self.http) self.assertTrue(getattr(zoo, 'animals')) - request = zoo.animals().list(name="bat", projection="size") + + request = zoo.animals().list(name='bat', projection="size") parsed = urlparse.urlparse(request.uri) q = parse_qs(parsed[4]) self.assertEqual(q['name'], ['bat'])