Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 1 | # Copyright (C) 2010 Google Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | """Client for discovery based APIs |
| 16 | |
| 17 | A client library for Google's discovery |
| 18 | based APIs. |
| 19 | """ |
| 20 | |
| 21 | __author__ = 'jcgregorio@google.com (Joe Gregorio)' |
| 22 | |
| 23 | |
| 24 | import httplib2 |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 25 | import logging |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 26 | import os |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 27 | import re |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 28 | import uritemplate |
Joe Gregorio | fe695fb | 2010-08-30 12:04:04 -0400 | [diff] [blame] | 29 | import urllib |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 30 | import urlparse |
ade@google.com | c5eb46f | 2010-09-27 23:35:39 +0100 | [diff] [blame] | 31 | try: |
| 32 | from urlparse import parse_qsl |
| 33 | except ImportError: |
| 34 | from cgi import parse_qsl |
Joe Gregorio | 5f087cf | 2010-09-20 16:08:07 -0400 | [diff] [blame] | 35 | from apiclient.http import HttpRequest |
Joe Gregorio | f658e32 | 2010-10-11 15:40:31 -0400 | [diff] [blame^] | 36 | from apiclient.json import simplejson |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 37 | |
Tom Miller | 05cd4f5 | 2010-10-06 11:09:12 -0700 | [diff] [blame] | 38 | class Error(Exception): |
| 39 | """Base error for this module.""" |
Joe Gregorio | 41cf797 | 2010-08-18 15:21:06 -0400 | [diff] [blame] | 40 | pass |
| 41 | |
Joe Gregorio | 3bbbf66 | 2010-08-30 16:41:53 -0400 | [diff] [blame] | 42 | |
Tom Miller | 05cd4f5 | 2010-10-06 11:09:12 -0700 | [diff] [blame] | 43 | class HttpError(Error): |
| 44 | """HTTP data was invalid or unexpected.""" |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 45 | pass |
| 46 | |
Tom Miller | 05cd4f5 | 2010-10-06 11:09:12 -0700 | [diff] [blame] | 47 | |
| 48 | class UnknownLinkType(Error): |
| 49 | """Link type unknown or unexpected.""" |
| 50 | pass |
| 51 | |
| 52 | |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 53 | DISCOVERY_URI = ('http://www.googleapis.com/discovery/0.1/describe' |
| 54 | '{?api,apiVersion}') |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 55 | |
| 56 | |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 57 | def key2param(key): |
| 58 | """ |
| 59 | max-results -> max_results |
| 60 | """ |
| 61 | result = [] |
| 62 | key = list(key) |
| 63 | if not key[0].isalpha(): |
| 64 | result.append('x') |
| 65 | for c in key: |
| 66 | if c.isalnum(): |
| 67 | result.append(c) |
| 68 | else: |
| 69 | result.append('_') |
| 70 | |
| 71 | return ''.join(result) |
| 72 | |
| 73 | |
| 74 | class JsonModel(object): |
Joe Gregorio | 41cf797 | 2010-08-18 15:21:06 -0400 | [diff] [blame] | 75 | |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 76 | def request(self, headers, path_params, query_params, body_value): |
| 77 | query = self.build_query(query_params) |
Joe Gregorio | ba9ea7f | 2010-08-19 15:49:04 -0400 | [diff] [blame] | 78 | headers['accept'] = 'application/json' |
Joe Gregorio | 6b2e5dc | 2010-09-14 15:11:03 -0400 | [diff] [blame] | 79 | if 'user-agent' in headers: |
| 80 | headers['user-agent'] += ' ' |
| 81 | else: |
| 82 | headers['user-agent'] = '' |
Joe Gregorio | e936958 | 2010-09-14 15:17:28 -0400 | [diff] [blame] | 83 | headers['user-agent'] += 'google-api-python-client/1.0' |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 84 | if body_value is None: |
| 85 | return (headers, path_params, query, None) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 86 | else: |
Joe Gregorio | 46b0ff6 | 2010-10-09 22:13:12 -0400 | [diff] [blame] | 87 | if len(body_value) == 1 and 'data' in body_value: |
| 88 | model = body_value |
| 89 | else: |
| 90 | model = {'data': body_value} |
Joe Gregorio | ba9ea7f | 2010-08-19 15:49:04 -0400 | [diff] [blame] | 91 | headers['content-type'] = 'application/json' |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 92 | return (headers, path_params, query, simplejson.dumps(model)) |
| 93 | |
| 94 | def build_query(self, params): |
jcgregorio@google.com | e3c8b6d | 2010-10-07 19:34:54 -0400 | [diff] [blame] | 95 | params.update({'alt': 'json'}) |
Joe Gregorio | fe695fb | 2010-08-30 12:04:04 -0400 | [diff] [blame] | 96 | astuples = [] |
| 97 | for key, value in params.iteritems(): |
| 98 | if getattr(value, 'encode', False) and callable(value.encode): |
| 99 | value = value.encode('utf-8') |
| 100 | astuples.append((key, value)) |
| 101 | return '?' + urllib.urlencode(astuples) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 102 | |
| 103 | def response(self, resp, content): |
Joe Gregorio | 41cf797 | 2010-08-18 15:21:06 -0400 | [diff] [blame] | 104 | # Error handling is TBD, for example, do we retry |
| 105 | # for some operation/error combinations? |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 106 | if resp.status < 300: |
ade@google.com | 9d821b0 | 2010-10-11 03:33:51 -0700 | [diff] [blame] | 107 | if resp.status == 204: |
| 108 | # A 204: No Content response should be treated differently to all the other success states |
| 109 | return simplejson.loads('{}') |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 110 | return simplejson.loads(content)['data'] |
| 111 | else: |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 112 | logging.debug('Content from bad request was: %s' % content) |
Joe Gregorio | c5c5a37 | 2010-09-22 11:42:32 -0400 | [diff] [blame] | 113 | if resp.get('content-type', '') != 'application/json': |
Joe Gregorio | fbf9d0d | 2010-08-18 16:50:47 -0400 | [diff] [blame] | 114 | raise HttpError('%d %s' % (resp.status, resp.reason)) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 115 | else: |
| 116 | raise HttpError(simplejson.loads(content)['error']) |
| 117 | |
| 118 | |
Joe Gregorio | c204b64 | 2010-09-21 12:01:23 -0400 | [diff] [blame] | 119 | def build(serviceName, version, http=None, |
Joe Gregorio | 00cf1d9 | 2010-09-27 09:22:03 -0400 | [diff] [blame] | 120 | discoveryServiceUrl=DISCOVERY_URI, developerKey=None, model=JsonModel()): |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 121 | params = { |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 122 | 'api': serviceName, |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 123 | 'apiVersion': version |
| 124 | } |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 125 | |
Joe Gregorio | c204b64 | 2010-09-21 12:01:23 -0400 | [diff] [blame] | 126 | if http is None: |
| 127 | http = httplib2.Http() |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 128 | requested_url = uritemplate.expand(discoveryServiceUrl, params) |
| 129 | logging.info('URL being requested: %s' % requested_url) |
| 130 | resp, content = http.request(requested_url) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 131 | d = simplejson.loads(content) |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 132 | service = d['data'][serviceName][version] |
| 133 | |
Joe Gregorio | 3bbbf66 | 2010-08-30 16:41:53 -0400 | [diff] [blame] | 134 | fn = os.path.join(os.path.dirname(__file__), "contrib", |
| 135 | serviceName, "future.json") |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 136 | f = file(fn, "r") |
| 137 | d = simplejson.load(f) |
| 138 | f.close() |
| 139 | future = d['data'][serviceName][version]['resources'] |
Joe Gregorio | a2f56e7 | 2010-09-09 15:15:56 -0400 | [diff] [blame] | 140 | auth_discovery = d['data'][serviceName][version]['auth'] |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 141 | |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 142 | base = service['baseUrl'] |
| 143 | resources = service['resources'] |
| 144 | |
| 145 | class Service(object): |
| 146 | """Top level interface for a service""" |
| 147 | |
| 148 | def __init__(self, http=http): |
| 149 | self._http = http |
| 150 | self._baseUrl = base |
| 151 | self._model = model |
Joe Gregorio | 00cf1d9 | 2010-09-27 09:22:03 -0400 | [diff] [blame] | 152 | self._developerKey = developerKey |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 153 | |
Joe Gregorio | a2f56e7 | 2010-09-09 15:15:56 -0400 | [diff] [blame] | 154 | def auth_discovery(self): |
| 155 | return auth_discovery |
| 156 | |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 157 | def createMethod(theclass, methodName, methodDesc, futureDesc): |
Joe Gregorio | 41cf797 | 2010-08-18 15:21:06 -0400 | [diff] [blame] | 158 | |
Joe Gregorio | 59cd951 | 2010-10-04 12:46:46 -0400 | [diff] [blame] | 159 | def method(self): |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 160 | return createResource(self._http, self._baseUrl, self._model, |
Joe Gregorio | 00cf1d9 | 2010-09-27 09:22:03 -0400 | [diff] [blame] | 161 | methodName, self._developerKey, methodDesc, futureDesc) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 162 | |
| 163 | setattr(method, '__doc__', 'A description of how to use this function') |
| 164 | setattr(theclass, methodName, method) |
| 165 | |
| 166 | for methodName, methodDesc in resources.iteritems(): |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 167 | createMethod(Service, methodName, methodDesc, future[methodName]) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 168 | return Service() |
| 169 | |
| 170 | |
Joe Gregorio | 00cf1d9 | 2010-09-27 09:22:03 -0400 | [diff] [blame] | 171 | def createResource(http, baseUrl, model, resourceName, developerKey, |
| 172 | resourceDesc, futureDesc): |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 173 | |
| 174 | class Resource(object): |
| 175 | """A class for interacting with a resource.""" |
| 176 | |
| 177 | def __init__(self): |
| 178 | self._http = http |
| 179 | self._baseUrl = baseUrl |
| 180 | self._model = model |
Joe Gregorio | 00cf1d9 | 2010-09-27 09:22:03 -0400 | [diff] [blame] | 181 | self._developerKey = developerKey |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 182 | |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 183 | def createMethod(theclass, methodName, methodDesc, futureDesc): |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 184 | pathUrl = methodDesc['pathUrl'] |
| 185 | pathUrl = re.sub(r'\{', r'{+', pathUrl) |
| 186 | httpMethod = methodDesc['httpMethod'] |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 187 | |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 188 | argmap = {} |
| 189 | if httpMethod in ['PUT', 'POST']: |
| 190 | argmap['body'] = 'body' |
| 191 | |
| 192 | |
| 193 | required_params = [] # Required parameters |
| 194 | pattern_params = {} # Parameters that must match a regex |
| 195 | query_params = [] # Parameters that will be used in the query string |
| 196 | path_params = {} # Parameters that will be used in the base URL |
Joe Gregorio | 4292c6e | 2010-09-09 14:32:43 -0400 | [diff] [blame] | 197 | if 'parameters' in methodDesc: |
| 198 | for arg, desc in methodDesc['parameters'].iteritems(): |
| 199 | param = key2param(arg) |
| 200 | argmap[param] = arg |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 201 | |
Joe Gregorio | 4292c6e | 2010-09-09 14:32:43 -0400 | [diff] [blame] | 202 | if desc.get('pattern', ''): |
| 203 | pattern_params[param] = desc['pattern'] |
| 204 | if desc.get('required', False): |
| 205 | required_params.append(param) |
| 206 | if desc.get('parameterType') == 'query': |
| 207 | query_params.append(param) |
| 208 | if desc.get('parameterType') == 'path': |
| 209 | path_params[param] = param |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 210 | |
| 211 | def method(self, **kwargs): |
| 212 | for name in kwargs.iterkeys(): |
| 213 | if name not in argmap: |
| 214 | raise TypeError('Got an unexpected keyword argument "%s"' % name) |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 215 | |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 216 | for name in required_params: |
Joe Gregorio | fbf9d0d | 2010-08-18 16:50:47 -0400 | [diff] [blame] | 217 | if name not in kwargs: |
| 218 | raise TypeError('Missing required parameter "%s"' % name) |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 219 | |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 220 | for name, regex in pattern_params.iteritems(): |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 221 | if name in kwargs: |
| 222 | if re.match(regex, kwargs[name]) is None: |
Joe Gregorio | 3bbbf66 | 2010-08-30 16:41:53 -0400 | [diff] [blame] | 223 | raise TypeError( |
| 224 | 'Parameter "%s" value "%s" does not match the pattern "%s"' % |
| 225 | (name, kwargs[name], regex)) |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 226 | |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 227 | actual_query_params = {} |
| 228 | actual_path_params = {} |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 229 | for key, value in kwargs.iteritems(): |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 230 | if key in query_params: |
| 231 | actual_query_params[argmap[key]] = value |
| 232 | if key in path_params: |
| 233 | actual_path_params[argmap[key]] = value |
| 234 | body_value = kwargs.get('body', None) |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 235 | |
Joe Gregorio | 00cf1d9 | 2010-09-27 09:22:03 -0400 | [diff] [blame] | 236 | if self._developerKey: |
| 237 | actual_query_params['key'] = self._developerKey |
| 238 | |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 239 | headers = {} |
Joe Gregorio | 3bbbf66 | 2010-08-30 16:41:53 -0400 | [diff] [blame] | 240 | headers, params, query, body = self._model.request(headers, |
| 241 | actual_path_params, actual_query_params, body_value) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 242 | |
ade@google.com | 7ebb2ca | 2010-09-29 16:42:15 +0100 | [diff] [blame] | 243 | # TODO(ade) This exists to fix a bug in V1 of the Buzz discovery document. |
| 244 | # Base URLs should not contain any path elements. If they do then urlparse.urljoin will strip them out |
| 245 | # This results in an incorrect URL which returns a 404 |
| 246 | url_result = urlparse.urlsplit(self._baseUrl) |
| 247 | new_base_url = url_result.scheme + '://' + url_result.netloc |
| 248 | |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 249 | expanded_url = uritemplate.expand(pathUrl, params) |
ade@google.com | 7ebb2ca | 2010-09-29 16:42:15 +0100 | [diff] [blame] | 250 | url = urlparse.urljoin(new_base_url, url_result.path + expanded_url + query) |
Joe Gregorio | fbf9d0d | 2010-08-18 16:50:47 -0400 | [diff] [blame] | 251 | |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 252 | logging.info('URL being requested: %s' % url) |
Joe Gregorio | 5f087cf | 2010-09-20 16:08:07 -0400 | [diff] [blame] | 253 | return HttpRequest(self._http, url, method=httpMethod, body=body, |
| 254 | headers=headers, postproc=self._model.response) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 255 | |
| 256 | docs = ['A description of how to use this function\n\n'] |
| 257 | for arg in argmap.iterkeys(): |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 258 | required = "" |
| 259 | if arg in required_params: |
| 260 | required = " (required)" |
| 261 | docs.append('%s - A parameter%s\n' % (arg, required)) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 262 | |
| 263 | setattr(method, '__doc__', ''.join(docs)) |
| 264 | setattr(theclass, methodName, method) |
| 265 | |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 266 | def createNextMethod(theclass, methodName, methodDesc): |
| 267 | |
| 268 | def method(self, previous): |
| 269 | """ |
| 270 | Takes a single argument, 'body', which is the results |
| 271 | from the last call, and returns the next set of items |
| 272 | in the collection. |
| 273 | |
| 274 | Returns None if there are no more items in |
| 275 | the collection. |
| 276 | """ |
| 277 | if methodDesc['type'] != 'uri': |
| 278 | raise UnknownLinkType(methodDesc['type']) |
| 279 | |
| 280 | try: |
| 281 | p = previous |
| 282 | for key in methodDesc['location']: |
| 283 | p = p[key] |
| 284 | url = p |
Joe Gregorio | c5c5a37 | 2010-09-22 11:42:32 -0400 | [diff] [blame] | 285 | except (KeyError, TypeError): |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 286 | return None |
| 287 | |
Joe Gregorio | 00cf1d9 | 2010-09-27 09:22:03 -0400 | [diff] [blame] | 288 | if self._developerKey: |
| 289 | parsed = list(urlparse.urlparse(url)) |
ade@google.com | c5eb46f | 2010-09-27 23:35:39 +0100 | [diff] [blame] | 290 | q = parse_qsl(parsed[4]) |
Joe Gregorio | 00cf1d9 | 2010-09-27 09:22:03 -0400 | [diff] [blame] | 291 | q.append(('key', self._developerKey)) |
| 292 | parsed[4] = urllib.urlencode(q) |
| 293 | url = urlparse.urlunparse(parsed) |
| 294 | |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 295 | headers = {} |
| 296 | headers, params, query, body = self._model.request(headers, {}, {}, None) |
| 297 | |
| 298 | logging.info('URL being requested: %s' % url) |
| 299 | resp, content = self._http.request(url, method='GET', headers=headers) |
| 300 | |
Joe Gregorio | 5f087cf | 2010-09-20 16:08:07 -0400 | [diff] [blame] | 301 | return HttpRequest(self._http, url, method='GET', |
| 302 | headers=headers, postproc=self._model.response) |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 303 | |
| 304 | setattr(theclass, methodName, method) |
| 305 | |
| 306 | # Add basic methods to Resource |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 307 | for methodName, methodDesc in resourceDesc['methods'].iteritems(): |
Joe Gregorio | 3bbbf66 | 2010-08-30 16:41:53 -0400 | [diff] [blame] | 308 | future = futureDesc['methods'].get(methodName, {}) |
| 309 | createMethod(Resource, methodName, methodDesc, future) |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 310 | |
| 311 | # Add <m>_next() methods to Resource |
| 312 | for methodName, methodDesc in futureDesc['methods'].iteritems(): |
| 313 | if 'next' in methodDesc and methodName in resourceDesc['methods']: |
| 314 | createNextMethod(Resource, methodName + "_next", methodDesc['next']) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 315 | |
| 316 | return Resource() |