當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。