3 SÉLj˜Qã@sÆdZdZddlZddlZejddkr`Gdd„deƒZGdd„deƒZejjeƒejjeƒnejZGd d „d eƒZ Gd d „d e ƒZ ej je ƒGd d„de ƒZ Gdd„deƒZ Gdd„deƒZdS)aèContains container classes to represent different protocol buffer types. This file defines container classes which represent categories of protocol buffer field types which need extra maintenance. Currently these categories are: - Repeated scalar fields - These are all repeated fields which aren't composite (e.g. they are of simple types like int32, string, etc). - Repeated composite fields - Repeated fields which are composite. This includes groups and nested messages. zpetar@google.com (Petar Petrov)éNéc@sfeZdZfZddd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dZ dd„Z dd„ZdS)ÚMappingNc Cs"y||Stk r|SXdS)N)ÚKeyError)ÚselfÚkeyÚdefault©rú /usr/lib/python3.6/containers.pyÚgetGsz Mapping.getc Cs*y ||Wntk r dSXdSdS)NFT)r)rrrrr Ú __contains__Ms  zMapping.__contains__cCst|ƒS)N)Úiter)rrrr ÚiterkeysUszMapping.iterkeysccsx|D]}||VqWdS)Nr)rrrrr Ú itervaluesXs zMapping.itervaluesccs x|D]}|||fVqWdS)Nr)rrrrr Ú iteritems\s zMapping.iteritemscCst|ƒS)N)Úlist)rrrr Úkeys`sz Mapping.keyscs‡fdd„ˆDƒS)Ncsg|]}|ˆ|f‘qSrr)Ú.0r)rrr ú dsz!Mapping.items..r)rr)rr Úitemscsz Mapping.itemscs‡fdd„ˆDƒS)Ncsg|] }ˆ|‘qSrr)rr)rrr rgsz"Mapping.values..r)rr)rr ÚvaluesfszMapping.valuescCs(t|tjƒstSt|jƒƒt|jƒƒkS)N)Ú isinstanceÚ collectionsrÚNotImplementedÚdictr)rÚotherrrr Ú__eq__ls zMapping.__eq__cCs ||k S)Nr)rrrrr Ú__ne__qszMapping.__ne__)N)Ú__name__Ú __module__Ú __qualname__Ú __slots__r r r rrrrrÚ__hash__rrrrrr rDs rc@sDeZdZfZeƒZefdd„Zdd„Zdd„Zdd„Z d d d „Z d S) ÚMutableMappingc Cs<y ||}Wn tk r,||jkr(‚|SX||=|SdS)N)rÚ_MutableMapping__marker)rrrÚvaluerrr Úpopys  zMutableMapping.popc Cs@ytt|ƒƒ}Wntk r(t‚YnX||}||=||fS)N)Únextr Ú StopIterationr)rrr$rrr Úpopitem„s zMutableMapping.popitemc Cs,yx |jƒqWWntk r&YnXdS)N)r(r)rrrr Úclears zMutableMapping.clearcOsØt|ƒdkr tdjt|ƒƒƒ‚n |s,tdƒ‚|d}t|ƒdkrH|dnf}t|tƒrrx^|D]}||||<q\WnDt|dƒrœx8|jƒD]}||||<q†Wnx|D]\}}|||<q¢Wx|jƒD]\}}|||<qÀWdS)Néz8update() takes at most 2 positional arguments ({} given)z,update() takes at least 1 argument (0 given)rér)ÚlenÚ TypeErrorÚformatrrÚhasattrrr)ÚargsÚkwdsrrrr$rrr Úupdate”s"     zMutableMapping.updateNc Cs*y||Stk r$|||<YnX|S)N)r)rrrrrr Ú setdefault©s zMutableMapping.setdefault)N) rrrr Úobjectr#r%r(r)r2r3rrrr r"ts  r"c@sPeZdZdZddgZdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dS)Ú BaseContainerzBase container class.Ú_message_listenerÚ_valuescCs||_g|_dS)z¹ Args: message_listener: A MessageListener implementation. The RepeatedScalarFieldContainer will call this object's Modified() method when it is modified. N)r6r7)rÚmessage_listenerrrr Ú__init__ÀszBaseContainer.__init__cCs |j|S)z$Retrieves item by the specified key.)r7)rrrrr Ú __getitem__ÊszBaseContainer.__getitem__cCs t|jƒS)z0Returns the number of elements in the container.)r,r7)rrrr Ú__len__ÎszBaseContainer.__len__cCs ||k S)z3Checks if another instance isn't equal to this one.r)rrrrr rÒszBaseContainer.__ne__cCs tdƒ‚dS)Nzunhashable object)r-)rrrr r!×szBaseContainer.__hash__cCs t|jƒS)N)Úreprr7)rrrr Ú__repr__ÚszBaseContainer.__repr__cOs(d|kr|jdƒ|d<|jj||ŽdS)NZ sort_functionZcmp)r%r7Úsort)rr0Úkwargsrrr r>ÝszBaseContainer.sortN) rrrÚ__doc__r r9r:r;rr!r=r>rrrr r5¹s r5csˆeZdZdZdgZ‡fdd„Zdd„Zdd„Zd d „Zd d „Z d d„Z ddd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Z‡ZS) ÚRepeatedScalarFieldContainerzGSimple, type-checked, list-like container for holding repeated scalars.Ú _type_checkercstt|ƒj|ƒ||_dS)a, Args: message_listener: A MessageListener implementation. The RepeatedScalarFieldContainer will call this object's Modified() method when it is modified. type_checker: A type_checkers.ValueChecker instance to run on elements inserted into this container. N)ÚsuperrAr9rB)rr8Z type_checker)Ú __class__rr r9ís z%RepeatedScalarFieldContainer.__init__cCs*|jj|jj|ƒƒ|jjs&|jjƒdS)z6Appends an item to the list. Similar to list.append().N)r7ÚappendrBÚ CheckValuer6ÚdirtyÚModified)rr$rrr rEùsz#RepeatedScalarFieldContainer.appendcCs,|jj||jj|ƒƒ|jjs(|jjƒdS)zEInserts the item at the specified position. Similar to list.insert().N)r7ÚinsertrBrFr6rGrH)rrr$rrr rIÿsz#RepeatedScalarFieldContainer.insertc sh|dkr dSy t|ƒ}Wntk r6|s0dS‚YnX‡fdd„|Dƒ}|rZˆjj|ƒˆjjƒdS)zBExtends by appending the given iterable. Similar to list.extend().Ncsg|]}ˆjj|ƒ‘qSr)rBrF)rÚelem)rrr rsz7RepeatedScalarFieldContainer.extend..)r r-r7Úextendr6rH)rÚelem_seqZ elem_seq_iterÚ new_valuesr)rr rKs  z#RepeatedScalarFieldContainer.extendcCs|jj|jƒ|jjƒdS)z‰Appends the contents of another repeated field of the same type to this one. We do not check the types of the individual fields. N)r7rKr6rH)rrrrr Ú MergeFromsz&RepeatedScalarFieldContainer.MergeFromcCs|jj|ƒ|jjƒdS)z8Removes an item from the list. Similar to list.remove().N)r7Úremover6rH)rrJrrr rOs z#RepeatedScalarFieldContainer.remover+cCs|j|}|j|ƒ|S)zDRemoves and returns an item at a given index. Similar to list.pop().)r7Ú __delitem__)rrr$rrr r%$s  z RepeatedScalarFieldContainer.popcCsPt|tƒr0|jdk rtdƒ‚|j|j|j|ƒn|jj|ƒ|j |<|j j ƒdS)z(Sets the item on the specified position.NzExtended slices not supported) rÚsliceÚstepÚ ValueErrorÚ __setslice__ÚstartÚstoprBrFr7r6rH)rrr$rrr Ú __setitem__*s   z(RepeatedScalarFieldContainer.__setitem__cCs|j||…S)zARetrieves the subset of items from between the specified indices.)r7)rrUrVrrr Ú __getslice__4sz)RepeatedScalarFieldContainer.__getslice__cCs@g}x|D]}|j|jj|ƒƒq W||j||…<|jjƒdS)z|jj|ƒ}|jjƒ}||j|<|SXdS)N)r7rrerFrfZ DefaultValue)rrÚvalrrr r:Ís    zScalarMap.__getitem__cCs|jj|ƒ||jkS)N)rerFr7)rÚitemrrr r Ös zScalarMap.__contains__NcCs||kr||S|SdS)Nr)rrrrrr r ßsz ScalarMap.getcCs0|jj|ƒ}|jj|ƒ}||j|<|jjƒdS)N)rerFrfr7r6rH)rrr$Z checked_keyZ checked_valuerrr rWås   zScalarMap.__setitem__cCs|j|=|jjƒdS)N)r7r6rH)rrrrr rPëszScalarMap.__delitem__cCs t|jƒS)N)r,r7)rrrr r;ïszScalarMap.__len__cCs t|jƒS)N)r r7)rrrr Ú__iter__òszScalarMap.__iter__cCs t|jƒS)N)r<r7)rrrr r=õszScalarMap.__repr__cCs|jj|jƒ|jjƒdS)N)r7r2r6rH)rrrrr rNøszScalarMap.MergeFromcCs|j}|jƒ|_d|d<dS)N)r7Úcopy)rÚoriginalrrr ÚInvalidateIteratorsüs zScalarMap.InvalidateIteratorscCs|jjƒ|jjƒdS)N)r7r)r6rH)rrrr r)s zScalarMap.clearcCs|jjS)N)rgr_)rrrr Ú GetEntryClassszScalarMap.GetEntryClass)N)rrrr@r r9r:r r rWrPr;rlr=rNror)rprrrr rd²s   rdc@seZdZdZdddddgZdd„Zd d „Zd d „Zd$dd„Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zd d!„Zd"d#„Zd S)%Ú MessageMapzESimple, type-checked, dict-like container for with submessage values.rer7r6r]rgcCs"||_||_||_||_i|_dS)aÓ Args: message_listener: A MessageListener implementation. The ScalarMap will call this object's Modified() method when it is modified. key_checker: A type_checkers.ValueChecker instance to run on keys inserted into this container. value_checker: A type_checkers.ValueChecker instance to run on values inserted into this container. entry_descriptor: The MessageDescriptor of a map entry: key and value. N)r6r]rergr7)rr8r^rhrirrr r9s zMessageMap.__init__c CsZy |j|Stk rT|jj|ƒ}|jjƒ}|j|jƒ||j|<|jjƒ|SXdS)N) r7rrerFr]r_r`r6rH)rrrarrr r:'s      zMessageMap.__getitem__cCs||S)aaget_or_create() is an alias for getitem (ie. map[key]). Args: key: The key to get or create in the map. This is useful in cases where you want to be explicit that the call is mutating the map. This can avoid lint errors for statements like this that otherwise would appear to be pointless statements: msg.my_map[key] r)rrrrr Ú get_or_create3s zMessageMap.get_or_createNcCs||kr||S|SdS)Nr)rrrrrr r DszMessageMap.getcCs ||jkS)N)r7)rrkrrr r JszMessageMap.__contains__cCs tdƒ‚dS)Nz5May not set values directly, call my_map[key].foo = 5)rS)rrr$rrr rWMszMessageMap.__setitem__cCs|j|=|jjƒdS)N)r7r6rH)rrrrr rPPszMessageMap.__delitem__cCs t|jƒS)N)r,r7)rrrr r;TszMessageMap.__len__cCs t|jƒS)N)r r7)rrrr rlWszMessageMap.__iter__cCs t|jƒS)N)r<r7)rrrr r=ZszMessageMap.__repr__cCs2x,|D]$}||kr||=||j||ƒqWdS)N)ZCopyFrom)rrrrrr rN]s zMessageMap.MergeFromcCs|j}|jƒ|_d|d<dS)N)r7rm)rrnrrr rogs zMessageMap.InvalidateIteratorscCs|jjƒ|jjƒdS)N)r7r)r6rH)rrrr r)os zMessageMap.clearcCs|jjS)N)rgr_)rrrr rpsszMessageMap.GetEntryClass)N)rrrr@r r9r:rrr r rWrPr;rlr=rNror)rprrrr rq s"   rq)r@Ú __author__rÚsysÚ version_infor4rr"Úregisterr5rAÚMutableSequencer\rdrqrrrr Ú(s0< -n [Z