コード例 #1
0
try:
    from urlparse import parse_qs
except ImportError:
    from urllib.parse import parse_qs


def handler(response, body):
    ''' form.handler:
    Performs a conversion from the raw string into a dictionary using the built
    in urlparsing library.
    '''
    data = parse_qs(body)
    for key, value in data.items():
        if len(value) == 1:
            data[key] = value[0]

    return data

from restler import Response
Response.add_mimetype("application/x-www-form-urlencoded", handler)
コード例 #2
0
try:
    from urlparse import parse_qs
except ImportError:
    from urllib.parse import parse_qs


def handler(response, body):
    """ MIMEtype handling function for form urlencoded data strings.  Performs
    the conversion from the raw url encoded string using the ``urlparse``
    library to handle the basic parsing.  (HTTP allows for the same key to be
    used multiple times, as this behaviour is often handled differently
    between applications, this does not attempt to handle these and it should
    be defined by the user based on the application being communicated with)
    """
    data = parse_qs(body)
    for key, value in data.items():
        if len(value) == 1:
            data[key] = value[0]

    return data


from restler import Response

Response.add_mimetype("application/x-www-form-urlencoded", handler)
コード例 #3
0
import json


def handler(response, body):
    """ MIMEtype handling function for JSON data strings.  Performs the
    conversion fromt he raw JSON string into the rich JSON structure using the
    built in ``json`` library.
    """
    return json.loads(body)

from restler import Response
Response.add_mimetype("application/json", handler)