qs_codec.models package

Submodules

qs_codec.models.decode_options module

This module contains the DecodeOptions class that configures the output of decode.

class qs_codec.models.decode_options.DecodeOptions(allow_dots: bool = None, decode_dot_in_keys: bool = None, allow_empty_lists: bool = False, list_limit: int = 20, charset: ~qs_codec.enums.charset.Charset = Charset.UTF8, charset_sentinel: bool = False, comma: bool = False, delimiter: str | ~typing.Pattern[str] = '&', depth: int = 5, parameter_limit: int | float = 1000, duplicates: ~qs_codec.enums.duplicates.Duplicates = Duplicates.COMBINE, ignore_query_prefix: bool = False, interpret_numeric_entities: bool = False, parse_lists: bool = True, strict_null_handling: bool = False, decoder: ~typing.Callable[[str | None, ~qs_codec.enums.charset.Charset | None], ~typing.Any] = <bound method DecodeUtils.decode of <class 'qs_codec.utils.decode_utils.DecodeUtils'>>)[source]

Bases: object

Options that configure the output of decode.

allow_dots: bool = None

Set to True to decode dot dict notation in the encoded input.

allow_empty_lists: bool = False

Set to True to allow empty list values inside dicts in the encoded input.

charset: Charset = _CharsetDataMixin(encoding='utf-8')

The character encoding to use when decoding the input.

charset_sentinel: bool = False

Some services add an initial utf8=✓ value to forms so that old InternetExplorer versions are more likely to submit the form as utf-8. Additionally, the server can check the value against wrong encodings of the checkmark character and detect that a query string or application/x-www-form-urlencoded body was not sent as utf-8, e.g. if the form had an accept-charset parameter or the containing page had a different character set.

qs_codec supports this mechanism via the charset_sentinel option. If specified, the utf-8 parameter will be omitted from the returned dict. It will be used to switch to LATIN1 or UTF8 mode depending on how the checkmark is encoded.

Important: When you specify both the charset option and the charset_sentinel option, the charset will be overridden when the request contains a utf-8 parameter from which the actual charset can be deduced. In that sense the charset will behave as the default charset rather than the authoritative charset.

comma: bool = False

Set to True to parse the input as a comma-separated value. Note: nested dict s, such as 'a={b:1},{c:d}' are not supported.

decode_dot_in_keys: bool = None

Set to True to decode dots in keys. Note: it implies allow_dots, so decode will error if you set decode_dot_in_keys to True, and allow_dots to False.

classmethod decoder(string: str | None, charset: Charset | None = Charset.UTF8) str | None

Set a Callable to affect the decoding of the input.

delimiter: str | Pattern[str] = '&'

The delimiter to use when splitting key-value pairs in the encoded input. Can be a str or a Pattern.

depth: int = 5

By default, when nesting dicts qs_codec will only decode up to 5 children deep. This depth can be overridden by setting the depth. The depth limit helps mitigate abuse when qs_codec is used to parse user input, and it is recommended to keep it a reasonably small number.

duplicates: Duplicates = 1

Change the duplicate key handling strategy.

ignore_query_prefix: bool = False

Set to True to ignore the leading question mark query prefix in the encoded input.

interpret_numeric_entities: bool = False

Set to True to interpret HTML numeric entities (&#...;) in the encoded input.

list_limit: int = 20

qs_codec will limit specifying indices in a list to a maximum index of 20. Any list members with an index of greater than 20 will instead be converted to a dict with the index as the key. This is needed to handle cases when someone sent, for example, a[999999999] and it will take significant time to iterate over this huge list. This limit can be overridden by passing a list_limit option.

parameter_limit: int | float = 1000

For similar reasons, by default qs_codec will only parse up to 1000 parameters. This can be overridden by passing a parameter_limit option.

parse_lists: bool = True

To disable list parsing entirely, set parse_lists to False.

strict_null_handling: bool = False

Set to true to decode values without = to None.

qs_codec.models.encode_options module

This module contains the EncodeOptions class that configures the output of encode.

class qs_codec.models.encode_options.EncodeOptions(allow_dots: bool = None, add_query_prefix: bool = False, allow_empty_lists: bool = False, indices: bool | None = None, list_format: ~qs_codec.enums.list_format.ListFormat = ListFormat.INDICES, charset: ~qs_codec.enums.charset.Charset = Charset.UTF8, charset_sentinel: bool = False, delimiter: str = '&', encode: bool = True, encode_dot_in_keys: bool = None, encode_values_only: bool = False, format: ~qs_codec.enums.format.Format = Format.RFC3986, filter: ~typing.Callable | ~typing.List[str | int] | None = None, skip_nulls: bool = False, serialize_date: ~typing.Callable[[~datetime.datetime], str | None] = <function EncodeUtils.serialize_date>, encoder: ~typing.Callable[[~typing.Any, ~qs_codec.enums.charset.Charset | None, ~qs_codec.enums.format.Format | None], str] = <property object>, strict_null_handling: bool = False, comma_round_trip: bool | None = None, sort: ~typing.Callable[[~typing.Any, ~typing.Any], int] | None = None)[source]

Bases: object

Options that configure the output of encode.

add_query_prefix: bool = False

Set to True to add a question mark ? prefix to the encoded output.

allow_dots: bool = None

Set to True to use dot dict notation in the encoded output.

allow_empty_lists: bool = False

Set to True to allow empty list s in the encoded output.

charset: Charset = _CharsetDataMixin(encoding='utf-8')

The character encoding to use.

charset_sentinel: bool = False

Set to True to announce the character by including an utf8=✓ parameter with the proper encoding of the checkmark, similar to what Ruby on Rails and others do when submitting forms.

comma_round_trip: bool | None = None

When list_format is set to ListFormat.COMMA, you can also set comma_round_trip option to True or False, to append [] on single-item lists, so that they can round trip through a parse.

delimiter: str = '&'

The delimiter to use when joining key-value pairs in the encoded output.

encode: bool = True

Set to False to disable encoding.

encode_dot_in_keys: bool = None

Encode dict keys using dot notation by setting encode_dot_in_keys to True. Caveat: When encode_values_only is True as well as encode_dot_in_keys, only dots in keys and nothing else will be encoded.

encode_values_only: bool = False

Encoding can be disabled for keys by setting the encode_values_only to True.

property encoder: Callable[[Any, Charset | None, Format | None], str]

Set an Encoder to affect the encoding of values. Note: the encoder option does not apply if encode is False.

filter: Callable | List[str | int] | None = None

Use the filter option to restrict which keys will be included in the encoded output. If you pass a Callable, it will be called for each key to obtain the replacement value. If you pass a list, it will be used to select properties and list indices to be encoded.

format: Format = _FormatDataMixin(format_name='RFC3986', formatter=<function Formatter.rfc3986>)

The encoding format to use. The default format is Format.RFC3986 which encodes ' ' to %20 which is backward compatible. You can also set format to Format.RFC1738 which encodes ' ' to +.

indices: bool | None = None

Use list_format instead.

Type:

Deprecated

list_format: ListFormat = _ListFormatDataMixin(list_format_name='INDICES', generator=<function ListFormatGenerator.indices>)

The list encoding format to use.

serialize_date() str

If you only want to override the serialization of datetime objects, you can provide a Callable.

skip_nulls: bool = False

Set to True to completely skip encoding keys with None values.

sort: Callable[[Any, Any], int] | None = None

Set a Callable to affect the order of parameter keys.

strict_null_handling: bool = False

Set to True to distinguish between null values and empty strings. This way the encoded string None values will have no = sign.

qs_codec.models.undefined module

Undefined class definition.

class qs_codec.models.undefined.Undefined[source]

Bases: object

Singleton class to represent undefined values.

qs_codec.models.weak_wrapper module

A wrapper that allows weak references to be used as dictionary keys.

class qs_codec.models.weak_wrapper.WeakWrapper(value: Any)[source]

Bases: object

A wrapper that allows weak references to be used as dictionary keys.

value: Any

Module contents