예제 #1
0
    def on_post(self, req, resp):
        """process the utterance using POST method"""
        req_data = req.context['data']
        classifier = req.context['classifier']
        if not req_data:
            raise RaiseError.error_invalid_parameter(
                description=req.context['data'])
        try:
            if classifier:
                #model,confidence_score = classifier.predict(req_data.get('question'))
                filename = req_data.get('filename')
                filetype = req_data.get('filetype')
                etl_obj = DataSource(filename, filetype)
                sheet_names = etl_obj.getMetaData()['sheet_names']
                l_msg = "output returned by the Model: {}".format(sheet_names)
                log.info(l_msg)

                bdata = OrderedDict()
                bdata['sheet_names'] = sheet_names
            else:
                log.error("classifier is not configured...")
        except:
            ExUtil.print_stack_trace()
            RaiseError.error_not_found(
                description='No Utterance Mapping found')
        self.on_success(resp, bdata)
예제 #2
0
def validate_expression(req, resp, resource, params):
    schema = {'question': FIELDS['question']}
    """validate the request payload"""
    v = Validator(schema)

    try:
        if not v.validate(req.context['data']):
            RaiseError.error_invalid_parameter(description="invalid payload")
        max_body(6 * 1024)
    except DocumentError:
        description = "invalid expression {}".format(req.context['data'])
        RaiseError.error_invalid_parameter(description=description)
예제 #3
0
 def process_request(self, req, resp):
     """ enfornce the request method and media type"""
     if req.method in ('POST', 'PUT'):
         print(req.content_type)
         print('------------')
         if 'application/json' in req.content_type:
             try:
                 print("inside ")
                 raw_json = req.stream.read()
                 if not raw_json:
                     RaiseError.error_invalid_parameter(
                         description=
                         'empty request body - need a valid JSON.')
                 """ set the data in the context after decoding"""
                 req.context['data'] = json.loads(raw_json)
             except HTTPBadRequest:
                 raise
             except (UnicodeDecodeError, TypeError):
                 ExUtil.print_stack_trace()
                 RaiseError.error_invalid_parameter(
                     description=
                     'unable to process your request - malformed payload...'
                 )
         else:
             RaiseError.error_missing_header(
                 description='supports requests encoded in JSON in JSON only'
             )
     """enforce the media support types"""
     if req.path not in ('/', '/x-tree/F5Monitor.html', '/favicon.ico',
                         '/favicon.png') and not req.path.startswith(
                             ('v1/swagger', '/static')):
         if not req.client_accepts_json:
             RaiseError.error_not_acceptable(
                 description='support response encoded in JSON only' +
                 MEDIA_TEXT)
예제 #4
0
 def hook(req, resp, resource, params):
     length = req.content_length
     if length is not None and length > limit:
         description = ('The size of the request is too large. The body must not exceed ' + str(limit) +' bytes in length.')
         RaiseError.error_request_body_too_large(description=description)
     return hook
예제 #5
0
 def on_delete(self, req, res):
     RaiseError.error_method_not_supported(allowed_methods='DELETE',description='for the request path: ' + req.path)
예제 #6
0
 def on_put(self, req, res):
     RaiseError.error_method_not_supported(allowed_methods='PUT', description='for the request path: ' + req.path)
예제 #7
0
 def on_get(self, req, resp):
     if req.path == '/':
         self.on_success(resp, self.CUST_VA)
     else:
         RaiseError.error_method_not_supported(allowed_methods='GET',description='for the request path: ' + req.path)
예제 #8
0
 def to_json(self, body_dict):
     try:
         return json.dumps(body_dict)
     except (ValueError, TypeError):
         ExUtil.print_stack_trace()
         RaiseError.error_application(description='unable to process your request - try again...')