當前位置: 首頁>>代碼示例>>Python>>正文


Python falcon.HTTP_400屬性代碼示例

本文整理匯總了Python中falcon.HTTP_400屬性的典型用法代碼示例。如果您正苦於以下問題:Python falcon.HTTP_400屬性的具體用法?Python falcon.HTTP_400怎麽用?Python falcon.HTTP_400使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在falcon的用法示例。


在下文中一共展示了falcon.HTTP_400屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: on_post

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def on_post(self, req, resp):
        try:
            json_data = self.req_json(req)
            node_filter = json_data.get('node_filter', None)
            design_ref = json_data.get('design_ref', None)
            if design_ref is None:
                self.info(req.context,
                          'Missing required input value: design_ref')
                self.return_error(
                    resp,
                    falcon.HTTP_400,
                    message='Missing input required value: design_ref',
                    retry=False)
                return
            _, site_design = self.orchestrator.get_effective_site(design_ref)
            nodes = self.orchestrator.process_node_filter(
                node_filter=node_filter, site_design=site_design)
            resp_list = [n.name for n in nodes if nodes]

            resp.body = json.dumps(resp_list)
            resp.status = falcon.HTTP_200
        except Exception as ex:
            self.error(req.context, "Unknown error: %s" % str(ex), exc_info=ex)
            self.return_error(
                resp, falcon.HTTP_500, message="Unknown error", retry=False) 
開發者ID:airshipit,項目名稱:drydock,代碼行數:27,代碼來源:nodes.py

示例2: task_validate_design

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def task_validate_design(self, req, resp, json_data):
        """Create async task for validate design."""
        action = json_data.get('action', None)

        if action != 'validate_design':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_validate_design"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
開發者ID:airshipit,項目名稱:drydock,代碼行數:24,代碼來源:tasks.py

示例3: task_prepare_site

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def task_prepare_site(self, req, resp, json_data):
        """Create async task for prepare site."""
        action = json_data.get('action', None)

        if action != 'prepare_site':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_prepare_site"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
開發者ID:airshipit,項目名稱:drydock,代碼行數:24,代碼來源:tasks.py

示例4: task_verify_nodes

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def task_verify_nodes(self, req, resp, json_data):
        """Create async task for verify node."""
        action = json_data.get('action', None)

        if action != 'verify_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_verify_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
開發者ID:airshipit,項目名稱:drydock,代碼行數:24,代碼來源:tasks.py

示例5: task_prepare_nodes

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def task_prepare_nodes(self, req, resp, json_data):
        """Create async task for prepare node."""
        action = json_data.get('action', None)

        if action != 'prepare_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_prepare_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
開發者ID:airshipit,項目名稱:drydock,代碼行數:24,代碼來源:tasks.py

示例6: task_deploy_nodes

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def task_deploy_nodes(self, req, resp, json_data):
        """Create async task for deploy node."""
        action = json_data.get('action', None)

        if action != 'deploy_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_deploy_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
開發者ID:airshipit,項目名稱:drydock,代碼行數:24,代碼來源:tasks.py

示例7: task_destroy_nodes

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def task_destroy_nodes(self, req, resp, json_data):
        """Create async task for destroy node."""
        action = json_data.get('action', None)

        if action != 'destroy_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_destroy_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
開發者ID:airshipit,項目名稱:drydock,代碼行數:24,代碼來源:tasks.py

示例8: recordUser

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def recordUser(session, valueDict):
        userRow = None
        requiredValues = ["Signature", "Name", "Email", "UserID"]

        for value in requiredValues:
            if value not in valueDict.keys():
                return None
                #resp.body = "Error, missing key {}".format(value)
                #resp.status = falcon.HTTP_400

        # User table values
        signature = valueDict.get("Signature")
        name = valueDict.get("Name")
        email = valueDict.get("Email")
        company = valueDict.get("Company")
        userID = valueDict.get("UserID")

        userExists = True
        userRow = session.query(UsersTable).get((signature, userID))    

        if userRow is None:
            userExists = False
            userRow = UsersTable(Signature=signature, Name=name, Email=email, Company=company, UserID=userID, InstallDateTime=ctime())

        return userRow, userExists 
開發者ID:pyskell,項目名稱:LicenseServer,代碼行數:27,代碼來源:insert.py

示例9: on_post

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def on_post(self, req, resp):
        try:
            json_data = self.req_json(req)
            node_filter = json_data.get('node_filter', None)
            design_ref = json_data.get('design_ref', None)
            if design_ref is None:
                self.info(req.context, 'Missing required input value: design_ref')
                self.return_error(
                    resp,
                    falcon.HTTP_400,
                    message='Missing input required value: design_ref',
                    retry=False)
                return
            _, site_design = self.orchestrator.get_effective_site(design_ref)
            nodes = self.orchestrator.process_node_filter(node_filter=node_filter,
                                                          site_design=site_design)
            resp_list = [n.name for n in nodes if nodes]

            resp.body = json.dumps(resp_list)
            resp.status = falcon.HTTP_200
        except Exception as ex:
            self.error(req.context, "Unknown error: %s" % str(ex), exc_info=ex)
            self.return_error(
                resp, falcon.HTTP_500, message="Unknown error", retry=False) 
開發者ID:att-comdev,項目名稱:drydock,代碼行數:26,代碼來源:nodes.py

示例10: add_messages_to_validation_status

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def add_messages_to_validation_status(status, msgs, level):
    """Given a status retrieved from _format_validations_to_status and a list
    of messages at a given level (Error, Warning, Info), add messages to the
    status
    """
    code = falcon.HTTP_200
    if str(level).lower() == 'error':
        code = falcon.HTTP_400
        status['status'] = 'Failure'
        status['message'] = 'Validations failed'
        status['code'] = code
        status['details']['errorCount'] += len(msgs)

    formatted_messages = []
    for msg in msgs:
        formatted_messages.append({'code': code,
                                   'message': msg,
                                   'status': str(level).capitalize(),
                                   'level': str(level).lower()})
    status['details']['messageList'] += formatted_messages 
開發者ID:airshipit,項目名稱:shipyard,代碼行數:22,代碼來源:configdocs_helper.py

示例11: _format_validations_to_status

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def _format_validations_to_status(val_msgs, error_count):
    """Using a list of validation messages and an error count,
    formulates and returns a status response dict
    """
    status = 'Success'
    message = 'Validations succeeded'
    code = falcon.HTTP_200
    if error_count > 0:
        status = 'Failure'
        message = 'Validations failed'
        code = falcon.HTTP_400

    return {
        "kind": "Status",
        "apiVersion": "v1.0",
        "metadata": {},
        "status": status,
        "message": message,
        "reason": "Validation",
        "details": {
            "errorCount": error_count,
            "messageList": val_msgs,
        },
        "code": code
    } 
開發者ID:airshipit,項目名稱:shipyard,代碼行數:27,代碼來源:configdocs_helper.py

示例12: verbosity

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def verbosity(self, req):
        """Process the verbosity parameter

        :param req: the Falcon request object
        Valid values range from 0 (none) to 5 (maximum verbosity)
        """

        try:
            verbosity = req.get_param_as_int(
                'verbosity', required=False, min=0, max=MAX_VERBOSITY
            )
            if verbosity is not None:
                # if not set, retains the context default value.
                req.context.verbosity = verbosity
        except falcon.HTTPBadRequest as hbr:
            LOG.exception(hbr)
            raise ApiError(
                title="Invalid verbosity parameter",
                description=("If specified, verbosity parameter should be a "
                             "value from 0 to {}".format(MAX_VERBOSITY)),
                status=falcon.HTTP_400
            ) 
開發者ID:airshipit,項目名稱:shipyard,代碼行數:24,代碼來源:common_params.py

示例13: validate_content_length

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def validate_content_length(self, content_length):
        """Validates that the content length header is valid

        :param content_length: the value of the content-length header.
        :returns: the validate content length value
        """
        content_length = content_length or 0
        if (content_length == 0):
            raise ApiError(
                title=('Content-Length is a required header'),
                description='Content Length is 0 or not specified',
                status=falcon.HTTP_400,
                error_list=[{
                    'message': (
                        "The Content-Length specified is 0 or not set. To "
                        "clear a collection's contents, please specify "
                        "the query parameter 'empty-collection=true'."
                        "Otherwise, a non-zero length payload and "
                        "matching Content-Length header is required to "
                        "post a collection.")
                }],
                retry=False, )
        return content_length 
開發者ID:airshipit,項目名稱:shipyard,代碼行數:25,代碼來源:configdocs_api.py

示例14: on_post

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def on_post(self, req, resp):
        """Method handler for POST requests.

        :param req: Falcon request object
        :param resp: Falcon response object
        """
        try:
            json_data = self.req_json(req)
            design = None
            if json_data is not None:
                base_design = json_data.get('base_design_id', None)

                if base_design is not None:
                    base_design = uuid.UUID(base_design)
                    design = hd_objects.SiteDesign(base_design_id=base_design)
            else:
                design = hd_objects.SiteDesign()
            design.assign_id()
            design.create(req.context, self.state_manager)

            resp.body = json.dumps(design.obj_to_simple())
            resp.status = falcon.HTTP_201
        except errors.StateError:
            self.error(req.context, "Error updating persistence")
            self.return_error(
                resp,
                falcon.HTTP_500,
                message="Error updating persistence",
                retry=True)
        except errors.InvalidFormat as fex:
            self.error(req.context, str(fex))
            self.return_error(
                resp, falcon.HTTP_400, message=str(fex), retry=False) 
開發者ID:airshipit,項目名稱:drydock,代碼行數:35,代碼來源:designs.py

示例15: on_post

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_400 [as 別名]
def on_post(self, req, resp):
        """Handler for POST method."""
        # A map of supported actions to the handlers for tasks for those actions
        supported_actions = {
            'validate_design': TasksResource.task_validate_design,
            'verify_site': TasksResource.task_verify_site,
            'prepare_site': TasksResource.task_prepare_site,
            'verify_nodes': TasksResource.task_verify_nodes,
            'prepare_nodes': TasksResource.task_prepare_nodes,
            'deploy_nodes': TasksResource.task_deploy_nodes,
            'destroy_nodes': TasksResource.task_destroy_nodes,
            'relabel_nodes': TasksResource.task_relabel_nodes,
        }

        try:
            json_data = self.req_json(req)

            action = json_data.get('action', None)
            if supported_actions.get(action, None) is None:
                self.error(req.context, "Unsupported action %s" % action)
                self.return_error(
                    resp,
                    falcon.HTTP_400,
                    message="Unsupported action %s" % action,
                    retry=False)
            else:
                supported_actions.get(action)(self, req, resp, json_data)
        except Exception as ex:
            self.error(
                req.context,
                "Unknown error: %s\n%s" % (str(ex), traceback.format_exc()))
            self.return_error(
                resp, falcon.HTTP_500, message="Unknown error", retry=False) 
開發者ID:airshipit,項目名稱:drydock,代碼行數:35,代碼來源:tasks.py


注:本文中的falcon.HTTP_400屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。