benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 3a0ca97c-3ef5-550e-a1c0-cc93faec673d

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import cgi
import http.server
import json

def task_func():
    """
    The function creates an HTTP POST request handler for processing incoming data. The data is expected to be in JSON format with a key 'data'. The handler responds with a 200 success message if the data is valid, or an error message otherwise.

    Notes:
    - If the 'Content-Type' header is not 'application/json', the server responds with a 400 Bad Request status and a JSON object:
      {"status": "error", "message": "Content-Type header is not application/json"}.
    - If the received JSON object does not contain a 'data' key, the response is a 400 Bad Request with a JSON object:
      {"status": "error", "message": "No data received"}.
    - For successfully processed requests, the server responds with a 200 OK status and a JSON object:
      {"status": "success", "message": "Data received successfully."}.

    Returns:
    class: A class that is a subclass of http.server.BaseHTTPRequestHandler, designed to handle HTTP POST requests.

    Requirements:
    - cgi
    - http.server
    - json

    Example:
    >>> handler = task_func()
    >>> server = http.server.HTTPServer(('127.0.0.1', 8080), handler)
    >>> server.serve_forever()
    """

instruct prompt

The function creates an HTTP POST request handler for processing incoming data. The data is expected to be in JSON format with a key 'data'. The handler responds with a 200 success message if the data is valid, or an error message otherwise.
Note that: Notes: If the 'Content-Type' header is not 'application/json', the server responds with a 400 Bad Request status and a JSON object: {"status": "error", "message": "Content-Type header is not application/json"}. If the received JSON object does not contain a 'data' key, the response is a 400 Bad Request with a JSON object: {"status": "error", "message": "No data received"}. For successfully processed requests, the server responds with a 200 OK status and a JSON object: {"status": "success", "message": "Data received successfully."}.
The function should output with:
    class: A class that is a subclass of http.server.BaseHTTPRequestHandler, designed to handle HTTP POST requests.
You should write self-contained code starting with:

Code

import cgi
import http.server
import json
def task_func():

code prompt

Code

import cgi
import http.server
import json
def task_func():

entry point

task_func

libs

  • http
  • cgi
  • json

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import