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


Python chalice.Chalice方法代码示例

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


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

示例1: _consumers

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def _consumers(self):
        """
        Gets consumers from Lambda environment variables prefixed with
        CONSUMER_KEY_SECRET_. For example, given a consumer key of foo
        and a shared secret of bar, you should have an environment
        variable CONSUMER_KEY_SECRET_foo=bar.

        :return: consumers map
        :raises: LTIException if environment variables are not found
        """
        consumers = {}
        for env in os.environ:
            if env.startswith('CONSUMER_KEY_SECRET_'):
                key = env[20:]  # Strip off the CONSUMER_KEY_SECRET_ prefix
                # TODO: remove below after live test
                # consumers[key] = {"secret": os.environ[env], "cert": 'NA'}
                consumers[key] = {"secret": os.environ[env], "cert": None}
        if not consumers:
            raise LTIException("No consumers found. Chalice stores "
                               "consumers in Lambda environment variables. "
                               "Have you created the environment variables?")
        return consumers 
开发者ID:mitodl,项目名称:pylti,代码行数:24,代码来源:chalice.py

示例2: __init__

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def __init__(self, lti_args, lti_kwargs):
        # Chalice does not support sessions. Yet, we want the experiance
        # to be the same as Flask. Therefore, use a simple dictionary
        # to keep session variables for the length of this request.
        self.session = {}
        LTIBase.__init__(self, lti_args, lti_kwargs) 
开发者ID:mitodl,项目名称:pylti,代码行数:8,代码来源:chalice.py

示例3: _verify_any

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def _verify_any(self):
        """
        Verify that request is in session or initial request

        :raises: LTIException
        """
        raise LTIException("The Request Type any is not "
                           "supported because Chalice does not support "
                           "session state. Change the Request Type to "
                           "initial or omit it from the declaration.") 
开发者ID:mitodl,项目名称:pylti,代码行数:12,代码来源:chalice.py

示例4: _verify_session

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def _verify_session():
        """
        Verify that session was already created

        :raises: LTIException
        """
        raise LTIException("The Request Type session is not "
                           "supported because Chalice does not support "
                           "session state. Change the Request Type to "
                           "initial or omit it from the declaration.") 
开发者ID:mitodl,项目名称:pylti,代码行数:12,代码来源:chalice.py

示例5: sample_app

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def sample_app():
    demo = app.Chalice('demo-app')

    thread_safety_check = []
    lock = Lock()

    @demo.route('/', methods=['GET'])
    def index():
        return {'hello': 'world'}

    @demo.route('/test-cors', methods=['POST'], cors=True)
    def test_cors():
        return {'hello': 'world'}

    @demo.route('/count', methods=['POST'])
    def record_counter():
        # An extra delay helps ensure we consistently fail if we're
        # not thread safe.
        time.sleep(0.001)
        count = int(demo.current_request.json_body['counter'])
        with lock:
            thread_safety_check.append(count)

    @demo.route('/count', methods=['GET'])
    def get_record_counter():
        return thread_safety_check[:]

    return demo 
开发者ID:aws,项目名称:chalice,代码行数:30,代码来源:test_local.py

示例6: test_can_get_unicode_string_content_length

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def test_can_get_unicode_string_content_length(
        config, local_server_factory):
    demo = app.Chalice('app-name')

    @demo.route('/')
    def index_view():
        return u'\u2713'

    local_server, port = local_server_factory(demo, config)
    response = local_server.make_call(requests.get, '/', port)
    assert response.headers['Content-Length'] == '3' 
开发者ID:aws,项目名称:chalice,代码行数:13,代码来源:test_local.py

示例7: test_can_accept_multiple_connections

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def test_can_accept_multiple_connections(config, sample_app,
                                         local_server_factory):
    # When a GET request is made to Chalice from a browser, it will send the
    # connection keep-alive header in order to hold the connection open and
    # reuse it for subsequent requests. If the conncetion close header is sent
    # back by the server the connection will be closed, but the browser will
    # reopen a new connection just in order to have it ready when needed.
    # In this case, since it does not send any content we do not have the
    # opportunity to send a connection close header back in a response to
    # force it to close the socket.
    # This is an issue in Chalice since the single threaded local server will
    # now be blocked waiting for IO from the browser socket. If a request from
    # any other source is made it will be blocked until the browser sends
    # another request through, giving us a chance to read from another socket.
    local_server, port = local_server_factory(sample_app, config)
    local_server.wait_for_server_ready()
    # We create a socket here to emulate a browser's open connection and then
    # make a request. The request should succeed.
    socket.create_connection(('localhost', port), timeout=1)
    try:
        response = local_server.make_call(requests.get, '/', port)
    except requests.exceptions.ReadTimeout:
        assert False, (
            'Read timeout occurred, the socket is blocking the next request '
            'from going though.'
        )
    assert response.status_code == 200
    assert response.text == '{"hello":"world"}' 
开发者ID:aws,项目名称:chalice,代码行数:30,代码来源:test_local.py

示例8: sample_app

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def sample_app():
    app = Chalice("sample_app")

    @app.route('/')
    def index():
        return {"hello": "world"}

    return app 
开发者ID:aws,项目名称:chalice,代码行数:10,代码来源:test_package.py

示例9: test_does_error_code_propagate

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def test_does_error_code_propagate(self):
        pip = SubprocessPip()
        rc, _, err = pip.main(['badcommand'])
        assert rc != 0
        # Don't want to depend on a particular error message from pip since it
        # may change if we pin a differnet version to Chalice at some point.
        # But there should be a non-empty error message of some kind.
        assert err != b'' 
开发者ID:aws,项目名称:chalice,代码行数:10,代码来源:test_package.py

示例10: clifactory

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def clifactory(tmpdir):
    appdir = tmpdir.mkdir('app')
    appdir.join('app.py').write(
        '# Test app\n'
        'import chalice\n'
        'app = chalice.Chalice(app_name="test")\n'
    )
    chalice_dir = appdir.mkdir('.chalice')
    chalice_dir.join('config.json').write('{}')
    return factory.CLIFactory(str(appdir)) 
开发者ID:aws,项目名称:chalice,代码行数:12,代码来源:test_factory.py

示例11: test_can_access_lazy_loaded_app

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def test_can_access_lazy_loaded_app(clifactory):
    config = clifactory.create_config_obj()
    assert isinstance(config.chalice_app, Chalice) 
开发者ID:aws,项目名称:chalice,代码行数:5,代码来源:test_factory.py

示例12: test_can_analyze_chalice_app

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def test_can_analyze_chalice_app():
    assert chalice_aws_calls("""\
        from chalice import Chalice
        import boto3

        app = Chalice(app_name='james1')
        ec2 = boto3.client('ec2')


        @app.route('/')
        def index():
            ec2.describe_instances()
            return {}
    """) == {'ec2': set(['describe_instances'])} 
开发者ID:aws,项目名称:chalice,代码行数:16,代码来源:test_analyzer.py

示例13: test_can_analyze_lambda_function

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def test_can_analyze_lambda_function():
    assert chalice_aws_calls("""\
        from chalice import Chalice
        import boto3
        app = Chalice(app_name='james1')
        ec2 = boto3.client('ec2')
        @app.lambda_function(name='lambda1')
        def index():
            ec2.describe_instances()
            return {}
    """) == {'ec2': set(['describe_instances'])} 
开发者ID:aws,项目名称:chalice,代码行数:13,代码来源:test_analyzer.py

示例14: test_can_analyze_combination

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def test_can_analyze_combination():
    assert chalice_aws_calls("""\
        from chalice import Chalice
        import boto3
        app = Chalice(app_name='james1')
        s3 = boto3.client('s3')
        ec = boto3.client('ec2')
        @app.route('/')
        def index():
            ec2.describe_instances()
            return {}
        @app.schedule('rate(1 hour)')
        def index_sc():
            s3.list_buckets()
            return {}

        @app.lambda_function(name='lambda1')
        def index_lm():
            ec.describe_instances()
            return {}

        @random
        def foo():
            return {}

    """) == {'s3': set(['list_buckets']),
             'ec2': set(['describe_instances'])} 
开发者ID:aws,项目名称:chalice,代码行数:29,代码来源:test_analyzer.py

示例15: test_can_analyze_custom_auth

# 需要导入模块: import chalice [as 别名]
# 或者: from chalice import Chalice [as 别名]
def test_can_analyze_custom_auth():
    assert chalice_aws_calls("""\
        from chalice import Chalice
        import boto3

        ec2 = boto3.client('ec2')
        app = Chalice(app_name='custom-auth')

        @app.authorizer()
        def index(auth_request):
            ec2.describe_instances()
            return {}
    """) == {'ec2': set(['describe_instances'])} 
开发者ID:aws,项目名称:chalice,代码行数:15,代码来源:test_analyzer.py


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