duck.http.querydict

Module for implementation of a basic Query Dictionary

Module Contents

Classes

FixedQueryDict

A custom dictionary-like class that accepts a dictionary with any number of keys. This class does not support deletion or modification of keys but only modification of values.

QueryDict

A dictionary subclass that allows multiple values for a single key.

API

class duck.http.querydict.FixedQueryDict(data: dict)[source]

Bases: duck.http.querydict.QueryDict

A custom dictionary-like class that accepts a dictionary with any number of keys. This class does not support deletion or modification of keys but only modification of values.

Initialization

Initializes the FixedQueryDict with a dictionary of any number of keys.

Parameters:

data – Dictionary with any number of keys.

Raises:

ValueError – If the input is not a dictionary.

__delitem__(key)[source]

Raises an error as deletion of keys is not supported.

Parameters:

key – The key to delete.

Raises:

KeyError – Always raised as deletion is not supported.

__getitem__(key)[source]

Retrieves the value associated with the given key.

Parameters:

key – The key to look up.

Returns:

The value associated with the key.

__repr__()[source]

Returns a string representation of the QueryDict.

Returns:

String representation of the QueryDict.

Return type:

str

__setitem__(key, value)[source]

Sets the value for the given key if the key is allowed.

Parameters:
  • key – The key to set the value for.

  • value – The value to set.

Raises:

KeyError – If the key is not one of the allowed keys.

__slots__

(‘_data’, ‘_keys’)

get(key)[source]

Retrieves the value associated with the given key, or None if the key is not found.

Parameters:

key – The key to look up.

Returns:

The value associated with the key, or None if the key is not found.

update(other: dict)[source]

Updates the FixedQueryDict with values from another dictionary.

Parameters:

other – Dictionary to update the FixedQueryDict with.

Raises:

KeyError – If any key in the other dictionary is not one of the allowed keys.

class duck.http.querydict.QueryDict[source]

Bases: dict

A dictionary subclass that allows multiple values for a single key.

Initialization

Initialize self. See help(type(self)) for accurate signature.

__delitem__(key: str) None[source]

Deletes a key from the QueryDict.

__getitem__(key: str)[source]

Returns the first value for the key, or raises KeyError if the key is missing.

__repr__()[source]
__setitem__(key: str, value) None[source]

Ensures values are always stored as lists.

__slots__

()

appendlist(key: str, value) None[source]

Appends a value to a key’s list.

clear() None[source]

Removes all items from the QueryDict.

copy()[source]

Returns a copy of the QueryDict .

get(key: str, default=None)[source]

Retrieves the first value for a key, or default if not found.

getlist(key: str, default=None)[source]

Retrieves all values for a key as a list.

items()[source]

Returns all key-value pairs in the QueryDict.

keys()[source]

Returns all keys in the QueryDict.

pop(key: str, default=None)[source]

Removes a key and returns its list of values.

poplist(key: str, default=None)[source]

Removes a key and returns its values as a list.

setlist(key: str, values: list) None[source]

Sets a key to multiple values, replacing existing ones.

update(other=None, **kwargs) None[source]

Merges values instead of replacing them.

values()[source]

Returns all values in the QueryDict.