我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用tornado.web.MissingArgumentError()。
def with_query_parameters(*parameter_names): def wrapped(method): @wraps(method) def call(self, *args, **kwargs): try: for param in parameter_names: kwargs[param] = self.get_query_argument(param) return method(self, *args, **kwargs) except MissingArgumentError: self.set_status(HTTPStatus.BAD_REQUEST) return call return wrapped
def with_body_arguments(*parameter_names): def wrapped(method): @wraps(method) def call(self, *args, **kwargs): try: for param in parameter_names: kwargs[param] = self.get_body_argument(param) return method(self, *args, **kwargs) except MissingArgumentError: self.set_status(HTTPStatus.BAD_REQUEST) return call return wrapped
def exception_control(func): ''' ??????? ''' @functools.wraps(func) def wrapper(self): ''' ???? ''' try: code, msg, body = E_SUCC, "OK", func(self) except (MissingArgumentError, AssertionError) as ex: code, msg, body = E_PARAM, str(ex), None except tornado.web.HTTPError: raise except Exception as ex: code, msg, body = E_INTER, str(ex), None log_msg = self.request.uri \ if self.request.files else \ "%s %s" % (self.request.uri, self.request.body) logging.error(log_msg, exc_info=True) self.send_json(body, code, msg) return wrapper
def view_output(self): """ Returns the output_file of testcase specified in GET request """ try: id = int(self.get_argument('id')) session = self.acquire_sql_session() testcase = TestcaseRepository.get_by_id(session, id) except MissingArgumentError: raise HTTPError(404, 'No id specified') except SQLAlchemyError: raise HTTPError(500, 'Database error, could not find specified id') except: raise HTTPError(500, 'Shit happened') # Sends the actual file data self.write(testcase.output_file) session.close()
def get(self): try: self.get_argument('foo') self.write({}) except MissingArgumentError as e: self.write({'arg_name': e.arg_name, 'log_message': e.log_message})
def _get_query_args(self, handler_def): """Retreives the values for query arguments.""" query_args = {} for qarg in handler_def.query_args: try: query_args[qarg.name] = self.get_query_argument(qarg.name) except MissingArgumentError: if not qarg.required: continue raise BadRequestError( "Missing required query argument '{}'".format(qarg.name) ) return query_args
def get(self, repository_id=None, entity_type=None, entity_id=None): if repository_id is None: try: hub_key = self.get_query_argument('hub_key') except MissingArgumentError: raise HTTPError(400, 'hub_key parameter is required') try: parts = parse_hub_key(hub_key) except ValueError: raise HTTPError(404, 'Invalid hub key') if parts['schema_version'] == 's0': raise HTTPError(404, 'Only hub keys matching ' 'schema >= s1 are supported') else: parts = { 'repository_id': repository_id, 'entity_type': entity_type, 'entity_id': entity_id } try: entity = yield get_entity(parts['repository_id'], parts['entity_type'], parts['entity_id']) except httpclient.HTTPError, e: raise HTTPError(e.code, e.message) if not entity: raise HTTPError(404, 'Not found') self.finish({'status': 200, 'data': entity})
def view_input(self): """ Returns the input_file of testcase specified in GET request """ try: id = int(self.get_argument('id')) session = self.acquire_sql_session() try: testcase = TestcaseRepository.get_by_id(session, id) except SQLAlchemyError: raise HTTPError(400, 'Testcase with specified ' 'id does not exist.') except MissingArgumentError: raise HTTPError(404, 'No id specified.') except HTTPError: raise except SQLAlchemyError: raise HTTPError(500, 'Database error, could not ' 'find specified id.') except: raise HTTPError(500, 'Unexpected error') # Sends the actual file data self.write(testcase.input_file) session.close()
def edit_dataset(self): """ Renders the page for editing a dataset. """ try: id = int(self.get_argument('id')) session = self.acquire_sql_session() try: dataset = DatasetRepository.get_by_id(session, id) except: raise HTTPError(404, 'Specified id doesn\'t exist') except MissingArgumentError: raise HTTPError(404, 'No id specified') except SQLAlchemyError: raise HTTPError(500, 'Database error occured.') except HTTPError: raise except: raise HTTPError(500, 'Unexpected error occured') self.render('dataset_edit.html', dataset=dataset) session.close()
def delete_testcase(self): """ Deletes testcase specified by id from POST request """ try: session = self.acquire_sql_session() except: raise HTTPError(500, 'Could not acquire database session.') try: # Get argument from request id = int(self.get_argument('id')) try: # Try to delete the testcase TestcaseRepository.delete_by_id(session, id) except SQLAlchemyError: traceback.print_exc() raise HTTPError(400, 'Testcase with specified id ' 'does not exist.') session.commit() except MissingArgumentError as e: traceback.print_exc() self.set_status(400) self.write('Id not specified in request.') return except SQLAlchemyError as e: traceback.print_exc() self.set_status(500) self.write('Databse error occured.') return except HTTPError: raise except: traceback.print_exc() self.set_status(500) self.write('Unexpected error occured.') return finally: session.close() self.write('Success!')