当前位置: 首页>>代码示例>>Python>>正文


Python SwaggerClient.close方法代码示例

本文整理汇总了Python中swaggerpy.client.SwaggerClient.close方法的典型用法代码示例。如果您正苦于以下问题:Python SwaggerClient.close方法的具体用法?Python SwaggerClient.close怎么用?Python SwaggerClient.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swaggerpy.client.SwaggerClient的用法示例。


在下文中一共展示了SwaggerClient.close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AsyncSwaggerClient

# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import close [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)
开发者ID:matt-jordan,项目名称:twisted-ari,代码行数:104,代码来源:swagger_client.py


注:本文中的swaggerpy.client.SwaggerClient.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。