K i(jdZddlmZGddeZdZdZdZdZGd d eZ d Z d Z d Z y)zContains FieldMask class.)FieldDescriptorcHeZdZdZdZdZdZdZdZdZ dZ d Z d d Z y ) FieldMaskz!Class for FieldMask message type.c~g}|jD]}|jt|dj|S)z;Converts FieldMask to string according to proto3 JSON spec.,)pathsappend_SnakeCaseToCamelCasejoin)selfcamelcase_pathspaths i/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/google/protobuf/internal/field_mask.py ToJsonStringzFieldMask.ToJsonStrings=O :2489: 88O $$ct|tstdj||j |r;|j dD]&}|j jt|(yy)z;Converts string to FieldMask according to proto3 JSON spec.z'FieldMask JSON value not a string: {!r}rN) isinstancestr ValueErrorformatClearsplitr r _CamelCaseToSnakeCase)r valuers rFromJsonStringzFieldMask.FromJsonStringsd eS ! @GGN OOJJL ++c"7$ /567 rcB|jD]}t||ryy)z=Checks whether the FieldMask is valid for Message Descriptor.FT)r _IsValidPath)r message_descriptorrs rIsValidForDescriptorzFieldMask.IsValidForDescriptor"s(  ,d 3 rc|j|jD]'}|jj|j)y)z:Gets all direct fields of Message Descriptor to FieldMask.N)rfieldsr r name)r rfields rAllFieldsFromDescriptorz!FieldMask.AllFieldsFromDescriptor)s6JJL#**$ jj #$rc<t|}|j|y)a:Converts a FieldMask to the canonical form. Removes paths that are covered by another path. For example, "foo.bar" is covered by "foo" and will be removed if "foo" is also in the FieldMask. Then sorts all paths in alphabetical order. Args: mask: The original FieldMask to be converted. N)_FieldMaskTree ToFieldMask)r masktrees rCanonicalFormFromMaskzFieldMask.CanonicalFormFromMask/s $ DTrct|t|t|}|j||j|y)z+Merges mask1 and mask2 into this FieldMask.N)_CheckFieldMaskMessager'MergeFromFieldMaskr()r mask1mask2r*s rUnionzFieldMask.Union<s85!5! % DE"Trct|t|t|}t}|jD]}|j|||j |y)z/Intersects mask1 and mask2 into this FieldMask.N)r-r'r IntersectPathr()r r/r0r* intersectionrs r IntersectzFieldMask.IntersectDsU5!5! % D!#L - |,-T"rcBt|}|j||||y)aMerges fields specified in FieldMask from source to destination. Args: source: Source message. destination: The destination message to be merged into. replace_message_field: Replace message field if True. Merge message field if False. replace_repeated_field: Replace repeated field if True. Append elements of repeated field if False. N)r' MergeMessage)r source destinationreplace_message_fieldreplace_repeated_fieldr*s rr7zFieldMask.MergeMessageNs( $ D 24JLrN)FF) __name__ __module__ __qualname____doc__ __slots__rrr r%r+r1r5r7rrrrr s9))%7$ #;@Lrrc|jd}|j}|D]V}|jj|}|)|js|j t jk7ry|j}X||jvS)z8Checks whether the path is valid for Message Descriptor..F) rpopfields_by_nameget is_repeatedtyper TYPE_MESSAGE message_type)rrpartslastr#r$s rrr`s **S/% $,d  - - 1 1$ 7E   o222 ++ , #22 22rc|j}|jdk7s|jjdk7r$tdj |j y)z0Raises ValueError if message is not a FieldMask.rz google/protobuf/field_mask.protozMessage {0} is not a FieldMask.N) DESCRIPTORr#filerr full_name)messagers rr-r-ns[)),""&HH 6==$$& ''Irc|g}d}|D]}|jrtdj||rL|jr"|j |j d}atdj||dk(rd}||z }|rtdj|dj |S)z2Converts a path name from snake_case to camelCase.FzYFail to print FieldMask to Json string: Path name {0} must not contain uppercase letters.znFail to print FieldMask to Json string: The character after a "_" must be a lowercase letter in path name {0}._TzFFail to print FieldMask to Json string: Trailing "_" in path name {0}.)isupperrrislowerr upperr ) path_nameresultafter_underscorecs rr r ws & ayy{  44:F94E GG  aggi   &y 13 3 c kf#& ))/ ): << rcg}|D]O}|dk(rtdj||jr|dz }||jz }K||z }Qdj |S)z3Converts a field name from camelCase to snake_case.rRz=Fail to parse FieldMask: Path name {0} must not contain "_"s.rS)rrrTlowerr )rWrXrZs rrrsv & aCx 44:F94E GGyy{ mf  f kf rc@eZdZdZdZd dZdZdZdZdZ d Z d Z y) r'a7Represents a FieldMask in a tree structure. For example, given a FieldMask "foo.bar,foo.baz,bar.baz", the FieldMaskTree will be: [_root] -+- foo -+- bar | | | +- baz | +- bar --- baz In the tree, each leaf node represents a field path. )_rootNc:i|_|r|j|yy)z"Initializes the tree by FieldMask.N)r^r.r field_masks r__init__z_FieldMaskTree.__init__sDJ j)rcH|jD]}|j|y)zMerges a FieldMask to the tree.N)r AddPath)r rars rr.z!_FieldMaskTree.MergeFromFieldMasks#   ll4rc|j}|jdD]}||vri||<n||sy||}|jy)a Adds a field path into the tree. If the field path to add is a sub-path of an existing field path in the tree (i.e., a leaf node), it means the tree already matches the given path so nothing will be added to the tree. If the path matches an existing non-leaf node in the tree, that non-leaf node will be turned into a leaf node with all its children removed because the path matches all the node's children. Otherwise, a new path will be added. Args: path: The field path to add. rBN)r^rclear)r rnoder#s rrdz_FieldMaskTree.AddPathsS ::D 3 T T Dz $Zd  JJLrcR|jt|jd|y)z!Converts the tree to a FieldMask.rSN)r_AddFieldPathsr^r`s rr(z_FieldMaskTree.ToFieldMasks4::r:.rc|j}|jdD]%}||vry||s|j|y||}'|j||y)zCalculates the intersection part of a field path with this tree. Args: path: The field path to calculates. intersection: The out tree to record the intersection part. rBN)r^rrd AddLeafNodes)r rr4rgr#s rr3z_FieldMaskTree.IntersectPathsb ::D 3 T DzT" $Zd dD)rcr|s|j||D]}|dz|z}|j|||!y)z/Adds leaf nodes begin with prefix to this tree.rBN)rdrk)r prefixrgr# child_paths rrkz_FieldMaskTree.AddLeafNodessB  ll60C<$&j  DJ/0rc6t|j||||y)zCMerge all fields specified by this tree from source to destination.N) _MergeMessager^)r r8r9replace_messagereplace_repeateds rr7z_FieldMaskTree.MergeMessages FK:JLr)N) r<r=r>r?r@rbr.rdr(r3rkr7rrrr'r's2 )*  2/ *"0Lrr'cHt|ts|jdS|S)z#Converts value to str if it is not.zutf-8)rrencode)rs r _StrConvertrus" E3  <<  ,rc |j}|D]}||}|j|}|%tdj||j|r|j s|j tjk7r%tdj||j|j|r#t|t||t|||||j rG|r|jt|t||} t||} | j| |j tjk(rV|r|jt||j|sct||jt|||jr|j|rt!||t|||jt|y)zDMerge all fields specified by a sub-tree from source to destination.Nz+Error: Can't find field {0} in message {1}.z[Error: Field {0} in message {1} is not a singular message field and cannot have sub-fields.)rMrDrrrOrFcpp_typerCPPTYPE_MESSAGEHasFieldrpgetattr ClearFieldru MergeFrom has_presencesetattr) rgr8r9rqrrsource_descriptorr#childr$repeated_sourcerepeated_destinations rrprps''!2d JE  , ,T 2E } ELL !++- ..    ..O;; ;EEKV!#4#>#>F@A A   764('+t*D - /  {401-o$[$7$$_5 ?:: :   T!2 3 ??4 +t $ . .wvt/D E!!V__T%: T764#89{401C!2rc|s|r|jj|yt|D]}|r |dz|z}n|}t||||!y)z7Adds the field paths descended from node to field_mask.NrB)r r sortedri)rgrmrar#rns rriri.sW &F# Tl7d C<$&jj4:z:6 7rN) r?google.protobuf.descriptorrobjectrrr-r rr'rurprirrrrsS 6PLPLf 3': VLVVLr%2P 7r