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 | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 35 | |
Joe Gregorio | b843fa2 | 2010-12-13 16:26:07 -0500 | [diff] [blame] | 36 | from http import HttpRequest |
Joe Gregorio | 034e700 | 2010-12-15 08:45:03 -0500 | [diff] [blame] | 37 | from anyjson import simplejson |
Joe Gregorio | b843fa2 | 2010-12-13 16:26:07 -0500 | [diff] [blame] | 38 | from model import JsonModel |
Joe Gregorio | b843fa2 | 2010-12-13 16:26:07 -0500 | [diff] [blame] | 39 | from errors import UnknownLinkType |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 40 | |
Joe Gregorio | bc2ff9b | 2010-11-08 09:20:48 -0500 | [diff] [blame] | 41 | URITEMPLATE = re.compile('{[^}]*}') |
| 42 | VARNAME = re.compile('[a-zA-Z0-9_-]+') |
Joe Gregorio | 2379ecc | 2010-10-26 10:51:28 -0400 | [diff] [blame] | 43 | DISCOVERY_URI = ('https://www.googleapis.com/discovery/v0.2beta1/describe/' |
| 44 | '{api}/{apiVersion}') |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 45 | |
| 46 | |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 47 | def key2param(key): |
| 48 | """ |
| 49 | max-results -> max_results |
| 50 | """ |
| 51 | result = [] |
| 52 | key = list(key) |
| 53 | if not key[0].isalpha(): |
| 54 | result.append('x') |
| 55 | for c in key: |
| 56 | if c.isalnum(): |
| 57 | result.append(c) |
| 58 | else: |
| 59 | result.append('_') |
| 60 | |
| 61 | return ''.join(result) |
| 62 | |
| 63 | |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 64 | def build(serviceName, version, |
Joe Gregorio | 3fada33 | 2011-01-07 17:07:45 -0500 | [diff] [blame^] | 65 | http=None, |
| 66 | discoveryServiceUrl=DISCOVERY_URI, |
| 67 | developerKey=None, |
| 68 | model=JsonModel(), |
| 69 | requestBuilder=HttpRequest): |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 70 | params = { |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 71 | 'api': serviceName, |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 72 | 'apiVersion': version |
| 73 | } |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 74 | |
Joe Gregorio | c204b64 | 2010-09-21 12:01:23 -0400 | [diff] [blame] | 75 | if http is None: |
| 76 | http = httplib2.Http() |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 77 | requested_url = uritemplate.expand(discoveryServiceUrl, params) |
| 78 | logging.info('URL being requested: %s' % requested_url) |
| 79 | resp, content = http.request(requested_url) |
Joe Gregorio | 2379ecc | 2010-10-26 10:51:28 -0400 | [diff] [blame] | 80 | service = simplejson.loads(content) |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 81 | |
Joe Gregorio | 3bbbf66 | 2010-08-30 16:41:53 -0400 | [diff] [blame] | 82 | fn = os.path.join(os.path.dirname(__file__), "contrib", |
| 83 | serviceName, "future.json") |
Joe Gregorio | 2379ecc | 2010-10-26 10:51:28 -0400 | [diff] [blame] | 84 | try: |
| 85 | f = file(fn, "r") |
| 86 | d = simplejson.load(f) |
| 87 | f.close() |
| 88 | future = d['resources'] |
| 89 | auth_discovery = d['auth'] |
| 90 | except IOError: |
| 91 | future = {} |
| 92 | auth_discovery = {} |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 93 | |
Joe Gregorio | 2379ecc | 2010-10-26 10:51:28 -0400 | [diff] [blame] | 94 | base = urlparse.urljoin(discoveryServiceUrl, service['restBasePath']) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 95 | resources = service['resources'] |
| 96 | |
| 97 | class Service(object): |
| 98 | """Top level interface for a service""" |
| 99 | |
| 100 | def __init__(self, http=http): |
| 101 | self._http = http |
| 102 | self._baseUrl = base |
| 103 | self._model = model |
Joe Gregorio | 00cf1d9 | 2010-09-27 09:22:03 -0400 | [diff] [blame] | 104 | self._developerKey = developerKey |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 105 | self._requestBuilder = requestBuilder |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 106 | |
Joe Gregorio | a2f56e7 | 2010-09-09 15:15:56 -0400 | [diff] [blame] | 107 | def auth_discovery(self): |
| 108 | return auth_discovery |
| 109 | |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 110 | def createMethod(theclass, methodName, methodDesc, futureDesc): |
Joe Gregorio | 41cf797 | 2010-08-18 15:21:06 -0400 | [diff] [blame] | 111 | |
Joe Gregorio | 59cd951 | 2010-10-04 12:46:46 -0400 | [diff] [blame] | 112 | def method(self): |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 113 | return createResource(self._http, self._baseUrl, self._model, |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 114 | self._requestBuilder, methodName, |
| 115 | self._developerKey, methodDesc, futureDesc) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 116 | |
| 117 | setattr(method, '__doc__', 'A description of how to use this function') |
Joe Gregorio | 20cfcda | 2010-10-26 11:58:08 -0400 | [diff] [blame] | 118 | setattr(method, '__is_resource__', True) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 119 | setattr(theclass, methodName, method) |
| 120 | |
| 121 | for methodName, methodDesc in resources.iteritems(): |
Joe Gregorio | 2379ecc | 2010-10-26 10:51:28 -0400 | [diff] [blame] | 122 | createMethod(Service, methodName, methodDesc, future.get(methodName, {})) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 123 | return Service() |
| 124 | |
| 125 | |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 126 | def createResource(http, baseUrl, model, requestBuilder, resourceName, |
| 127 | developerKey, resourceDesc, futureDesc): |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 128 | |
| 129 | class Resource(object): |
| 130 | """A class for interacting with a resource.""" |
| 131 | |
| 132 | def __init__(self): |
| 133 | self._http = http |
| 134 | self._baseUrl = baseUrl |
| 135 | self._model = model |
Joe Gregorio | 00cf1d9 | 2010-09-27 09:22:03 -0400 | [diff] [blame] | 136 | self._developerKey = developerKey |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 137 | self._requestBuilder = requestBuilder |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 138 | |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 139 | def createMethod(theclass, methodName, methodDesc, futureDesc): |
Joe Gregorio | 2379ecc | 2010-10-26 10:51:28 -0400 | [diff] [blame] | 140 | pathUrl = methodDesc['restPath'] |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 141 | pathUrl = re.sub(r'\{', r'{+', pathUrl) |
| 142 | httpMethod = methodDesc['httpMethod'] |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 143 | methodId = methodDesc['rpcMethod'] |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 144 | |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 145 | argmap = {} |
| 146 | if httpMethod in ['PUT', 'POST']: |
| 147 | argmap['body'] = 'body' |
| 148 | |
| 149 | |
| 150 | required_params = [] # Required parameters |
| 151 | pattern_params = {} # Parameters that must match a regex |
| 152 | query_params = [] # Parameters that will be used in the query string |
| 153 | path_params = {} # Parameters that will be used in the base URL |
Joe Gregorio | 4292c6e | 2010-09-09 14:32:43 -0400 | [diff] [blame] | 154 | if 'parameters' in methodDesc: |
| 155 | for arg, desc in methodDesc['parameters'].iteritems(): |
| 156 | param = key2param(arg) |
| 157 | argmap[param] = arg |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 158 | |
Joe Gregorio | 4292c6e | 2010-09-09 14:32:43 -0400 | [diff] [blame] | 159 | if desc.get('pattern', ''): |
| 160 | pattern_params[param] = desc['pattern'] |
| 161 | if desc.get('required', False): |
| 162 | required_params.append(param) |
Joe Gregorio | 2379ecc | 2010-10-26 10:51:28 -0400 | [diff] [blame] | 163 | if desc.get('restParameterType') == 'query': |
Joe Gregorio | 4292c6e | 2010-09-09 14:32:43 -0400 | [diff] [blame] | 164 | query_params.append(param) |
Joe Gregorio | 2379ecc | 2010-10-26 10:51:28 -0400 | [diff] [blame] | 165 | if desc.get('restParameterType') == 'path': |
Joe Gregorio | 4292c6e | 2010-09-09 14:32:43 -0400 | [diff] [blame] | 166 | path_params[param] = param |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 167 | |
Joe Gregorio | bc2ff9b | 2010-11-08 09:20:48 -0500 | [diff] [blame] | 168 | for match in URITEMPLATE.finditer(pathUrl): |
| 169 | for namematch in VARNAME.finditer(match.group(0)): |
| 170 | name = key2param(namematch.group(0)) |
| 171 | path_params[name] = name |
| 172 | if name in query_params: |
| 173 | query_params.remove(name) |
| 174 | |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 175 | def method(self, **kwargs): |
| 176 | for name in kwargs.iterkeys(): |
| 177 | if name not in argmap: |
| 178 | raise TypeError('Got an unexpected keyword argument "%s"' % name) |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 179 | |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 180 | for name in required_params: |
Joe Gregorio | fbf9d0d | 2010-08-18 16:50:47 -0400 | [diff] [blame] | 181 | if name not in kwargs: |
| 182 | raise TypeError('Missing required parameter "%s"' % name) |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 183 | |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 184 | for name, regex in pattern_params.iteritems(): |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 185 | if name in kwargs: |
| 186 | if re.match(regex, kwargs[name]) is None: |
Joe Gregorio | 3bbbf66 | 2010-08-30 16:41:53 -0400 | [diff] [blame] | 187 | raise TypeError( |
| 188 | 'Parameter "%s" value "%s" does not match the pattern "%s"' % |
| 189 | (name, kwargs[name], regex)) |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 190 | |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 191 | actual_query_params = {} |
| 192 | actual_path_params = {} |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 193 | for key, value in kwargs.iteritems(): |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 194 | if key in query_params: |
| 195 | actual_query_params[argmap[key]] = value |
| 196 | if key in path_params: |
| 197 | actual_path_params[argmap[key]] = value |
| 198 | body_value = kwargs.get('body', None) |
Joe Gregorio | 21f1167 | 2010-08-18 17:23:17 -0400 | [diff] [blame] | 199 | |
Joe Gregorio | 00cf1d9 | 2010-09-27 09:22:03 -0400 | [diff] [blame] | 200 | if self._developerKey: |
| 201 | actual_query_params['key'] = self._developerKey |
| 202 | |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 203 | headers = {} |
Joe Gregorio | 3bbbf66 | 2010-08-30 16:41:53 -0400 | [diff] [blame] | 204 | headers, params, query, body = self._model.request(headers, |
| 205 | actual_path_params, actual_query_params, body_value) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 206 | |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 207 | # TODO(ade) This exists to fix a bug in V1 of the Buzz discovery |
| 208 | # document. Base URLs should not contain any path elements. If they do |
| 209 | # then urlparse.urljoin will strip them out This results in an incorrect |
| 210 | # URL which returns a 404 |
ade@google.com | 7ebb2ca | 2010-09-29 16:42:15 +0100 | [diff] [blame] | 211 | url_result = urlparse.urlsplit(self._baseUrl) |
| 212 | new_base_url = url_result.scheme + '://' + url_result.netloc |
| 213 | |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 214 | expanded_url = uritemplate.expand(pathUrl, params) |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 215 | url = urlparse.urljoin(new_base_url, |
| 216 | url_result.path + expanded_url + query) |
Joe Gregorio | fbf9d0d | 2010-08-18 16:50:47 -0400 | [diff] [blame] | 217 | |
ade@google.com | 850cf55 | 2010-08-20 23:24:56 +0100 | [diff] [blame] | 218 | logging.info('URL being requested: %s' % url) |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 219 | return self._requestBuilder(self._http, url, |
| 220 | method=httpMethod, body=body, |
| 221 | headers=headers, |
| 222 | postproc=self._model.response, |
| 223 | methodId=methodId) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 224 | |
| 225 | docs = ['A description of how to use this function\n\n'] |
| 226 | for arg in argmap.iterkeys(): |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 227 | required = "" |
| 228 | if arg in required_params: |
| 229 | required = " (required)" |
| 230 | docs.append('%s - A parameter%s\n' % (arg, required)) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 231 | |
| 232 | setattr(method, '__doc__', ''.join(docs)) |
| 233 | setattr(theclass, methodName, method) |
| 234 | |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 235 | def createNextMethod(theclass, methodName, methodDesc, futureDesc): |
| 236 | methodId = methodDesc['rpcMethod'] + '.next' |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 237 | |
| 238 | def method(self, previous): |
| 239 | """ |
| 240 | Takes a single argument, 'body', which is the results |
| 241 | from the last call, and returns the next set of items |
| 242 | in the collection. |
| 243 | |
| 244 | Returns None if there are no more items in |
| 245 | the collection. |
| 246 | """ |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 247 | if futureDesc['type'] != 'uri': |
| 248 | raise UnknownLinkType(futureDesc['type']) |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 249 | |
| 250 | try: |
| 251 | p = previous |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 252 | for key in futureDesc['location']: |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 253 | p = p[key] |
| 254 | url = p |
Joe Gregorio | c5c5a37 | 2010-09-22 11:42:32 -0400 | [diff] [blame] | 255 | except (KeyError, TypeError): |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 256 | return None |
| 257 | |
Joe Gregorio | 00cf1d9 | 2010-09-27 09:22:03 -0400 | [diff] [blame] | 258 | if self._developerKey: |
| 259 | parsed = list(urlparse.urlparse(url)) |
ade@google.com | c5eb46f | 2010-09-27 23:35:39 +0100 | [diff] [blame] | 260 | q = parse_qsl(parsed[4]) |
Joe Gregorio | 00cf1d9 | 2010-09-27 09:22:03 -0400 | [diff] [blame] | 261 | q.append(('key', self._developerKey)) |
| 262 | parsed[4] = urllib.urlencode(q) |
| 263 | url = urlparse.urlunparse(parsed) |
| 264 | |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 265 | headers = {} |
| 266 | headers, params, query, body = self._model.request(headers, {}, {}, None) |
| 267 | |
| 268 | logging.info('URL being requested: %s' % url) |
| 269 | resp, content = self._http.request(url, method='GET', headers=headers) |
| 270 | |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 271 | return self._requestBuilder(self._http, url, method='GET', |
| 272 | headers=headers, |
| 273 | postproc=self._model.response, |
| 274 | methodId=methodId) |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 275 | |
| 276 | setattr(theclass, methodName, method) |
| 277 | |
| 278 | # Add basic methods to Resource |
Joe Gregorio | 2379ecc | 2010-10-26 10:51:28 -0400 | [diff] [blame] | 279 | if 'methods' in resourceDesc: |
| 280 | for methodName, methodDesc in resourceDesc['methods'].iteritems(): |
| 281 | if futureDesc: |
| 282 | future = futureDesc['methods'].get(methodName, {}) |
| 283 | else: |
| 284 | future = None |
| 285 | createMethod(Resource, methodName, methodDesc, future) |
| 286 | |
| 287 | # Add in nested resources |
| 288 | if 'resources' in resourceDesc: |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 289 | |
Joe Gregorio | 2379ecc | 2010-10-26 10:51:28 -0400 | [diff] [blame] | 290 | def createMethod(theclass, methodName, methodDesc, futureDesc): |
| 291 | |
| 292 | def method(self): |
| 293 | return createResource(self._http, self._baseUrl, self._model, |
Joe Gregorio | 3fada33 | 2011-01-07 17:07:45 -0500 | [diff] [blame^] | 294 | self._requestBuilder, methodName, |
| 295 | self._developerKey, methodDesc, futureDesc) |
Joe Gregorio | 2379ecc | 2010-10-26 10:51:28 -0400 | [diff] [blame] | 296 | |
| 297 | setattr(method, '__doc__', 'A description of how to use this function') |
Joe Gregorio | 20cfcda | 2010-10-26 11:58:08 -0400 | [diff] [blame] | 298 | setattr(method, '__is_resource__', True) |
Joe Gregorio | 2379ecc | 2010-10-26 10:51:28 -0400 | [diff] [blame] | 299 | setattr(theclass, methodName, method) |
| 300 | |
| 301 | for methodName, methodDesc in resourceDesc['resources'].iteritems(): |
| 302 | if futureDesc and 'resources' in futureDesc: |
| 303 | future = futureDesc['resources'].get(methodName, {}) |
| 304 | else: |
| 305 | future = {} |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 306 | createMethod(Resource, methodName, methodDesc, |
| 307 | future.get(methodName, {})) |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 308 | |
| 309 | # Add <m>_next() methods to Resource |
Joe Gregorio | 2379ecc | 2010-10-26 10:51:28 -0400 | [diff] [blame] | 310 | if futureDesc: |
| 311 | for methodName, methodDesc in futureDesc['methods'].iteritems(): |
| 312 | if 'next' in methodDesc and methodName in resourceDesc['methods']: |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 313 | createNextMethod(Resource, methodName + "_next", |
| 314 | resourceDesc['methods'][methodName], |
| 315 | methodDesc['next']) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 316 | |
| 317 | return Resource() |