HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: sport3497 (1034)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib/python3.10/site-packages/proto/marshal/__pycache__/marshal.cpython-310.pyc
o

�h�.�@s"ddlZddlZddlmZddlmZddlmZddlmZddlmZddlmZddl	m
Z
dd	lmZdd
lm
Z
ddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZGdd�dej�ZGdd�d�ZGdd�de�ZGdd�d�ZdZdS)�N)�message)�duration_pb2)�
timestamp_pb2)�field_mask_pb2)�
struct_pb2)�wrappers_pb2)�compat)�MapComposite)�Repeated)�RepeatedComposite)�bytes)�stringy_numbers)�dates)�struct)�wrappers)�
field_mask)�	ProtoTypec@seZdZdZedd��ZdS)�Rulez,Abstract class definition for marshal rules.cCst|d�rt|d�rdStS)N�	to_python�to_protoT)�hasattr�NotImplemented)�cls�C�r�H/usr/local/CyberCP/lib/python3.10/site-packages/proto/marshal/marshal.py�__subclasshook__*szRule.__subclasshook__N)�__name__�
__module__�__qualname__�__doc__�classmethodrrrrrr'src@sdeZdZdZdd�Zddedefdd�Zd	d
�Zdd�Z	dd
�de
fdd�Zdd�de
fdd�ZdS)�BaseMarshala�The base class to translate between protobuf and Python classes.

    Protocol buffers defines many common types (e.g. Timestamp, Duration)
    which also exist in the Python standard library. The marshal essentially
    translates between these: it keeps a registry of common protocol buffers
    and their Python representations, and translates back and forth.

    The protocol buffer class is always the "key" in this relationship; when
    presenting a message, the declared field types are used to determine
    whether a value should be transformed into another class. Similarly,
    when accepting a Python value (when setting a field, for example),
    the declared field type is still used. This means that, if appropriate,
    multiple protocol buffer types may use the same Python type.

    The primary implementation of this is :class:`Marshal`, which should
    usually be used instead of this class directly.
    cCsi|_t�|_|��dS�N)�_rules�NoopRule�_noop�reset)�selfrrr�__init__DszBaseMarshal.__init__N�
proto_type�rulecs<|rt|t�std��|�j�<dSdtf��fdd�}|S)a�Register a rule against the given ``proto_type``.

        This function expects a ``proto_type`` (the descriptor class) and
        a ``rule``; an object with a ``to_python`` and ``to_proto`` method.
        Each method should return the appropriate Python or protocol buffer
        type, and be idempotent (e.g. accept either type as input).

        This function can also be used as a decorator::

            @marshal.register(timestamp_pb2.Timestamp)
            class TimestampRule:
                ...

        In this case, the class will be initialized for you with zero
        arguments.

        Args:
            proto_type (type): A protocol buffer message type.
            rule: A marshal object
        zIMarshal rule instances must implement `to_proto` and `to_python` methods.N�
rule_classcs"t|t�s	td��|��j�<|S)NzJMarshal rule subclasses must implement `to_proto` and `to_python` methods.)�
issubclassr�	TypeErrorr$)r,�r*r(rr�register_rule_classms
�z1BaseMarshal.register.<locals>.register_rule_class)�
isinstancerr.r$�type)r(r*r+r0rr/r�registerIs
�
zBaseMarshal.registercCsV|j��|�tjt���|�tjt�	��|�t
jt�
��|�tjt���|�tjt���|�tjt���|�tjt���|�tjt���|�tjt���|�tjt���|�tjt���|�tj t�!��|�t"j#t$j%|d��|�t"j&t$j'|d��|�t"j(t$j)|d��|�t*j+t,�-��t.j/D]
}|�|j0|��q�dS)z(Reset the registry to its initial state.��marshalN)1r$�clearr3r�	Timestampr�
TimestampRuler�Duration�DurationRuler�	FieldMaskr�
FieldMaskRuler�	BoolValuer�
BoolValueRule�
BytesValue�BytesValueRule�DoubleValue�DoubleValueRule�
FloatValue�FloatValueRule�
Int32Value�Int32ValueRule�
Int64Value�Int64ValueRule�StringValue�StringValueRule�UInt32Value�UInt32ValueRule�UInt64Value�UInt64ValueRuler�Valuer�	ValueRule�	ListValue�
ListValueRule�Struct�
StructRuler�BYTES�pb_bytes�	BytesRuler
�STRINGY_NUMBER_RULES�_proto_type)r(r,rrrr'{s(

�zBaseMarshal.resetcCs\|j�||j�}||jkr,t|d�r,|j��D]\}}|j�||j�}||jkr+|Sq|S)N�
_instances)r$�getr&rrZ�items)r(r*r+�_�instancerrr�get_rule�s
�zBaseMarshal.get_rule��absentracCs�t|�}|tjvrt||d�S|tjvr&t|t�r t|||d�St||d�S|tjvs1|jtj	vr7t
||d�S|j|d�j||d�S)Nr4)r5r*�r*r`)
r2r�repeated_composite_typesr�repeated_scalar_typesr1r
�map_composite_typesr�map_composite_type_namesr	r_r)r(r*�valuera�
value_typerrrr�s



zBaseMarshal.to_pythonF)�strictrics��tjtjtjfvr)t|ttf�r|jSt|tt	f�r)t
|���fdd�|D��St|t�rJ�jj
rJ�j��jrJt
��j����fdd�|��D�S�j�d��|�}|rft|��sftdj�j|jjd���|S)Nc3s�|]	}���|�VqdSr#�r)�.0�ir/rr�	<genexpr>�s�z'BaseMarshal.to_proto.<locals>.<genexpr>csi|]\}}|���|��qSrrj)rk�k�v)�recursive_typer(rr�
<dictcomp>�sz(BaseMarshal.to_proto.<locals>.<dictcomp>rbzLParameter must be instance of the same class; expected {expected}, got {got})�expected�got)rrOrQrSr1r
r	�pb�list�tupler2�dict�
DESCRIPTOR�has_options�
GetOptions�	map_entryrgr\r_rr.�formatr�	__class__)r(r*rgri�pb_valuer)r*rpr(rr�s4�

�
���zBaseMarshal.to_protor#)
rrrr r)r2rr3r'r_�boolrrrrrrr"1s2'r"cs<eZdZdZiZdef�fdd�Zdef�fdd�Z�ZS)�MarshalaThe translator between protocol buffer and Python instances.

    The bulk of the implementation is in :class:`BaseMarshal`. This class
    adds identity tracking: multiple instantiations of :class:`Marshal` with
    the same name will provide the same instance.
    �namecs.|j�|�}|durt��|�}|j|<|S)z�Create a marshal instance.

        Args:
            name (str): The name of the marshal. Instantiating multiple
                marshals with the same ``name`` argument will provide the
                same marshal each time.
        N)rZr[�super�__new__)rr��klass�r}rrr�szMarshal.__new__cs"||_t|d�st���dSdS)z�Instantiate a marshal.

        Args:
            name (str): The name of the marshal. Instantiating multiple
                marshals with the same ``name`` argument will provide the
                same marshal each time.
        r$N)�_namerr�r))r(r�r�rrr)s
�zMarshal.__init__)	rrrr rZ�strr�r)�
__classcell__rrr�rr��s
r�c@s,eZdZdZdd�defdd�Zdd�ZdS)	r%z#A catch-all rule that does nothing.Nr`racC�|Sr#r)r(r~rarrrr"�zNoopRule.to_pythoncCr�r#r)r(rgrrrr%r�zNoopRule.to_proto)rrrr rrrrrrrr%sr%)r�)�abc�enum�google.protobufrrrrrr�
proto.marshalr�proto.marshal.collectionsr	r
r�proto.marshal.rulesrrVr
rrrr�proto.primitivesr�ABCrr"r�r%�__all__rrrr�<module>s2
J%