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_depth: bool = False, 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 dotdict
notation in the encoded input.
- allow_empty_lists: bool = False¶
Set to
True
to allow emptylist
values insidedict
s 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 asutf-8
. Additionally, the server can check the value against wrong encodings of the checkmark character and detect that a query string orapplication/x-www-form-urlencoded
body was not sent asutf-8
, e.g. if the form had anaccept-charset
parameter or the containing page had a different character set.qs_codec
supports this mechanism via thecharset_sentinel
option. If specified, theutf-8
parameter will be omitted from the returneddict
. It will be used to switch toLATIN1
orUTF8
mode depending on how the checkmark is encoded.Important: When you specify both the
charset
option and thecharset_sentinel
option, thecharset
will be overridden when the request contains autf-8
parameter from which the actual charset can be deduced. In that sense thecharset
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: nesteddict
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 impliesallow_dots
, sodecode
will error if you setdecode_dot_in_keys
toTrue
, andallow_dots
toFalse
.
- 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 aPattern
.
- depth: int = 5¶
By default, when nesting
dict
sqs_codec
will only decode up to 5 children deep. This depth can be overridden by setting thedepth
. The depth limit helps mitigate abuse whenqs_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 alist
to a maximum index of20
. Anylist
members with an index of greater than20
will instead be converted to adict
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 hugelist
. This limit can be overridden by passing alist_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 aparameter_limit
option.
- parse_lists: bool = True¶
To disable
list
parsing entirely, setparse_lists
toFalse
.
- strict_depth: bool = False¶
Set to
True
to throw an error when the input exceeds thedepth
limit.
- strict_null_handling: bool = False¶
Set to true to decode values without
=
toNone
.
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 dotdict
notation in the encoded output.
- allow_empty_lists: bool = False¶
Set to
True
to allow emptylist
s in the encoded output.
- charset_sentinel: bool = False¶
Set to
True
to announce the character by including anutf8=✓
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 toListFormat.COMMA
, you can also setcomma_round_trip
option toTrue
orFalse
, to append[]
on single-itemlist
s, 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 settingencode_dot_in_keys
toTrue
. Caveat: Whenencode_values_only
isTrue
as well asencode_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
toTrue
.
- property encoder: Callable[[Any, Charset | None, Format | None], str]¶
Set an
Encoder
to affect the encoding of values. Note: theencoder
option does not apply ifencode
isFalse
.
- 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 aCallable
, it will be called for each key to obtain the replacement value. If you pass alist
, it will be used to select properties andlist
indices to be encoded.
- format: Format = _FormatDataMixin(format_name='RFC3986', formatter=<function Formatter.rfc3986>)¶
The encoding format to use. The default
format
isFormat.RFC3986
which encodes' '
to%20
which is backward compatible. You can also setformat
toFormat.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 aCallable
.
- skip_nulls: bool = False¶
Set to
True
to completely skip encoding keys withNone
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 betweennull
values and emptystr
ings. This way the encoded stringNone
values will have no=
sign.
qs_codec.models.undefined module¶
Undefined class definition.
qs_codec.models.weak_wrapper module¶
A wrapper that allows weak references to be used as dictionary keys.