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


Python falcon.HTTPConflict方法代码示例

本文整理汇总了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") 
开发者ID:laurivosandi,项目名称:certidude,代码行数:23,代码来源:token.py

示例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 
开发者ID:opendns,项目名称:og-miner,代码行数:23,代码来源:server.py

示例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) 
开发者ID:openstack,项目名称:freezer-api,代码行数:7,代码来源:test_exceptions.py

示例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) 
开发者ID:openstack,项目名称:freezer-api,代码行数:6,代码来源:exceptions.py

示例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') 
开发者ID:opendns,项目名称:og-miner,代码行数:30,代码来源:api.py

示例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) 
开发者ID:IntelAI,项目名称:inference-model-manager,代码行数:6,代码来源:errors_handling.py

示例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 
开发者ID:openstack,项目名称:monasca-api,代码行数:35,代码来源:resource.py


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