;i.\ddlZddlZddlmZddlmZddlmZddlmZddlmZddlmZddl m Z dd l m Z dd l m Z dd l mZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZGddejZGddZGddeZGddZdZdS)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(eZdZdZedZdS)Rulez,Abstract class definition for marshal rules.cTt|drt|drdStS)N to_pythonto_protoT)hasattrNotImplemented)clsCs IC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\proto/marshal/marshal.py__subclasshook__zRule.__subclasshook__*s0 1k " " wq*'='= 4N)__name__ __module__ __qualname____doc__ classmethodrrrrr's366[rrcZeZdZdZdZddedefdZdZdZ dd d e fd Z d d de fdZ dS) BaseMarshalaThe 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. cbi|_t|_|dSN)_rulesNoopRule_noopreset)selfs r__init__zBaseMarshal.__init__Ds% ZZ  rN proto_typerulec|r0t|tstd|j<dSdtffd }|S)aRegister 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_classctt|tstd|j<|S)NzJMarshal rule subclasses must implement `to_proto` and `to_python` methods.) issubclassr TypeErrorr*)r3r0r.s rregister_rule_classz1BaseMarshal.register..register_rule_classmsFj$// : '1jllDK # r) isinstancerr6r*type)r.r0r1r7s`` rregisterzBaseMarshal.registerIs|,  dD)) : '+DK # F D       #"rc|j|tjt j|tjt j |tj tj |tjt!j|tjt!j|tjt!j|tjt!j|tjt!j|tjt!j|tjt!j|tjt!j|tj t!j!|tDj#tIj%||tDj&tIj'||tDj(tIj)||tTj+tYj-t\j/D]%}||j0|&dS)z(Reset the registry to its initial state.marshalN)1r*clearr:r Timestampr TimestampRulerDuration DurationRuler FieldMaskr FieldMaskRuler BoolValuer BoolValueRule BytesValueBytesValueRule DoubleValueDoubleValueRule FloatValueFloatValueRule Int32ValueInt32ValueRule Int64ValueInt64ValueRule StringValueStringValueRule UInt32ValueUInt32ValueRule UInt64ValueUInt64ValueRulerValuer ValueRule ListValue ListValueRuleStruct StructRulerBYTESpb_bytes BytesRulerSTRINGY_NUMBER_RULES _proto_type)r.r3s rr-zBaseMarshal.reset{sp  m-u/B/D/DEEE l+U-?-A-ABBB n. 0H0J0JKKK l,h.D.F.FGGG l-x/F/H/HIII l.0H0J0JKKK l-x/F/H/HIII l-x/F/H/HIII l-x/F/H/HIII l.0H0J0JKKK l.0H0J0JKKK l.0H0J0JKKK j&(8(F(F(FGGG j*F,@,N,N,NOOO j'):4)H)H)HIII iox'9';';<<<*> @ @J MM*0**,, ? ? ? ? @ @rc|j||j}||jkr\t|drL|jD]2\}}|j||j}||jkrn3|S)N _instances)r*getr,rrcitems)r.r0r1_instances rget_rulezBaseMarshal.get_rules{z4:66 4:  '$ "="= #4466   8**:tzBB4:%%E& rabsentrjct|}|tjvrt||S|tjvr8t |trt|||St ||S|tjvs|jtj vrt||S| | ||S)Nr<)r=r0r0ri) r9r repeated_composite_typesr repeated_scalar_typesr8r map_composite_typesr map_composite_type_namesr rhr)r.r0valuerj value_types rrzBaseMarshal.to_pythons%[[ 8 8 8$UD999 9 5 5 5*d++ 5(TTTTt4444 &4 4 4"f&EEEt444 4}} }33==eF=SSSrF)strictrsctjtjtjfvrdt |t t fr|jSt |ttfr%t|fd|DSt |trgj j r[j jr=tjfd|DS|}|rCt |s3t)dj|jj|S)Nc3DK|]}|VdSr)r).0ir0r.s r z'BaseMarshal.to_proto..s1"O"OA4==Q#?#?"O"O"O"O"O"OrcDi|]\}}||Sr%rv)rwkvrecursive_typer.s r z(BaseMarshal.to_proto..s-RRRDAqAt}}^Q77RRRrrlzLParameter must be instance of the same class; expected {expected}, got {got})expectedgot)rrWrYr[r8r r pblisttupler9dict DESCRIPTOR has_options GetOptions map_entryrqrerhrr6formatr __class__)r.r0rqrspb_valuer}s`` @rrzBaseMarshal.to_protos         %(L!9:: x%$// P"tE{{"O"O"O"O"O"O"O"OOOO eT " " S  ! - S%0022< S"**,,"455NRRRRREKKMMRRR R==J=77@@GG  *Xz:: 117'0 *32822 rr)) r r!r"r#r/r9rr:r-rhboolrrr%rrr'r'1s$ 0#0#40#t0#0#0#0#d%@%@%@N >BTTTdTTTT0=B---T------rr'c<eZdZdZiZdeffd Zdeffd ZxZS)Marshala The 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. namec|j|}|+t|x}|j|<|S)zCreate 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. )rcrdsuper__new__)rrklassrs rrzMarshal.__new__sE""4(( =+077??3+?+? ?ECN4( rcz||_t|ds"tdSdS)zInstantiate 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)_namerrr/)r.rrs rr/zMarshal.__init__sD tX&&  GG         r) r r!r"r#rcstrrr/ __classcell__)rs@rrrszJ c                 rrc*eZdZdZdddefdZdZdS)r+z#A catch-all rule that does nothing.Nrirjc|Sr)r%)r.rrjs rrzNoopRule.to_python"src|Sr)r%)r.rqs rrzNoopRule.to_proto%s r)r r!r"r#rrrr%rrr+r+sQ--48Trr+)r)abcenumgoogle.protobufrrrrrr proto.marshalr proto.marshal.collectionsr r r proto.marshal.rulesr r^rrrrrproto.primitivesrABCrr'rr+__all__r%rrrs ######(((((())))))******&&&&&&(((((( 222222......777777111111//////%%%%%%&&&&&&((((((******&&&&&&37FFFFFFFFR"""""k"""J r