def parse_and_error_handle(parser, data, upload_format):
    """
    Standardized parsing and error handling for parsing. Returns the final
    HTTP body to send back to the uploader after parsing, or error messages.

    :param callable parser: The parser function to use to parse ``data``.
    :param object data: An dict or str of parser-specific data to parse
        using the callable specified in ``parser``.
    :param str upload_format: Upload format identifier for the logs.
    :rtype: str
    :returns: The HTTP body to return.
    """
    try:
        parsed_message = parser(data)
    except (
        EMDSError, MalformedUploadError, TypeError, __HOLE__
    ) as exc:
        # Something bad happened. We know this will return at least a
        # semi-useful error message, so do so.
        response.status = 400
        logger.error("Error to %s: %s" % (get_remote_address(), exc.message))
        return exc.message

    ip_hash_salt = settings.GATEWAY_IP_KEY_SALT
    if ip_hash_salt:
        # If an IP hash is set, salt+hash the uploader's IP address and set
        # it as the EMDR upload key value.
        ip_hash = hashlib.sha1(ip_hash_salt + get_remote_address()).hexdigest()
        parsed_message.upload_keys.append({'name': 'EMDR', 'key': ip_hash})

    # Sends the parsed MarketOrderList or MarketHistoryList to the Announcers
    # as compressed JSON.
    gevent.spawn(order_pusher.push_message, parsed_message)

    logger.info("Accepted %s %s upload from %s" % (
        upload_format, parsed_message.list_type, get_remote_address()
    ))
    # Goofy, but apparently expected by EVE Market Data Uploader.
    return '1'
dataset/ETHPy150Open gtaylor/EVE-Market-Data-Relay/emdr/daemons/gateway/wsgi.py/parse_and_error_handle