本文整理汇总了Python中falcon.HTTPConflict方法的典型用法代码示例。如果您正苦于以下问题:Python falcon.HTTPConflict方法的具体用法?Python falcon.HTTPConflict怎么用?Python falcon.HTTPConflict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类falcon
的用法示例。
在下文中一共展示了falcon.HTTPConflict方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_put
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPConflict [as 别名]
def on_put(self, req, resp):
try:
username, mail, created, expires, profile = self.manager.consume(req.get_param("token", required=True))
except RelationalMixin.DoesNotExist:
raise falcon.HTTPForbidden("Forbidden", "No such token or token expired")
body = req.stream.read(req.content_length)
header, _, der_bytes = pem.unarmor(body)
csr = CertificationRequest.load(der_bytes)
common_name = csr["certification_request_info"]["subject"].native["common_name"]
if not common_name.startswith(username + "@"):
raise falcon.HTTPBadRequest("Bad requst", "Invalid common name %s" % common_name)
try:
_, resp.body = self.authority._sign(csr, body, profile=config.PROFILES.get(profile),
overwrite=config.TOKEN_OVERWRITE_PERMITTED)
resp.set_header("Content-Type", "application/x-pem-file")
logger.info("Autosigned %s as proven by token ownership", common_name)
except FileExistsError:
logger.info("Won't autosign duplicate %s", common_name)
raise falcon.HTTPConflict(
"Certificate with such common name (CN) already exists",
"Will not overwrite existing certificate signing request, explicitly delete existing one and try again")
示例2: on_post
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPConflict [as 别名]
def on_post(self, request, response):
query = dict()
try:
raw_json = request.stream.read()
except Exception as e:
raise falcon.HTTPError(falcon.HTTP_400, 'Error', e.message)
try:
data = json.loads(raw_json, encoding='utf-8')
except ValueError:
raise falcon.HTTPError(falcon.HTTP_400, 'Malformed JSON')
if "id" not in data:
raise falcon.HTTPConflict('Task creation', "ID is not specified.")
if "type" not in data:
raise falcon.HTTPConflict('Task creation', "Type is not specified.")
transaction = self.client.push_task({ "task" : "vertex", "data" : data })
response.body = json.dumps({ "transaction" : transaction })
response.status = falcon.HTTP_202
示例3: test_DocumentExists
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPConflict [as 别名]
def test_DocumentExists(self):
e = exceptions.DocumentExists(message='testing')
self.assertRaises(falcon.HTTPConflict,
e.handle, self.ex, self.mock_req, self.mock_req,
None)
示例4: handle
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPConflict [as 别名]
def handle(ex, req, resp, params):
raise falcon.HTTPConflict(
title=_("Document already existing"),
description=ex.message)
示例5: on_post
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPConflict [as 别名]
def on_post(self, request, response, vertex_id):
query = dict()
try:
raw_json = request.stream.read()
except Exception as e:
raise falcon.HTTPError(falcon.HTTP_400, 'Error', e.message)
try:
data = json.loads(raw_json, encoding='utf-8')
except ValueError:
raise falcon.HTTPError(falcon.HTTP_400, 'Malformed JSON')
data["id"] = vertex_id
try:
query = list(graph.query_vertices({ "id" : vertex_id }))
except Exception as e:
raise falcon.HTTPError(falcon.HTTP_400, 'Error', e.message)
if len(query) > 0:
raise falcon.HTTPConflict('Vertex Creation', "Vertex already exists.")
try:
result = graph.update_vertex(**data)
except Exception as e:
raise falcon.HTTPError(falcon.HTTP_400, 'Error', e.message)
response.status = falcon.HTTP_200
response.body = json.dumps({ "created" : result }, encoding='utf-8')
示例6: handler
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPConflict [as 别名]
def handler(ex, req, resp, params):
message = "Tenant {} already exists".format(ex.tenant_name)
logger.error(message)
raise falcon.HTTPConflict(message)
示例7: resource_try_catch_block
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPConflict [as 别名]
def resource_try_catch_block(fun):
def try_it(*args, **kwargs):
try:
return fun(*args, **kwargs)
except falcon.HTTPError:
raise
except exceptions.DoesNotExistException:
raise falcon.HTTPNotFound
except exceptions.MultipleMetricsException as ex:
raise falcon.HTTPConflict("MultipleMetrics", str(ex))
except exceptions.AlreadyExistsException as ex:
raise falcon.HTTPConflict(ex.__class__.__name__, str(ex))
except exceptions.InvalidUpdateException as ex:
raise HTTPUnprocessableEntityError(ex.__class__.__name__, str(ex))
except exceptions.RepositoryException as ex:
LOG.exception(ex)
msg = " ".join(map(str, ex.args[0].args))
raise falcon.HTTPInternalServerError('The repository was unable '
'to process your request',
msg)
except Exception as ex:
LOG.exception(ex)
raise falcon.HTTPInternalServerError('Service unavailable',
str(ex))
return try_it