Example #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)
Example #2
0
File: util.py Project: 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)
Example #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)
Example #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]
Example #5
0
 def test_list_header(self):
     hl = http.parse_list_header('foo baz, blah')
     self.assert_equal(hl, ['foo baz', 'blah'])
Example #6
0
 def test_list_header(self):
     hl = http.parse_list_header('foo baz, blah')
     self.assert_equal(hl, ['foo baz', 'blah'])
Example #7
0
 def test_list_header(self):
     hl = http.parse_list_header('foo baz, blah')
     assert hl == ['foo baz', 'blah']
Example #8
0
 def test_list_header(self):
     hl = http.parse_list_header("foo baz, blah")
     assert hl == ["foo baz", "blah"]
Example #9
0
 def test_list_header(self):
     hl = http.parse_list_header('foo baz, blah')
     assert hl == ['foo baz', 'blah']
Example #10
0
 def test_list_header(self):
     hl = http.parse_list_header("foo baz, blah")
     self.assert_equal(hl, ["foo baz", "blah"])
Example #11
0
 def test_list_header(self):
     hl = http.parse_list_header("foo baz, blah")
     assert hl == ["foo baz", "blah"]
Example #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
Example #13
0
File: base.py Project: 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])
Example #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