Ejemplo n.º 1
0
def dict_response(data, url=None):
    accept = http.parse_list_header(request.headers.get('Accept',''))

    mime = 'text/plain'
    if accept and 'application/json' in accept:
        body = json.dumps(data, default=json_datetime)
        mime = 'application/json'
    else:
        body = safe_dump(data, default_flow_style=False)

    if url and request.args.get('r'):
        return redirect(url, body, mimetype=mime)
    return current_app.response_class(body, mimetype=mime)
Ejemplo n.º 2
0
Archivo: util.py Proyecto: hguemar/pb
def dict_response(data, url=None):
    accept = http.parse_list_header(request.headers.get('Accept',''))

    mime = 'text/x-yaml'
    if accept and 'application/json' in accept:
        body = json.dumps(data)
        mime = 'application/json'
    else:
        body = safe_dump(data, default_flow_style=False)

    if url and request.args.get('r'):
        return redirect(url, body, mimetype=mime)
    return current_app.response_class(body, mimetype=mime)
Ejemplo n.º 3
0
def dict_response(data, url=None):
    accept = http.parse_list_header(request.headers.get("Accept", ""))

    mime = "text/plain"
    if accept and "application/json" in accept:
        body = json.dumps(data, default=json_datetime)
        mime = "application/json"
    else:
        body = safe_dump(data, default_flow_style=False)

    if url and request.args.get("r"):
        return redirect(url, body, mimetype=mime)
    return current_app.response_class(body, mimetype=mime)
Ejemplo n.º 4
0
    def _get_real_value(self, trusted, value):
        """Get the real value from a list header based on the configured
        number of trusted proxies.

        :param trusted: Number of values to trust in the header.
        :param value: Comma separated list header value to parse.
        :return: The real value, or ``None`` if there are fewer values
            than the number of trusted proxies.

        .. versionchanged:: 1.0
            Renamed from ``_get_trusted_comma``.

        .. versionadded:: 0.15
        """
        if not (trusted and value):
            return
        values = parse_list_header(value)
        if len(values) >= trusted:
            return values[-trusted]
Ejemplo n.º 5
0
 def test_list_header(self):
     hl = http.parse_list_header('foo baz, blah')
     self.assert_equal(hl, ['foo baz', 'blah'])
Ejemplo n.º 6
0
 def test_list_header(self):
     hl = http.parse_list_header('foo baz, blah')
     self.assert_equal(hl, ['foo baz', 'blah'])
Ejemplo n.º 7
0
 def test_list_header(self):
     hl = http.parse_list_header('foo baz, blah')
     assert hl == ['foo baz', 'blah']
Ejemplo n.º 8
0
 def test_list_header(self):
     hl = http.parse_list_header("foo baz, blah")
     assert hl == ["foo baz", "blah"]
Ejemplo n.º 9
0
 def test_list_header(self):
     hl = http.parse_list_header('foo baz, blah')
     assert hl == ['foo baz', 'blah']
Ejemplo n.º 10
0
 def test_list_header(self):
     hl = http.parse_list_header("foo baz, blah")
     self.assert_equal(hl, ["foo baz", "blah"])
Ejemplo n.º 11
0
 def test_list_header(self):
     hl = http.parse_list_header("foo baz, blah")
     assert hl == ["foo baz", "blah"]
Ejemplo n.º 12
0
 def default_mimetype(self):
     accept = parse_list_header(request.headers.get('Accept', ''))
     if accept and 'application/json' in accept:
         return 'application/json'
     return 'text/plain'  # yaml
Ejemplo n.º 13
0
Archivo: base.py Proyecto: ccns1/ccns11
 def access_route(self) -> List[str]:
     if "X-Forwarded-For" in self.headers:
         return self.list_storage_class(
             parse_list_header(self.headers["X-Forwarded-For"]))
     else:
         return self.list_storage_class([self.remote_addr])
Ejemplo n.º 14
0
 def default_mimetype(self):
     accept = parse_list_header(request.headers.get('Accept',''))
     if accept and 'application/json' in accept:
         return 'application/json'
     return 'text/plain' # yaml