Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/site-packages/proto/marshal/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/site-packages/proto/marshal/__pycache__/marshal.cpython-38.pyc
U

O��g�.�@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�rt|d�rdStS)N�	to_python�to_protoT)�hasattr�NotImplemented)�cls�C�r�B/opt/cppython/lib/python3.8/site-packages/proto/marshal/marshal.py�__subclasshook__*szRule.__subclasshook__N)�__name__�
__module__�__qualname__�__doc__�classmethodrrrrrr'src@sbeZdZdZdd�Zdeed�dd�Zdd	�Zd
d�Z	dd�e
d�d
d�Zdd�e
d�dd�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__DszBaseMarshal.__init__N)�
proto_type�rulecs<|r$t|t�std��|�j�<dStd���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�std��|��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+r1rr0r�registerIs
�
zBaseMarshal.registercCsX|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$�clearr4r�	TimestamprZ
TimestampRulerZDurationZDurationRulerZ	FieldMaskrZ
FieldMaskRulerZ	BoolValuerZ
BoolValueRuleZ
BytesValueZBytesValueRuleZDoubleValueZDoubleValueRuleZ
FloatValueZFloatValueRuleZ
Int32ValueZInt32ValueRuleZ
Int64ValueZInt64ValueRuleZStringValueZStringValueRuleZUInt32ValueZUInt32ValueRuleZUInt64ValueZUInt64ValueRuler�ValuerZ	ValueRule�	ListValueZ
ListValueRule�StructZ
StructRulerZBYTES�pb_bytesZ	BytesRuler
ZSTRINGY_NUMBER_RULESZ_proto_type)r(r-rrrr'{s&

zBaseMarshal.resetcCsZ|j�||j�}||jkrVt|d�rV|j��D]&\}}|j�||j�}||jkr.qVq.|S)N�
_instances)r$�getr&rr=�items)r(r*r+�_�instancerrr�get_rule�s
zBaseMarshal.get_rule��absentcCs�t|�}|tjkrt||d�S|tjkrLt|t�r@t|||d�St||d�S|tjksb|jtj	krnt
||d�S|j|d�j||d�S)Nr5)r6r*�r*rC)
r3rZrepeated_composite_typesrZrepeated_scalar_typesr2r
Zmap_composite_typesrZmap_composite_type_namesr	rBr)r(r*�valuerDZ
value_typerrrr�s


�
�zBaseMarshal.to_pythonF)�strictcs��tjtjtjfkrRt|ttf�r(|jSt|tt	f�rRt
|���fdd�|D��St|t�r��jj
r��j��jr�t
��j����fdd�|��D�S�j�d��|�}|r�t|��s�tdj�j|jjd���|S)Nc3s|]}���|�VqdSr#�r)�.0�ir0rr�	<genexpr>�sz'BaseMarshal.to_proto.<locals>.<genexpr>csi|]\}}|���|��qSrrH)rI�k�v)�recursive_typer(rr�
<dictcomp>�sz(BaseMarshal.to_proto.<locals>.<dictcomp>rEzLParameter must be instance of the same class; expected {expected}, got {got})�expected�got)rr9r:r;r2r
r	Zpb�list�tupler3�dictZ
DESCRIPTORZhas_optionsZ
GetOptionsZ	map_entryrFr?rBrr/�formatr�	__class__)r(r*rFrG�pb_valuer)r*rNr(rr�s2�

�
���zBaseMarshal.to_proto)N)
rrrr r)r3rr4r'rB�boolrrrrrrr"1s2'r"cs<eZdZdZiZed��fdd�Zed��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�|�}|dkr*t��|�}|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)r=r>�super�__new__)rrZ�klass�rVrrr\szMarshal.__new__cs||_t|d�st���dS)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(rZr^rrr)s
zMarshal.__init__)	rrrr r=�strr\r)�
__classcell__rrr^rrY�srYc@s,eZdZdZdd�ed�dd�Zdd�ZdS)r%z#A catch-all rule that does nothing.NrCcCs|Sr#r)r(rWrDrrrr"szNoopRule.to_pythoncCs|Sr#r)r(rFrrrr%szNoopRule.to_proto)rrrr rXrrrrrrr%sr%)rY)�abc�enumZgoogle.protobufrrrrrrZ
proto.marshalrZproto.marshal.collectionsr	r
rZproto.marshal.rulesrr<r
rrrrZproto.primitivesr�ABCrr"rYr%�__all__rrrr�<module>s0
J%

F1le Man4ger