def __init__(self, url):
     html = '<!DOCTYPE HTML PUBLIC>\n<title>Redirecting...</title>\n'
     Response.__init__(self,
                       response=html,
                       status=301,
                       mimetype='text/html')
     self.headers['Location'] = url
Beispiel #2
0
    def __init__(self, data={}):
        Response.__init__(self)
        if not 'success' in data:
            data['success'] = True

        self.data = json.dumps(data)
        self.mimetype = "application/json"
Beispiel #3
0
    def __init__(self, get_frame=None, *args, **kwargs):
        if get_frame is None:
            abort(500, "Unable to get frames")

        def _get_frame():
            try:
                frame = get_frame()
                buffered = BytesIO()
                frame.save(buffered, format="JPEG")
                return buffered.getvalue()
            except Exception as e:
                print(e)

        def generate_frames():
            pool = gevent.get_hub().threadpool
            while True:
                # get_frame in thread so it won't block handler greenlets
                frame_bytes = pool.spawn(_get_frame).get()
                yield (b"--frame\r\n"
                       b"Content-Type: image/jpeg\r\n\r\n" + frame_bytes +
                       b"\r\n")

        Response.__init__(
            self,
            generate_frames(),
            mimetype="multipart/x-mixed-replace; boundary=frame",
            **kwargs,
        )
Beispiel #4
0
    def __init__(self, controller, *a, **kw):
        Context.__init__(self, controller)

        kw['mimetype'] = self.mimetype
        def generator():
            for item in self.queue:
                for i in self.item(item):
                    yield i
        Response.__init__(self, stream_with_context(generator()), *a, **kw)
Beispiel #5
0
 def __init__(self, response, status_code=200, message="success", mimetype=mimetype_json):
     response = {
         'status_code': status_code,
         'message': message,
         'data': response
     }
     self.response = json.dumps(response)
     json.loads(self.response)
     Response.__init__(self, response=self.response, status=200,
                       headers={"Content-type": mimetype})
Beispiel #6
0
 def __init__(self, msg, code=None):
     Response.__init__(self)
     self.headers['content-type'] = "application/json"
     self.status_code = code or self.code
     self.data = json.dumps({
         "success": False,
         "error": {
             "code": self.id,
             "msg": "%s: %s" % (self.__class__.__name__, msg)
         }
     })
Beispiel #7
0
    def __init__(self, obj={}):
        Response.__init__(self)

        if 'success' not in obj:
            obj['success'] = True

        if request.values.get("pretty") == '1':
            self.data = json.dumps(obj,
                sort_keys=True,
                indent=2,
                separators=(',', ': '))
        else:
            self.data = json.dumps(obj)

        self.mimetype = "application/json"
Beispiel #8
0
 def __init__(self,
              status,
              title,
              detail,
              instance=None,
              type_=None,
              ext=None,
              headers=None):
     response = Problem.make_response_body(status, title, detail, instance,
                                           type_, ext)
     Response.__init__(self,
                       response=response,
                       status=status,
                       headers=headers,
                       mimetype=self.default_mimetype)
Beispiel #9
0
    def __init__(self, obj={}):
        Response.__init__(self)

        if 'success' not in obj:
            obj['success'] = True

        if request.values.get("pretty") == '1':
            self.data = json.dumps(obj,
                                   sort_keys=True,
                                   indent=2,
                                   separators=(',', ': '))
        else:
            self.data = json.dumps(obj)

        self.mimetype = "application/json"
Beispiel #10
0
    def __init__(self,
                 message_obj,
                 status,
                 add_hostname=True,
                 indent=None,
                 running_time=None):
        if add_hostname:
            message_obj["hostname"] = hostname
        if running_time != None:
            message_obj["running_time"] = running_time

        message = json.dumps(message_obj, indent=indent) + '\n'
        Response.__init__(self,
                          message,
                          status=status,
                          mimetype="application/json")
Beispiel #11
0
    def __init__(self, object_response, status=200):
        """
        Constructor of the OKJSONResponse class.

           :param object_response: Dictionary to convert to JSON.
           :param status: Default is 200.
           :raise TypeError: If argument not a dict, list or tuple.
        """
        if object_response.__class__ is dict \
                or object_response.__class__ is list \
                or object_response.__class__ is tuple:
            Response.__init__(self, dumps(object_response),
                              status=status, mimetype='application/json'
                              )
        else:
            raise TypeError(
                'OKJSONResponse CLASS CONSTRUCTOR ARGUMENT MUST BE A dict, list or tuple.'
            )
 def __init__(self, rv, status=None, headers=None, mimetype=None, content_type=None, direct_passthrough=False):
     Response.__init__(self, rv, status=status, headers=headers,  mimetype=mimetype, content_type=content_type,
                       direct_passthrough=direct_passthrough)
     self.headers['Access-Control-Allow-Origin'] = "*"
 def __init__(self, obj):
     Response.__init__(self, json.dumps(obj, indent=4, separators=(',', ': ')),
                       mimetype="application/json")
Beispiel #14
0
 def __init__(self, *args, **kwargs):
     TwimlResponse.__init__(self)
     FlaskResponse.__init__(self, *args, **kwargs)
 def __init__(self, msg='not found', data=''):
     result = json.dumps(dict(msg=msg, data=data))
     Response.__init__(self,
                       result,
                       mimetype='application/json',
                       status=404)
Beispiel #16
0
 def __init__(self, data, msg='成功', total=0):
     result = json.dumps(dict(code=0, msg=msg, data=data, total=total))
     Response.__init__(self, result, mimetype='application/json')
Beispiel #17
0
 def __init__(self,json):
         Response.__init__(self,json, 201)
         self.headers['Content-type'] = 'application/json'
 def __init__(self, data: dict, msg=''):
     result = json.dumps(dict(msg=msg, data=data))
     Response.__init__(self, result, mimetype='application/json')
 def __init__(self, response=None, mimetype=None, *args, **kw):
     if mimetype is None:
         mimetype = self.default_mimetype
     Response.__init__(self, response=response, mimetype=mimetype, **kw)
     self._fixcors()
Beispiel #20
0
 def __init__(self, response=None, mimetype=None, *args, **kw):
     if mimetype is None:
         mimetype = self.default_mimetype
     Response.__init__(self, response=response, mimetype=mimetype, **kw)
     self._fixcors()
 def __init__(self, data: list, count: int, msg=''):
     result = json.dumps(dict(msg=msg, data=data, count=count))
     Response.__init__(self, result, mimetype='application/json')
Beispiel #22
0
 def __init__(self, results, status):
     response = json.dumps(results)
     current_app.logger.info('sending response status=%s' % (status))
     current_app.logger.info('sending response text=%s' % (response))
     Response.__init__(self, response=response, status=status)
Beispiel #23
0
 def __init__(self):
     result = json.dumps(dict(code=4001, msg='未登陆', data=None))
     Response.__init__(self, response=result, mimetype='application/json')
Beispiel #24
0
 def __init__(self, msg='成功'):
     result = json.dumps(dict(code=0, msg=msg, data=None))
     Response.__init__(self, result, mimetype='application/json')
Beispiel #25
0
 def __init__(self, data, force=False):
     Response.__init__(self)
     if not force:
         data['success'] = data.get("success", True)
     self.data = json.dumps(data)
     self.headers['content-type'] = "application/json"
Beispiel #26
0
 def __init__(self, *args, **kwargs):
     TwimlResponse.__init__(self)
     FlaskResponse.__init__(self, *args, **kwargs)
 def __init__(self, rv=None, **kwargs):
     self.ext_paylod = rv
     FlaskResponse.__init__(self, rv, **kwargs)
 def __init__(self, obj):
     Response.__init__(self,
                       json.dumps(obj, indent=4, separators=(',', ': ')),
                       mimetype="application/json")
Beispiel #29
0
 def __init__(self, err_code=1, error_msg=''):
     result = json.dumps(dict(code=err_code, msg=error_msg, data=None))
     Response.__init__(self, result, mimetype='application/json')
Beispiel #30
0
 def __init__(self, status, title, detail, instance=None, type_=None, ext=None, headers=None):
     response = Problem.make_response_body(status, title, detail, instance, type_, ext)
     Response.__init__(self, response=response, status=status, headers=headers, mimetype=self.default_mimetype)