B s `%c@sdZdZddlZyddlmZWnek r<ddlZYnXejddkrGddde Z Gddde Z ej e ej e nej Z Gd d d e Z ej e Gd d d e ZGd dde ZGddde ZGddde ZGddde ZGddde ZGddde ZdS)aContains 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)Nc@sfeZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ dZ ddZ ddZdS)MappingNcCs"y||Stk r|SXdS)N)KeyError)selfkeydefaultrrG/tmp/pip-unpacked-wheel-u0__x60w/google/protobuf/internal/containers.pygetLsz Mapping.getcCs*y ||Wntk r dSXdSdS)NFT)r)rrrrr __contains__Rs  zMapping.__contains__cCst|S)N)iter)rrrr iterkeysZszMapping.iterkeysccsx|D]}||VqWdS)Nr)rrrrr itervalues]s zMapping.itervaluesccs x|D]}|||fVqWdS)Nr)rrrrr iteritemsas zMapping.iteritemscCst|S)N)list)rrrr keysesz Mapping.keyscsfddDS)Ncsg|]}||fqSrr).0r)rrr isz!Mapping.items..r)rr)rr itemshsz Mapping.itemscsfddDS)Ncsg|] }|qSrr)rr)rrr rlsz"Mapping.values..r)rr)rr valueskszMapping.valuescCs(t|tjstSt|t|kS)N) isinstancecollections_abcrNotImplementeddictr)rotherrrr __eq__qs zMapping.__eq__cCs ||k S)Nr)rrrrr __ne__vszMapping.__ne__)N)__name__ __module__ __qualname__ __slots__r r r rrrrr__hash__rrrrrr rIs rc@sDeZdZdZeZefddZddZddZdd Z d d d Z d S)MutableMappingrcCs<y ||}Wn tk r,||jkr(|SX||=|SdS)N)r_MutableMapping__marker)rrrvaluerrr pop~s  zMutableMapping.popcCs@ytt|}Wntk r(tYnX||}||=||fS)N)nextr StopIterationr)rrr$rrr popitems zMutableMapping.popitemcCs,yx |qWWntk r&YnXdS)N)r(r)rrrr clears zMutableMapping.clearcOst|dkr tdt|n |s,td|d}t|dkrH|dnd}t|trrx^|D]}||||<q\WnDt|drx8|D]}||||<qWnx|D]\}}|||<qWx|D]\}}|||<qWdS)Nz8update() takes at most 2 positional arguments ({} given)z,update() takes at least 1 argument (0 given)rrr)len TypeErrorformatrrhasattrrr)argskwdsrrrr$rrr updates"     zMutableMapping.updateNcCs*y||Stk r$|||<YnX|S)N)r)rrrrrr setdefaults zMutableMapping.setdefault)N) rrrr objectr#r%r(r)r2r3rrrr r"ys  r"c@sPeZdZdZddgZddZddZdd Zd d Zd d Z ddZ ddZ 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)rmessage_listenerrrr __init__szBaseContainer.__init__cCs |j|S)z$Retrieves item by the specified key.)r7)rrrrr __getitem__szBaseContainer.__getitem__cCs t|jS)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 rszBaseContainer.__ne__cCs tddS)Nzunhashable object)r-)rrrr r!szBaseContainer.__hash__cCs t|jS)N)reprr7)rrrr __repr__szBaseContainer.__repr__cOs(d|kr|d|d<|jj||dS)NZ sort_functioncmp)r%r7sort)rr0kwargsrrr r?szBaseContainer.sortN) rrr__doc__r r9r:r;rr!r=r?rrrr r5s r5cseZdZdZdgZfddZddZddZd d Zd d Z d dZ dddZ ddZ ddZ ddZddZddZddZZS)RepeatedScalarFieldContainerzGSimple, type-checked, list-like container for holding repeated scalars. _type_checkercstt||||_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)superrBr9rC)rr8Z type_checker) __class__rr r9s z%RepeatedScalarFieldContainer.__init__cCs*|j|j||jjs&|jdS)z6Appends an item to the list. Similar to list.append().N)r7appendrC CheckValuer6dirtyModified)rr$rrr rFsz#RepeatedScalarFieldContainer.appendcCs,|j||j||jjs(|jdS)zEInserts the item at the specified position. Similar to list.insert().N)r7insertrCrGr6rHrI)rrr$rrr rJsz#RepeatedScalarFieldContainer.insertcsh|dkr dSy t|}Wntk r6|s0dSYnXfdd|D}|rZj|jdS)zBExtends by appending the given iterable. Similar to list.extend().Ncsg|]}j|qSr)rCrG)relem)rrr rsz7RepeatedScalarFieldContainer.extend..)r r-r7extendr6rI)relem_seqZ elem_seq_iter new_valuesr)rr rL s  z#RepeatedScalarFieldContainer.extendcCs|j|j|jdS)zAppends the contents of another repeated field of the same type to this one. We do not check the types of the individual fields. N)r7rLr6rI)rrrrr MergeFromsz&RepeatedScalarFieldContainer.MergeFromcCs|j||jdS)z8Removes an item from the list. Similar to list.remove().N)r7remover6rI)rrKrrr rP&s z#RepeatedScalarFieldContainer.removecCs|j|}|||S)zDRemoves and returns an item at a given index. Similar to list.pop().)r7 __delitem__)rrr$rrr r%+s  z RepeatedScalarFieldContainer.popcCsPt|tr0|jdk rtd||j|j|n|j||j |<|j dS)z(Sets the item on the specified position.NzExtended slices not supported) rslicestep ValueError __setslice__startstoprCrGr7r6rI)rrr$rrr __setitem__1s   z(RepeatedScalarFieldContainer.__setitem__cCs|j||S)zARetrieves the subset of items from between the specified indices.)r7)rrWrXrrr __getslice__;sz)RepeatedScalarFieldContainer.__getslice__cCs@g}x|D]}||j|q W||j||<|jdS)z|jdS)z+Appends one element by copying the message.N) r^r`rar6CopyFromr7rFrHrI)rr$rbrrr rFs     z&RepeatedCompositeFieldContainer.appendcCsD|j}||j|||j|||jjs@|jdS)z6Inserts the item at the specified position by copying.N) r^r`rar6rdr7rJrHrI)rrr$rbrrr rJs    z&RepeatedCompositeFieldContainer.insertcCsR|jj}|j}|j}x0|D](}|}||||||qW|dS)z|Extends by appending the given sequence of elements of the same type as this one, copying each individual message. N)r^r`r6r7rarOrFrI)rrMZ message_classZlistenerrmessagerbrrr rLs   z&RepeatedCompositeFieldContainer.extendcCs||jdS)zvAppends the contents of another repeated field of the same type to this one, copying each individual message. N)rLr7)rrrrr rOsz)RepeatedCompositeFieldContainer.MergeFromcCs|j||jdS)z8Removes an item from the list. Similar to list.remove().N)r7rPr6rI)rrKrrr rPs z&RepeatedCompositeFieldContainer.removerQcCs|j|}|||S)zDRemoves and returns an item at a given index. Similar to list.pop().)r7rR)rrr$rrr r%s  z#RepeatedCompositeFieldContainer.popcCs|j||S)zARetrieves the subset of items from between the specified indices.)r7)rrWrXrrr rZsz,RepeatedCompositeFieldContainer.__getslice__cCs|j|=|jdS)z+Deletes the item at the specified position.N)r7r6rI)rrrrr rRsz+RepeatedCompositeFieldContainer.__delitem__cCs|j||=|jdS)z?Deletes the subset of items from between the specified indices.N)r7r6rI)rrWrXrrr r[s z,RepeatedCompositeFieldContainer.__delslice__cCs,||kr dSt||js td|j|jkS)z/Compares the current instance with another one.TzSCan only compare repeated composite fields against other repeated composite fields.)rrEr-r7)rrrrr rs  z&RepeatedCompositeFieldContainer.__eq__)rQ)rrrrAr r9rcrFrJrLrOrPr%rZrRr[rr\rr)rEr r]\s     r]c@seZdZdZdddddgZddZd d Zd d Zd"ddZddZ ddZ ddZ ddZ ddZ ddZddZddZd d!Zd S)# ScalarMapzGSimple, type-checked, dict-like container for holding repeated scalars. _key_checker_value_checkerr7r6_entry_descriptorcCs"||_||_||_||_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)r6rgrhrir7)rr8 key_checkerZ value_checkerentry_descriptorrrr r9s zScalarMap.__init__cCsDy |j|Stk r>|j|}|j}||j|<|SXdS)N)r7rrgrGrhZ DefaultValue)rrvalrrr r:s    zScalarMap.__getitem__cCs|j|||jkS)N)rgrGr7)ritemrrr r s zScalarMap.__contains__NcCs||kr||S|SdS)Nr)rrrrrr r sz ScalarMap.getcCs0|j|}|j|}||j|<|jdS)N)rgrGrhr7r6rI)rrr$Z checked_keyZ checked_valuerrr rYs   zScalarMap.__setitem__cCs|j|=|jdS)N)r7r6rI)rrrrr rRszScalarMap.__delitem__cCs t|jS)N)r,r7)rrrr r;szScalarMap.__len__cCs t|jS)N)r r7)rrrr __iter__ szScalarMap.__iter__cCs t|jS)N)r<r7)rrrr r= szScalarMap.__repr__cCs|j|j|jdS)N)r7r2r6rI)rrrrr rOszScalarMap.MergeFromcCs|j}||_d|d<dS)N)r7copy)roriginalrrr InvalidateIteratorss zScalarMap.InvalidateIteratorscCs|j|jdS)N)r7r)r6rI)rrrr r)s zScalarMap.clearcCs|jjS)N)rir`)rrrr GetEntryClass szScalarMap.GetEntryClass)N)rrrrAr r9r:r r rYrRr;rnr=rOrqr)rrrrrr rfs   rfc@seZdZdZdddddgZddZd d Zd d Zd$ddZddZ ddZ ddZ ddZ ddZ ddZddZddZd d!Zd"d#Zd S)% MessageMapzESimple, type-checked, dict-like container for with submessage values.rgr7r6r^ricCs"||_||_||_||_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^rgrir7)rr8r_rjrkrrr r9,s zMessageMap.__init__cCsZ|j|}y |j|Stk rT|j}||j||j|<|j|SXdS)N) rgrGr7rr^r`rar6rI)rrrbrrr 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_createKs zMessageMap.get_or_createNcCs||kr||S|SdS)Nr)rrrrrr r \szMessageMap.getcCs|j|}||jkS)N)rgrGr7)rrmrrr r bs zMessageMap.__contains__cCs tddS)Nz5May not set values directly, call my_map[key].foo = 5)rU)rrr$rrr rYfszMessageMap.__setitem__cCs"|j|}|j|=|jdS)N)rgrGr7r6rI)rrrrr rRis zMessageMap.__delitem__cCs t|jS)N)r,r7)rrrr r;nszMessageMap.__len__cCs t|jS)N)r r7)rrrr rnqszMessageMap.__iter__cCs t|jS)N)r<r7)rrrr r=tszMessageMap.__repr__cCs4x.|jD]$}||kr||=||||qWdS)N)r7rd)rrrrrr rOws zMessageMap.MergeFromcCs|j}||_d|d<dS)N)r7ro)rrprrr rqs zMessageMap.InvalidateIteratorscCs|j|jdS)N)r7r)r6rI)rrrr r)s zMessageMap.clearcCs|jjS)N)rir`)rrrr rrszMessageMap.GetEntryClass)N)rrrrAr r9r:rtr r rYrRr;rnr=rOrqr)rrrrrr rs$s"   rsc@s2eZdZdZdddgZddZddZd d Zd S) _UnknownFieldzA parsed unknown field. _field_number _wire_type_datacCs||_||_||_dS)N)rvrwrx)r field_number wire_typedatarrr r9sz_UnknownField.__init__cCs |j|jkS)N)rv)rrrrr __lt__sz_UnknownField.__lt__cCs0||kr dS|j|jko.|j|jko.|j|jkS)NT)rvrwrx)rrrrr rs   z_UnknownField.__eq__N)rrrrAr r9r|rrrrr rus  ruc@s@eZdZddZddZeddZeddZed d Zd S) UnknownFieldRefcCs||_||_dS)N)_parent_index)rparentindexrrr r9szUnknownFieldRef.__init__cCs*|jstd|jt|jkr&tddS)NzAUnknownField does not exist. The parent message might be cleared.)r~rUrr,)rrrr _check_validszUnknownFieldRef._check_validcCs||j|jjS)N)rr~ _internal_getrrv)rrrr ryszUnknownFieldRef.field_numbercCs||j|jjS)N)rr~rrrw)rrrr rzszUnknownFieldRef.wire_typecCs||j|jjS)N)rr~rrrx)rrrr r{szUnknownFieldRef.dataN) rrrr9rpropertyryrzr{rrrr r}s   r}c@s^eZdZdZdgZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ dS)UnknownFieldSetzUnknownField containerr7cCs g|_dS)N)r7)rrrr r9szUnknownFieldSet.__init__cCsP|jdkrtdt|j}|dkr,||7}|dks<||krFtdjt||S)NzBUnknownFields does not exist. The parent message might be cleared.rzindex %d out of range)r7rUr, IndexErrorrr})rrsizerrr r:s   zUnknownFieldSet.__getitem__cCs |j|S)N)r7)rrrrr rszUnknownFieldSet._internal_getcCs|jdkrtdt|jS)NzBUnknownFields does not exist. The parent message might be cleared.)r7rUr,)rrrr r;s zUnknownFieldSet.__len__cCst|||}|j||S)N)rur7rF)rryrzr{Z unknown_fieldrrr _adds  zUnknownFieldSet._addccs&x tt|D]}t||VqWdS)N)ranger,r})rirrr rnszUnknownFieldSet.__iter__cCs|dkr dS|j|jdS)N)r7rL)rrrrr _extendszUnknownFieldSet._extendcCs>||kr dSt|j}|dkr$| S|t|j}||kS)NT)rr7r?sorted)rrrZ other_valuesrrr rs  zUnknownFieldSet.__eq__cCs0x$|jD]}t|jtr|jqWd|_dS)N)r7rrxr_clear)rr$rrr r s  zUnknownFieldSet._clearN)rrrrAr r9r:rr;rrnrrrrrrr rs  r)rA __author__syscollections.abcabcr ImportError collections version_infor4rr"registerr5MutableSequencerBr]rfrsrur}rrrrr )s*0< - nnZn"