本文整理匯總了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
示例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)
示例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.")
示例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.")
示例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
示例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'
示例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"}'
示例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
示例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''
示例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))
示例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)
示例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'])}
示例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'])}
示例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'])}
示例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'])}