benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf d599d687-c91e-5deb-a9fd-2a5ca9938bce

Problem

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

complete prompt

import random
import string
from django.http import HttpResponse


def task_func(request, session_expire_time):
    """
    This function creates a random session key comprising letters and digits with a specific length of 20,
    then sets this key in a cookie on an HttpResponse object with the specified expiration time.

    Parameters:
    request (django.http.HttpRequest): The incoming Django HttpRequest.
    session_expire_time (int): The expiration time for the session cookie in seconds.

    Returns:
    django.http.HttpResponse: A Django HttpResponse with the session key set in a cookie.

    Raises:
    ValueError: If the session key does not contain both letters and digits or
                the session key length is not equal to 20.

    Note:
    -   The function set the response content to "Session key generated successfully." if the session key
        is valid.

    Examples:
    >>> from django.conf import settings
    >>> from django.http import HttpRequest
    >>> if not settings.configured:
    ...     settings.configure()
    >>> request = HttpRequest()
    >>> response = task_func(request, 60)
    >>> 'session_key' in response.cookies
    True
    >>> len(response.cookies['session_key'].value) == 20
    True
    >>> response.cookies['session_key']['max-age'] == 60
    True

    Requirements:
    - django.http
    - django.conf
    - random
    - string
    """

instruct prompt

This function creates a random session key comprising letters and digits with a specific length of 20, then sets this key in a cookie on an HttpResponse object with the specified expiration time.
Note that: The function set the response content to "Session key generated successfully." if the session key is valid.
The function should raise the exception for: ValueError: If the session key does not contain both letters and digits or the session key length is not equal to 20.
The function should output with:
    django.http.HttpResponse: A Django HttpResponse with the session key set in a cookie.
You should write self-contained code starting with:

Code

import random
import string
from django.http import HttpResponse
def task_func(request, session_expire_time):

code prompt

Code

import random
import string
from django.http import HttpResponse
def task_func(request, session_expire_time):

entry point

task_func

libs

  • django
  • string
  • random

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