本文整理匯總了Python中falcon.HTTP_409屬性的典型用法代碼示例。如果您正苦於以下問題:Python falcon.HTTP_409屬性的具體用法?Python falcon.HTTP_409怎麽用?Python falcon.HTTP_409使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類falcon
的用法示例。
在下文中一共展示了falcon.HTTP_409屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: on_post
# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_409 [as 別名]
def on_post(self, req, resp, release):
try:
with self.get_tiller(req, resp) as tiller:
msg = self.handle(req, release, tiller)
resp.body = json.dumps({
'message': msg,
})
resp.content_type = 'application/json'
resp.status = falcon.HTTP_200
except LockException as e:
self.return_error(resp, falcon.HTTP_409, message=str(e))
except Exception as e:
self.logger.exception('Caught unexpected exception')
err_message = 'Failed to rollback release: {}'.format(e)
self.error(req.context, err_message)
self.return_error(resp, falcon.HTTP_500, message=err_message)
示例2: on_get
# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_409 [as 別名]
def on_get(self, req, resp, release):
try:
with self.get_tiller(req, resp) as tiller:
success = self.handle(req, release, tiller)
if success:
msg = {
'result': 'PASSED: {}'.format(release),
'message': 'MESSAGE: Test Pass'
}
else:
msg = {
'result': 'FAILED: {}'.format(release),
'message': 'MESSAGE: Test Fail'
}
resp.body = json.dumps(msg)
resp.status = falcon.HTTP_200
resp.content_type = 'application/json'
except LockException as e:
self.return_error(resp, falcon.HTTP_409, message=str(e))
示例3: add_collection
# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_409 [as 別名]
def add_collection(self, collection_id, document_string):
"""Triggers a call to Deckhand to add a collection(bucket)
Documents are assumed to be a string input, not a
collection.
Returns the id of the buffer version.
"""
try:
self.deckhand.put_bucket(collection_id, document_string)
except DocumentExistsElsewhereError as deee:
LOG.info('Deckhand has rejected this input because an included '
'document exists in another bucket already')
raise ApiError(
title='Documents may not exist in more than one collection',
description=deee.response_message,
status=falcon.HTTP_409)
except DeckhandRejectedInputError as drie:
LOG.info('Deckhand has rejected this input because: %s',
drie.response_message)
raise ApiError(
title="Document(s) invalid syntax or otherwise unsuitable",
description=drie.response_message)
# reset the revision dict so it regenerates.
self.revision_dict = None
return self.get_revision_id(BUFFER)
示例4: validate
# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_409 [as 別名]
def validate(self):
if self.action.get('allow_intermediate_commits'):
LOG.debug("Intermediate commit check skipped due to user input")
else:
intermediate_commits = (
self.configdocs_helper.check_intermediate_commit())
if intermediate_commits:
raise ApiError(
title='Intermediate commit detected',
description=(
'The current committed revision of documents has '
'other prior commits that have not been used as '
'part of a site action, e.g. update_site. If you '
'are aware and these other commits are intended, '
'please rerun this action with the option '
'`allow-intermediate-commits=True`'),
status=falcon.HTTP_409,
retry=False
)
示例5: on_post
# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_409 [as 別名]
def on_post(self, req, resp):
# TODO(fmontei): Validation Content-Type is application/x-yaml.
try:
with self.get_tiller(req, resp) as tiller:
return self.handle(req, resp, tiller)
except LockException as e:
self.return_error(resp, falcon.HTTP_409, message=str(e))
示例6: api_lock
# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_409 [as 別名]
def api_lock(api_lock_type):
"""
Decorator to handle allowing a resource method to institute a lock
based on the specified lock type.
These locks are intended for use around methods such as on_post
and on_get, etc...
"""
def lock_decorator(func):
@wraps(func)
def func_wrapper(self, req, resp, *args, **kwargs):
lock = ApiLock(api_lock_type,
req.context.external_marker,
req.context.user)
try:
lock.acquire()
return func(self, req, resp, *args, **kwargs)
except ApiLockAcquireError:
raise ApiError(
title='Blocked by another process',
description=(
'Another process is currently blocking this request '
'with a lock for {}. Lock expires in not more '
'than {} seconds'.format(
lock.lock_type_name,
lock.expires
)
),
status=falcon.HTTP_409,
retry=False,
)
finally:
lock.release()
return func_wrapper
return lock_decorator
示例7: pause_dag
# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_409 [as 別名]
def pause_dag(self, dag_id, execution_date):
"""
Sets the pause flag on this dag/execution
"""
try:
AIRFLOW_DB.pause_dag_run(
dag_id=dag_id, execution_date=execution_date)
except AirflowStateError as state_error:
raise ApiError(
title='Unable to pause action',
description=state_error.message,
status=falcon.HTTP_409)
示例8: unpause_dag
# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_409 [as 別名]
def unpause_dag(self, dag_id, execution_date):
"""
Clears the pause flag on this dag/execution
"""
try:
AIRFLOW_DB.unpause_dag_run(
dag_id=dag_id, execution_date=execution_date)
except AirflowStateError as state_error:
raise ApiError(
title='Unable to unpause action',
description=state_error.message,
status=falcon.HTTP_409)
示例9: commit_configdocs
# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_409 [as 別名]
def commit_configdocs(self, helper, force, dryrun):
"""
Attempts to commit the configdocs
"""
if helper.is_buffer_empty():
raise ApiError(
title=CommitConfigDocsResource.unable_to_commmit,
description='There are no documents in the buffer to commit',
status=falcon.HTTP_409,
retry=True)
validations = helper.get_validations_for_revision(
helper.get_revision_id(configdocs_helper.BUFFER)
)
if dryrun:
validations['code'] = falcon.HTTP_200
if 'message' in validations:
validations['message'] = (
validations['message'] + ' DRYRUN')
else:
validations['message'] = 'DRYRUN'
else:
if force or validations.get('status') == 'Success':
helper.tag_buffer(configdocs_helper.COMMITTED)
if force and validations.get('status') == 'Failure':
# override the status in the response
validations['code'] = falcon.HTTP_200
if 'message' in validations:
validations['message'] = (
validations['message'] + ' FORCED SUCCESS')
else:
validations['message'] = 'FORCED SUCCESS'
return validations
示例10: on_post
# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_409 [as 別名]
def on_post(self, req, resp):
# Load data from request and get options
if req.content_type == 'application/x-yaml':
data = list(self.req_yaml(req))
if type(data[0]) is list:
documents = list(data[0])
else:
documents = data
elif req.content_type == 'application/json':
self.logger.debug("Applying manifest based on reference.")
req_body = self.req_json(req)
doc_ref = req_body.get('hrefs', None)
if not doc_ref:
self.logger.info("Request did not contain 'hrefs'.")
resp.status = falcon.HTTP_400
return
data = ReferenceResolver.resolve_reference(doc_ref)
documents = list()
for d in data:
documents.extend(list(yaml.safe_load_all(d.decode())))
if req_body.get('overrides', None):
overrides = Override(
documents, overrides=req_body.get('overrides'))
documents = overrides.update_manifests()
else:
self.error(
req.context, "Unknown content-type %s" % req.content_type)
# TODO(fmontei): Use falcon.<Relevant API Exception Class> instead.
return self.return_error(
resp,
falcon.HTTP_415,
message="Request must be in application/x-yaml"
"or application/json")
try:
with self.get_tiller(req, resp) as tiller:
msg = self.handle(req, documents, tiller)
resp.body = json.dumps({
'message': msg,
})
resp.content_type = 'application/json'
resp.status = falcon.HTTP_200
except exceptions.ManifestException as e:
self.return_error(resp, falcon.HTTP_400, message=str(e))
except LockException as e:
self.return_error(resp, falcon.HTTP_409, message=str(e))
except Exception as e:
self.logger.exception('Caught unexpected exception')
err_message = 'Failed to apply manifest: {}'.format(e)
self.error(req.context, err_message)
self.return_error(resp, falcon.HTTP_500, message=err_message)