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


Python StackInABox.register方法代码示例

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


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

示例1: App

# 需要导入模块: from stackinabox.stack import StackInABox [as 别名]
# 或者: from stackinabox.stack.StackInABox import register [as 别名]

#.........这里部分代码省略.........
        521: "Web Server Is Down",
        522: "Connection Timed Out",
        523: "Origin Is Unreachable",
        524: "A Timeout Occurred",
        525: "SSL Handshake Failed",
        526: "Invalid SSL Certificate",

        # The below codes are specific cases for the infrastructure
        # supported here and should not conflict with anything above.

        # StackInABox Status Codes
        595: "Route Not Handled",
        596: "Unhandled Exception",
        597: "URI Is For Service That Is Unknown",

        # StackInAWSGI Status Codes
        593: "Session ID Missing from URI",
        594: "Invalid Session ID"
    }

    def __init__(self, services=None):
        """
        Create the WSGI Application

        :param list services: list of :obj:`StackInABoxService`s to load into
            StackInABox.
        """
        self.stackinabox = StackInABox()
        self.stack_service = StackInAWsgiSessionManager()
        self.admin_service = StackInAWsgiAdmin(
            self.stack_service,
            'http://localhost/stackinabox/'
        )
        self.stackinabox.register(self.admin_service)
        self.stackinabox.register(self.stack_service)

        def __check_service(service_object):
            """
            Simple wrapper to check whether an object provide by the caller is
            a StackInABoxService by creating an instance
            """
            svc = service_object()
            if not isinstance(svc, StackInABoxService):
                raise TypeError(
                    "Service is not a Stack-In-A-Box Service"
                )

        # if the caller does not provide any services then just log it
        # to keep from user confusion
        if services is not None:

            # Allow the caller to provide either an iterable of services to
            # to provide to the session or to provide a single service object
            if isinstance(services, Iterable):
                # for each service verify it is a StackInABoxService
                for service in services:
                    __check_service(service)
                    self.RegisterWithStackInABox(service)

            else:
                # if it's not an iterable - e.g a single object - then
                # just check the variable itself
                __check_service(services)
                self.RegisterWithStackInABox(services)

        else:
开发者ID:TestInABox,项目名称:stackInAWSGI,代码行数:70,代码来源:app.py


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