~sirn/fanboi2

ref: c1f8e48d5062ca982c7bd9392477a4cc8623d32e fanboi2/fanboi2/utils/request.py -rw-r--r-- 540 bytes
c1f8e48dKridsada Thanabulpong Fix GeoIP2 raising no method error. 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def serialize_request(request):
    """Serialize :class:`pyramid.request.Request` into a :type:`dict`.

    :param request: A :class:`pyramid.request.Request` object to serialize.

    :type request: pyramid.response.Request or dict
    :rtype: dict
    """

    if isinstance(request, dict):
        return request

    return {
        'application_url': request.application_url,
        'remote_addr': request.remote_addr,
        'user_agent': request.user_agent,
        'referrer': request.referrer,
        'url': request.url,
    }