def request_handler(self): args = self.req.view_args if not check_basic_auth(self.req, args['user'], args['passwd']): return Response_Element(False, ('Error', 401)) return Response_Element( False, (jsonify(dict(authenticated=True, user=args['user'])), 200))
def request_handler(self): g.parser = reqparse.RequestParser( argument_class=ValidatableArgument) g.parser.add_argument('q', type=bounded_str, location='args') args = strict_parse_args(g.parser, request.args) #MOCK args.limit = '' args.offset = '' g.namespace_public_id = '' class Encoder(): def jsonify(self, value): return jsonify(value) g.encoder = Encoder() #MOCK try: search_engine = NamespaceSearchEngine(g.namespace_public_id) results = search_engine.threads.search(query=args.q, max_results=args.limit, offset=args.offset) except SearchInterfaceError: return Response_Element(False, ('Search Endpoint not available', 501)) return Response_Element(True, (g.encoder.jsonify(results), 200))
def validate_query_string(self, reqs, input): status = True for r in reqs: if r['source'] == 'get_param': selected_input = None for q in input: if r['validation']['name'] == q: selected_input = q if selected_input == None: if type(r) is not list: if r is not list: if r['validation'] is not list: if r['validation']['required'] == True: return Response_Element(False, ('', 400)) else: if self.perform_validation(selected_input, input[selected_input], r['validation']) == False: status = False if status == True: return Response_Element() else: return Response_Element(False, ('', 400))
def request_handler(self): g.parser = reqparse.RequestParser(argument_class=ValidatableArgument) args = strict_parse_args(g.parser, self.req.args) #MOCK data = { 'query': '' } #MOCK query = data.get('query') validate_search_query(query) #MOCK args.limit = '' args.offset = '' g.namespace_public_id = '' class Encoder(): def jsonify(self, value): return jsonify(value) g.encoder = Encoder() #MOCK try: search_engine = NamespaceSearchEngine(g.namespace_public_id) results = search_engine.threads.search(query=query, max_results=args.limit,offset=args.offset) except SearchEngineError as e: g.log.error('Search Error: {0}'.format(e)) return Response_Element(False, ('Search error', 501)) return Response_Element(True, (g.encoder.jsonify(results), 200))
def validate_body_params(self, reqs, input, mime_type): if mime_type == None or mime_type == '': return Response_Element() mt = mime_type.replace('/', '_').replace('-', '_') delegates = 'delegates.' + mt + '_delegate' module = import_module(delegates, mt) instance = module.validation_Delegate() if instance.handle_delegation([reqs, input]) != False: return Response_Element() else: return Response_Element(False, ('', 400))
def validate_request_parameter(self, reqs, input): status = True for r in reqs: if r['source'] == 'uri_param': selected_input = None for q in input: if r['validation']['name'] == q: selected_input = q if selected_input == None: if type(r) is not list: if type(r['validation']) is not list: if r['validation']['required'] == True: return Response_Element(False, ('', 400)) else: for mime in r['validation']: for valid in mime['params']: if type(valid) is not list: if valid['validation'][ 'required'] == True: return Response_Element( False, ('', 400)) else: for v in valid: if v['validation'][ 'required'] == True: return Response_Element( False, ('', 400)) else: if self.perform_validation(selected_input, input[selected_input], r['validation']) == False: status = False if status == True: return Response_Element() else: return Response_Element(False, ('', 400))
def request_handler(self): response = get_dict(self.req, 'url', 'args', 'headers', 'origin') n = self.req.view_args['n'] def generate_stream(): for i in xrange(n): response['id'] = i yield json.dumps(response) + '\n' output = '' for i in generate_stream(): output += i return Response_Element(True, (json.dumps(output), 200), {"Content-Type": "application/json"})
def request_handler(self): response = get_dict(self.req, 'url', 'args', 'headers', 'origin') n = self.req.view_args['n'] def generate_stream(): for i in xrange(n): response["id"] = i yield json.dumps(response) + "\n" time.sleep(1) output = '' for i in generate_stream(): output += i return Response_Element(True, (json.dumps(output), 200), {"Transfer-Encoding": "chunked", "Content-Type": "application/json"})
def request_handler(self): n = self.req.view_args['n'] def generate(): for row in xrange(n): time.sleep(1) yield str(row) + "\n" output = '' for i in generate(): output += i return Response_Element(True, (json.dumps(output), 200), { "Transfer-Encoding": "chunked", "Content-Type": "application/json" })
def handle_delegation(self, request): return Response_Element()
def auth_handler(self): return Response_Element()
def request_handler(self): return Response_Element()
def add_validate_params_handler(self, **kwargs): return Response_Element()
def make_response(text): return Response_Element(True, (text, 200))
def request_handler(self): if not check_basic_authorization(self.req): return Response_Element(False, ('Error', 401)) return make_response('auth ok')
def request_handler(self): if not check_basic_authorization(self.req): return Response_Element(False, ('Error', 401)) return Response_Element(False, (dict(authenticated=True), 200))
def add_validate_params_handler(self, cust_request): return Response_Element()
def validate_params_handler(self): custom_processing = self.add_validate_params_handler() return Response_Element()