本文整理匯總了Python中swaggerpy.client.SwaggerClient.__repr__方法的典型用法代碼示例。如果您正苦於以下問題:Python SwaggerClient.__repr__方法的具體用法?Python SwaggerClient.__repr__怎麽用?Python SwaggerClient.__repr__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類swaggerpy.client.SwaggerClient
的用法示例。
在下文中一共展示了SwaggerClient.__repr__方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: AsyncSwaggerClient
# 需要導入模塊: from swaggerpy.client import SwaggerClient [as 別名]
# 或者: from swaggerpy.client.SwaggerClient import __repr__ [as 別名]
#.........這裏部分代碼省略.........
api_finished_deferred = Deferred()
def on_api_body_read(api_json_body):
"""Success callback for reading the body of an API
Args:
api_json_body: The JSON body for the API
Returns:
api_json_body
"""
write_resource_file(api_json_body)
return api_json_body
api_finished_deferred.addCallbacks(on_api_body_read,
on_error)
response.deliverBody(JSONBodyReceiver(api_finished_deferred))
return api_finished_deferred
api_deferreds = []
for api in resource_json_body.get('apis'):
path = api.get('path').replace('{format}', 'json')
api_url = urlparse.urljoin(self._base_url + '/', 'ari')
api_url = urlparse.urljoin(api_url + '/', path.strip('/'))
try:
api_deferred = http_client.request('GET', api_url)
api_deferred.addCallback(on_api_finished, api_url)
api_deferred.addErrback(on_error)
api_deferreds.append(api_deferred)
except Exception as e:
fail = Failure(e)
resource_finished.errback(fail)
return fail
def apis_processed(results):
"""Callback called when all API resources are processed
Args:
results: The list of (success, result) tuples returned from
the API request callbacks
Returns:
results on success
twisted.python.failure.Failure on error
"""
if any([result for result in results if not result[0]]):
msg = "Failed to process all API resources"
fail = Failure(Exception(msg))
finished_deferred.errback(fail)
return fail
resource_finished.callback(None)
return results
apis_finished = DeferredList(api_deferreds)
apis_finished.addCallback(apis_processed)
return apis_finished
finished_deferred.addCallbacks(on_resource_body_read, on_error)
response.deliverBody(JSONBodyReceiver(finished_deferred))
return finished_deferred
http_client.request('GET', url).addCallbacks(on_resource_finished,
on_error)
def on_resources_finished(result):
resource_file = 'file://{}/resources.json'.format(self._temp_dir)
self._swagger_client = SwaggerClient(resource_file)
print self._swagger_client
shutil.rmtree(self._temp_dir)
print "NIFTY"
resource_finished.addCallback(on_resources_finished)
return resource_finished
def __repr__(self):
return self._swagger_client.__repr__()
def __getattr__(self, item):
"""Promote resource objects to be client fields.
:param item: Name of the attribute to get.
:return: Resource object.
"""
return self._swagger_client.__getattr__(item)
def close(self):
"""Close the SwaggerClient, and underlying resources.
"""
self._swagger_client.close()
def get_resource(self, name):
"""Gets a Swagger resource by name.
:param name: Name of the resource to get
:rtype: Resource
:return: Resource, or None if not found.
"""
return self._swagger_client.resources.get(name)