imported patch reserved
diff --git a/apiclient/discovery.py b/apiclient/discovery.py
index 6f0f752..2965f3c 100644
--- a/apiclient/discovery.py
+++ b/apiclient/discovery.py
@@ -58,6 +58,16 @@
STACK_QUERY_PARAMETERS = ['trace', 'fields', 'pp', 'prettyPrint', 'userIp',
'userip', 'strict']
+RESERVED_WORDS = [ 'and', 'assert', 'break', 'class', 'continue', 'def', 'del',
+ 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from',
+ 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or',
+ 'pass', 'print', 'raise', 'return', 'try', 'while' ]
+
+def _fix_method_name(name):
+ if name in RESERVED_WORDS:
+ return name + '_'
+ else:
+ return name
def _write_headers(self):
# Utility no-op method for multipart media handling
@@ -260,6 +270,7 @@
self._requestBuilder = requestBuilder
def createMethod(theclass, methodName, methodDesc, futureDesc):
+ methodName = _fix_method_name(methodName)
pathUrl = methodDesc['path']
httpMethod = methodDesc['httpMethod']
methodId = methodDesc['id']
@@ -463,6 +474,7 @@
setattr(theclass, methodName, method)
def createNextMethod(theclass, methodName, methodDesc, futureDesc):
+ methodName = _fix_method_name(methodName)
methodId = methodDesc['id'] + '.next'
def methodNext(self, previous):
@@ -520,6 +532,7 @@
if 'resources' in resourceDesc:
def createResourceMethod(theclass, methodName, methodDesc, futureDesc):
+ methodName = _fix_method_name(methodName)
def methodResource(self):
return createResource(self._http, self._baseUrl, self._model,
diff --git a/setup_oauth2client.py b/setup_oauth2client.py
new file mode 100644
index 0000000..ec87873
--- /dev/null
+++ b/setup_oauth2client.py
@@ -0,0 +1,73 @@
+# Copyright (C) 2010 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Setup script for oauth2client.
+
+Also installs included versions of third party libraries, if those libraries
+are not already installed.
+"""
+import setup_utils
+
+has_setuptools = False
+try:
+ from setuptools import setup
+ has_setuptools = True
+except ImportError:
+ from distutils.core import setup
+
+packages = [
+ 'oauth2client',
+]
+
+install_requires = []
+py_modules = []
+
+
+# (module to test for, install_requires to add if missing, packages to add if missing, py_modules to add if missing)
+REQUIREMENTS = [
+ ('httplib2', 'httplib2', 'httplib2', None),
+ ('gflags', 'python-gflags', None, ['gflags', 'gflags_validators']),
+ (['json', 'simplejson', 'django.utils'], 'simplejson', 'simplejson', None)
+]
+
+for import_name, requires, package, modules in REQUIREMENTS:
+ if setup_utils.is_missing(import_name):
+ if has_setuptools:
+ install_requires.append(requires)
+ else:
+ if package is not None:
+ packages.append(package)
+ else:
+ py_modules.extend(modules)
+
+
+long_desc = """The oauth2client is a client library for OAuth 2.0."""
+
+setup(name="oauth2client",
+ version="1.0beta2",
+ description="OAuth 2.0 client library",
+ long_description=long_desc,
+ author="Joe Gregorio",
+ author_email="jcgregorio@google.com",
+ url="http://code.google.com/p/google-api-python-client/",
+ install_requires=install_requires,
+ packages=packages,
+ py_modules=py_modules,
+ license="Apache 2.0",
+ keywords="google oauth 2.0 http client",
+ classifiers=['Development Status :: 4 - Beta',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Apache Software License',
+ 'Operating System :: POSIX',
+ 'Topic :: Internet :: WWW/HTTP'])
diff --git a/tests/data/zoo.json b/tests/data/zoo.json
index 9314928..1475704 100644
--- a/tests/data/zoo.json
+++ b/tests/data/zoo.json
@@ -190,6 +190,25 @@
}
}
},
+ "global": {
+ "resources": {
+ "print": {
+ "methods": {
+ "assert": {
+ "path": "global/print/assert",
+ "id": "zoo.animals.mine",
+ "httpMethod": "GET",
+ "parameters": {
+ "max-results": {
+ "location": "query",
+ "required": false
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"animals": {
"methods": {
"crossbreed": {
diff --git a/tests/test_discovery.py b/tests/test_discovery.py
index f8c45c1..06bbbb8 100644
--- a/tests/test_discovery.py
+++ b/tests/test_discovery.py
@@ -188,6 +188,14 @@
q = parse_qs(parsed[4])
self.assertEqual(q['max-results'], ['5'])
+ def test_methods_with_reserved_names(self):
+ self.http = HttpMock(datafile('zoo.json'), {'status': '200'})
+ zoo = build('zoo', 'v1', self.http)
+ self.assertTrue(getattr(zoo, 'animals'))
+ request = zoo.global_().print_().assert_(max_results="5")
+ parsed = urlparse.urlparse(request.uri)
+ self.assertEqual(parsed[2], '/zoo/global/print/assert')
+
def test_top_level_functions(self):
self.http = HttpMock(datafile('zoo.json'), {'status': '200'})
zoo = build('zoo', 'v1', self.http)