qs_codec.utils package

Submodules

qs_codec.utils.decode_utils module

Decode utility methods used by the library.

class qs_codec.utils.decode_utils.DecodeUtils[source]

Bases: object

A collection of decode utility methods used by the library.

UNESCAPE_PATTERN: Pattern[str] = re.compile('%u(?P<unicode>[0-9A-Fa-f]{4})|%(?P<hex>[0-9A-Fa-f]{2})', re.IGNORECASE)
classmethod decode(string: str | None, charset: Charset | None = Charset.UTF8) str | None[source]

Decode a URL-encoded string.

For non-UTF8 charsets (specifically Charset.LATIN1), it replaces plus signs with spaces and applies a custom unescape for percent-encoded hex sequences. Otherwise, it defers to urllib.parse.unquote.

classmethod unescape(string: str) str[source]

A Python representation of the deprecated JavaScript unescape function.

This method replaces both “%XX” and “%uXXXX” escape sequences with their corresponding characters.

Example

unescape(“%u0041%20%42”) -> “A B”

qs_codec.utils.encode_utils module

A collection of encode utility methods used by the library.

class qs_codec.utils.encode_utils.EncodeUtils[source]

Bases: object

A collection of encode utility methods used by the library.

HEX_TABLE: Tuple[str, ...] = ('%00', '%01', '%02', '%03', '%04', '%05', '%06', '%07', '%08', '%09', '%0A', '%0B', '%0C', '%0D', '%0E', '%0F', '%10', '%11', '%12', '%13', '%14', '%15', '%16', '%17', '%18', '%19', '%1A', '%1B', '%1C', '%1D', '%1E', '%1F', '%20', '%21', '%22', '%23', '%24', '%25', '%26', '%27', '%28', '%29', '%2A', '%2B', '%2C', '%2D', '%2E', '%2F', '%30', '%31', '%32', '%33', '%34', '%35', '%36', '%37', '%38', '%39', '%3A', '%3B', '%3C', '%3D', '%3E', '%3F', '%40', '%41', '%42', '%43', '%44', '%45', '%46', '%47', '%48', '%49', '%4A', '%4B', '%4C', '%4D', '%4E', '%4F', '%50', '%51', '%52', '%53', '%54', '%55', '%56', '%57', '%58', '%59', '%5A', '%5B', '%5C', '%5D', '%5E', '%5F', '%60', '%61', '%62', '%63', '%64', '%65', '%66', '%67', '%68', '%69', '%6A', '%6B', '%6C', '%6D', '%6E', '%6F', '%70', '%71', '%72', '%73', '%74', '%75', '%76', '%77', '%78', '%79', '%7A', '%7B', '%7C', '%7D', '%7E', '%7F', '%80', '%81', '%82', '%83', '%84', '%85', '%86', '%87', '%88', '%89', '%8A', '%8B', '%8C', '%8D', '%8E', '%8F', '%90', '%91', '%92', '%93', '%94', '%95', '%96', '%97', '%98', '%99', '%9A', '%9B', '%9C', '%9D', '%9E', '%9F', '%A0', '%A1', '%A2', '%A3', '%A4', '%A5', '%A6', '%A7', '%A8', '%A9', '%AA', '%AB', '%AC', '%AD', '%AE', '%AF', '%B0', '%B1', '%B2', '%B3', '%B4', '%B5', '%B6', '%B7', '%B8', '%B9', '%BA', '%BB', '%BC', '%BD', '%BE', '%BF', '%C0', '%C1', '%C2', '%C3', '%C4', '%C5', '%C6', '%C7', '%C8', '%C9', '%CA', '%CB', '%CC', '%CD', '%CE', '%CF', '%D0', '%D1', '%D2', '%D3', '%D4', '%D5', '%D6', '%D7', '%D8', '%D9', '%DA', '%DB', '%DC', '%DD', '%DE', '%DF', '%E0', '%E1', '%E2', '%E3', '%E4', '%E5', '%E6', '%E7', '%E8', '%E9', '%EA', '%EB', '%EC', '%ED', '%EE', '%EF', '%F0', '%F1', '%F2', '%F3', '%F4', '%F5', '%F6', '%F7', '%F8', '%F9', '%FA', '%FB', '%FC', '%FD', '%FE', '%FF')

Hex table of all 256 characters

RFC1738_SAFE_CHARS = {40, 41, 45, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 95, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 126}

0-9, A-Z, a-z, -, ., _, ~, (, )

RFC1738_SAFE_POINTS: Set[int] = {40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 95, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122}

0-9, A-Z, a-z, @, *, _, -, +, ., /, (, )

SAFE_ALPHA: Set[int] = {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122}

0-9, A-Z, a-z

SAFE_CHARS: Set[int] = {45, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 95, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 126}

0-9, A-Z, a-z, -, ., _, ~

SAFE_POINTS: Set[int] = {42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 95, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122}

0-9, A-Z, a-z, @, *, _, -, +, ., /

classmethod encode(value: Any, charset: Charset | None = Charset.UTF8, format: Format | None = Format.RFC3986) str[source]

Encode a value to a URL-encoded string.

classmethod escape(string: str, format: Format | None = Format.RFC3986) str[source]

A Python representation the deprecated JavaScript escape function.

https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/escape

static serialize_date(dt: datetime) str[source]

Serialize a datetime object to an ISO 8601 string.

qs_codec.utils.str_utils module

Utility functions for working with strings.

qs_codec.utils.str_utils.code_unit_at(string: str, index: int) int[source]

Returns the 16-bit UTF-16 code unit at the given index.

This function first encodes the string in UTF-16 little endian format, then calculates the code unit at the given index. The code unit is calculated by taking the byte at the index and adding it to 256 times the next byte. This is because UTF-16 represents each code unit with two bytes, and in little endian format, the least significant byte comes first.

Adapted from https://api.dart.dev/stable/3.3.3/dart-core/String/codeUnitAt.html

qs_codec.utils.utils module

A collection of utility methods used by the library.

class qs_codec.utils.utils.Utils[source]

Bases: object

A collection of utility methods used by the library.

static apply(val: list | tuple | Any, fn: Callable) List | Any[source]

Apply a function to a value or a list of values.

static combine(a: list | tuple | Any, b: list | tuple | Any) List[source]

Combine two lists or values.

static compact(value: Dict[str, Any]) Dict[str, Any][source]

Remove all Undefined values from a dictionary.

static is_non_nullish_primitive(val: Any, skip_nulls: bool = False) bool[source]

Check if a value is a non-nullish primitive.

static merge(target: ~typing.Mapping[str, ~typing.Any] | ~typing.List[~typing.Any] | ~typing.Tuple | None, source: ~typing.Mapping[str, ~typing.Any] | ~typing.List[~typing.Any] | ~typing.Tuple | ~typing.Any | None, options: ~qs_codec.models.decode_options.DecodeOptions = DecodeOptions(allow_dots=False, decode_dot_in_keys=False, allow_empty_lists=False, list_limit=20, charset=<Charset.UTF8: encoding='utf-8'>, charset_sentinel=False, comma=False, delimiter='&', depth=5, parameter_limit=1000, duplicates=<Duplicates.COMBINE: 1>, ignore_query_prefix=False, interpret_numeric_entities=False, parse_lists=True, strict_depth=False, strict_null_handling=False, raise_on_limit_exceeded=False, decoder=<bound method DecodeUtils.decode of <class 'qs_codec.utils.decode_utils.DecodeUtils'>>)) Dict[str, Any] | List | Tuple | Any[source]

Merge two objects together.

Module contents