Skip to content

containers

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.

BaseContainer

Bases: Sequence[_T]

Base container class.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
class BaseContainer(Sequence[_T]):
  """Base container class."""

  # Minimizes memory usage and disallows assignment to other attributes.
  __slots__ = ['_message_listener', '_values']

  def __init__(self, message_listener: Any) -> None:
    """
    Args:
      message_listener: A MessageListener implementation.
        The RepeatedScalarFieldContainer will call this object's
        Modified() method when it is modified.
    """
    self._message_listener = message_listener
    self._values = []

  @overload
  def __getitem__(self, key: int) -> _T:
    ...

  @overload
  def __getitem__(self, key: slice) -> List[_T]:
    ...

  def __getitem__(self, key):
    """Retrieves item by the specified key."""
    return self._values[key]

  def __len__(self) -> int:
    """Returns the number of elements in the container."""
    return len(self._values)

  def __ne__(self, other: Any) -> bool:
    """Checks if another instance isn't equal to this one."""
    # The concrete classes should define __eq__.
    return not self == other

  __hash__ = None

  def __repr__(self) -> str:
    return repr(self._values)

  def sort(self, *args, **kwargs) -> None:
    # Continue to support the old sort_function keyword argument.
    # This is expected to be a rare occurrence, so use LBYL to avoid
    # the overhead of actually catching KeyError.
    if 'sort_function' in kwargs:
      kwargs['cmp'] = kwargs.pop('sort_function')
    self._values.sort(*args, **kwargs)

  def reverse(self) -> None:
    self._values.reverse()

__getitem__(key)

__getitem__(key: int) -> _T
__getitem__(key: slice) -> List[_T]

Retrieves item by the specified key.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
91
92
93
def __getitem__(self, key):
  """Retrieves item by the specified key."""
  return self._values[key]

__init__(message_listener)

Parameters:

Name Type Description Default
message_listener Any

A MessageListener implementation. The RepeatedScalarFieldContainer will call this object's Modified() method when it is modified.

required
Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
73
74
75
76
77
78
79
80
81
def __init__(self, message_listener: Any) -> None:
  """
  Args:
    message_listener: A MessageListener implementation.
      The RepeatedScalarFieldContainer will call this object's
      Modified() method when it is modified.
  """
  self._message_listener = message_listener
  self._values = []

__len__()

Returns the number of elements in the container.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
95
96
97
def __len__(self) -> int:
  """Returns the number of elements in the container."""
  return len(self._values)

__ne__(other)

Checks if another instance isn't equal to this one.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
 99
100
101
102
def __ne__(self, other: Any) -> bool:
  """Checks if another instance isn't equal to this one."""
  # The concrete classes should define __eq__.
  return not self == other

MessageMap

Bases: MutableMapping[_K, _V]

Simple, type-checked, dict-like container for with submessage values.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
class MessageMap(MutableMapping[_K, _V]):
  """Simple, type-checked, dict-like container for with submessage values."""

  # Disallows assignment to other attributes.
  __slots__ = ['_key_checker', '_values', '_message_listener',
               '_message_descriptor', '_entry_descriptor']

  def __init__(
      self,
      message_listener: Any,
      message_descriptor: Any,
      key_checker: Any,
      entry_descriptor: Any,
  ) -> None:
    """
    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.
    """
    self._message_listener = message_listener
    self._message_descriptor = message_descriptor
    self._key_checker = key_checker
    self._entry_descriptor = entry_descriptor
    self._values = {}

  def __getitem__(self, key: _K) -> _V:
    key = self._key_checker.CheckValue(key)
    try:
      return self._values[key]
    except KeyError:
      new_element = self._message_descriptor._concrete_class()
      new_element._SetListener(self._message_listener)
      self._values[key] = new_element
      self._message_listener.Modified()
      return new_element

  def get_or_create(self, key: _K) -> _V:
    """get_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]
    """
    return self[key]

  @overload
  def get(self, key: _K) -> Optional[_V]:
    ...

  @overload
  def get(self, key: _K, default: _T) -> Union[_V, _T]:
    ...

  # We need to override this explicitly, because our defaultdict-like behavior
  # will make the default implementation (from our base class) always insert
  # the key.
  def get(self, key, default=None):
    if key in self:
      return self[key]
    else:
      return default

  def __contains__(self, item: _K) -> bool:
    item = self._key_checker.CheckValue(item)
    return item in self._values

  def __setitem__(self, key: _K, value: _V) -> NoReturn:
    raise ValueError('May not set values directly, call my_map[key].foo = 5')

  def __delitem__(self, key: _K) -> None:
    key = self._key_checker.CheckValue(key)
    del self._values[key]
    self._message_listener.Modified()

  def __len__(self) -> int:
    return len(self._values)

  def __iter__(self) -> Iterator[_K]:
    return iter(self._values)

  def __repr__(self) -> str:
    return repr(self._values)

  def MergeFrom(self, other: 'MessageMap[_K, _V]') -> None:
    # pylint: disable=protected-access
    for key in other._values:
      # According to documentation: "When parsing from the wire or when merging,
      # if there are duplicate map keys the last key seen is used".
      if key in self:
        del self[key]
      self[key].CopyFrom(other[key])
    # self._message_listener.Modified() not required here, because
    # mutations to submessages already propagate.

  def InvalidateIterators(self) -> None:
    # It appears that the only way to reliably invalidate iterators to
    # self._values is to ensure that its size changes.
    original = self._values
    self._values = original.copy()
    original[None] = None

  # This is defined in the abstract base, but we can do it much more cheaply.
  def clear(self) -> None:
    self._values.clear()
    self._message_listener.Modified()

  def GetEntryClass(self) -> Any:
    return self._entry_descriptor._concrete_class

__init__(message_listener, message_descriptor, key_checker, entry_descriptor)

Parameters:

Name Type Description Default
message_listener Any

A MessageListener implementation. The ScalarMap will call this object's Modified() method when it is modified.

required
key_checker Any

A type_checkers.ValueChecker instance to run on keys inserted into this container.

required
value_checker

A type_checkers.ValueChecker instance to run on values inserted into this container.

required
entry_descriptor Any

The MessageDescriptor of a map entry: key and value.

required
Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
def __init__(
    self,
    message_listener: Any,
    message_descriptor: Any,
    key_checker: Any,
    entry_descriptor: Any,
) -> None:
  """
  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.
  """
  self._message_listener = message_listener
  self._message_descriptor = message_descriptor
  self._key_checker = key_checker
  self._entry_descriptor = entry_descriptor
  self._values = {}

get_or_create(key)

get_or_create() is an alias for getitem (ie. map[key]).

Parameters:

Name Type Description Default
key _K

The key to get or create in the map.

required

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]

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
510
511
512
513
514
515
516
517
518
519
520
521
522
def get_or_create(self, key: _K) -> _V:
  """get_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]
  """
  return self[key]

RepeatedCompositeFieldContainer

Bases: BaseContainer[_T], MutableSequence[_T]

Simple, list-like container for holding repeated composite fields.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
class RepeatedCompositeFieldContainer(BaseContainer[_T], MutableSequence[_T]):
  """Simple, list-like container for holding repeated composite fields."""

  # Disallows assignment to other attributes.
  __slots__ = ['_message_descriptor']

  def __init__(self, message_listener: Any, message_descriptor: Any) -> None:
    """
    Note that we pass in a descriptor instead of the generated directly,
    since at the time we construct a _RepeatedCompositeFieldContainer we
    haven't yet necessarily initialized the type that will be contained in the
    container.

    Args:
      message_listener: A MessageListener implementation.
        The RepeatedCompositeFieldContainer will call this object's
        Modified() method when it is modified.
      message_descriptor: A Descriptor instance describing the protocol type
        that should be present in this container.  We'll use the
        _concrete_class field of this descriptor when the client calls add().
    """
    super().__init__(message_listener)
    self._message_descriptor = message_descriptor

  def add(self, **kwargs: Any) -> _T:
    """Adds a new element at the end of the list and returns it. Keyword
    arguments may be used to initialize the element.
    """
    new_element = self._message_descriptor._concrete_class(**kwargs)
    new_element._SetListener(self._message_listener)
    self._values.append(new_element)
    if not self._message_listener.dirty:
      self._message_listener.Modified()
    return new_element

  def append(self, value: _T) -> None:
    """Appends one element by copying the message."""
    new_element = self._message_descriptor._concrete_class()
    new_element._SetListener(self._message_listener)
    new_element.CopyFrom(value)
    self._values.append(new_element)
    if not self._message_listener.dirty:
      self._message_listener.Modified()

  def insert(self, key: int, value: _T) -> None:
    """Inserts the item at the specified position by copying."""
    new_element = self._message_descriptor._concrete_class()
    new_element._SetListener(self._message_listener)
    new_element.CopyFrom(value)
    self._values.insert(key, new_element)
    if not self._message_listener.dirty:
      self._message_listener.Modified()

  def extend(self, elem_seq: Iterable[_T]) -> None:
    """Extends by appending the given sequence of elements of the same type

    as this one, copying each individual message.
    """
    message_class = self._message_descriptor._concrete_class
    listener = self._message_listener
    values = self._values
    for message in elem_seq:
      new_element = message_class()
      new_element._SetListener(listener)
      new_element.MergeFrom(message)
      values.append(new_element)
    listener.Modified()

  def MergeFrom(
      self,
      other: Union['RepeatedCompositeFieldContainer[_T]', Iterable[_T]],
  ) -> None:
    """Appends the contents of another repeated field of the same type to this
    one, copying each individual message.
    """
    self.extend(other)

  def remove(self, elem: _T) -> None:
    """Removes an item from the list. Similar to list.remove()."""
    self._values.remove(elem)
    self._message_listener.Modified()

  def pop(self, key: Optional[int] = -1) -> _T:
    """Removes and returns an item at a given index. Similar to list.pop()."""
    value = self._values[key]
    self.__delitem__(key)
    return value

  @overload
  def __setitem__(self, key: int, value: _T) -> None:
    ...

  @overload
  def __setitem__(self, key: slice, value: Iterable[_T]) -> None:
    ...

  def __setitem__(self, key, value):
    # This method is implemented to make RepeatedCompositeFieldContainer
    # structurally compatible with typing.MutableSequence. It is
    # otherwise unsupported and will always raise an error.
    raise TypeError(
        f'{self.__class__.__name__} object does not support item assignment')

  def __delitem__(self, key: Union[int, slice]) -> None:
    """Deletes the item at the specified position."""
    del self._values[key]
    self._message_listener.Modified()

  def __eq__(self, other: Any) -> bool:
    """Compares the current instance with another one."""
    if self is other:
      return True
    if not isinstance(other, self.__class__):
      raise TypeError('Can only compare repeated composite fields against '
                      'other repeated composite fields.')
    return self._values == other._values

MergeFrom(other)

Appends the contents of another repeated field of the same type to this one, copying each individual message.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
316
317
318
319
320
321
322
323
def MergeFrom(
    self,
    other: Union['RepeatedCompositeFieldContainer[_T]', Iterable[_T]],
) -> None:
  """Appends the contents of another repeated field of the same type to this
  one, copying each individual message.
  """
  self.extend(other)

__delitem__(key)

Deletes the item at the specified position.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
351
352
353
354
def __delitem__(self, key: Union[int, slice]) -> None:
  """Deletes the item at the specified position."""
  del self._values[key]
  self._message_listener.Modified()

__eq__(other)

Compares the current instance with another one.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
356
357
358
359
360
361
362
363
def __eq__(self, other: Any) -> bool:
  """Compares the current instance with another one."""
  if self is other:
    return True
  if not isinstance(other, self.__class__):
    raise TypeError('Can only compare repeated composite fields against '
                    'other repeated composite fields.')
  return self._values == other._values

__init__(message_listener, message_descriptor)

Note that we pass in a descriptor instead of the generated directly, since at the time we construct a _RepeatedCompositeFieldContainer we haven't yet necessarily initialized the type that will be contained in the container.

Parameters:

Name Type Description Default
message_listener Any

A MessageListener implementation. The RepeatedCompositeFieldContainer will call this object's Modified() method when it is modified.

required
message_descriptor Any

A Descriptor instance describing the protocol type that should be present in this container. We'll use the _concrete_class field of this descriptor when the client calls add().

required
Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
def __init__(self, message_listener: Any, message_descriptor: Any) -> None:
  """
  Note that we pass in a descriptor instead of the generated directly,
  since at the time we construct a _RepeatedCompositeFieldContainer we
  haven't yet necessarily initialized the type that will be contained in the
  container.

  Args:
    message_listener: A MessageListener implementation.
      The RepeatedCompositeFieldContainer will call this object's
      Modified() method when it is modified.
    message_descriptor: A Descriptor instance describing the protocol type
      that should be present in this container.  We'll use the
      _concrete_class field of this descriptor when the client calls add().
  """
  super().__init__(message_listener)
  self._message_descriptor = message_descriptor

add(**kwargs)

Adds a new element at the end of the list and returns it. Keyword arguments may be used to initialize the element.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
272
273
274
275
276
277
278
279
280
281
def add(self, **kwargs: Any) -> _T:
  """Adds a new element at the end of the list and returns it. Keyword
  arguments may be used to initialize the element.
  """
  new_element = self._message_descriptor._concrete_class(**kwargs)
  new_element._SetListener(self._message_listener)
  self._values.append(new_element)
  if not self._message_listener.dirty:
    self._message_listener.Modified()
  return new_element

append(value)

Appends one element by copying the message.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
283
284
285
286
287
288
289
290
def append(self, value: _T) -> None:
  """Appends one element by copying the message."""
  new_element = self._message_descriptor._concrete_class()
  new_element._SetListener(self._message_listener)
  new_element.CopyFrom(value)
  self._values.append(new_element)
  if not self._message_listener.dirty:
    self._message_listener.Modified()

extend(elem_seq)

Extends by appending the given sequence of elements of the same type

as this one, copying each individual message.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
301
302
303
304
305
306
307
308
309
310
311
312
313
314
def extend(self, elem_seq: Iterable[_T]) -> None:
  """Extends by appending the given sequence of elements of the same type

  as this one, copying each individual message.
  """
  message_class = self._message_descriptor._concrete_class
  listener = self._message_listener
  values = self._values
  for message in elem_seq:
    new_element = message_class()
    new_element._SetListener(listener)
    new_element.MergeFrom(message)
    values.append(new_element)
  listener.Modified()

insert(key, value)

Inserts the item at the specified position by copying.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
292
293
294
295
296
297
298
299
def insert(self, key: int, value: _T) -> None:
  """Inserts the item at the specified position by copying."""
  new_element = self._message_descriptor._concrete_class()
  new_element._SetListener(self._message_listener)
  new_element.CopyFrom(value)
  self._values.insert(key, new_element)
  if not self._message_listener.dirty:
    self._message_listener.Modified()

pop(key=-1)

Removes and returns an item at a given index. Similar to list.pop().

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
330
331
332
333
334
def pop(self, key: Optional[int] = -1) -> _T:
  """Removes and returns an item at a given index. Similar to list.pop()."""
  value = self._values[key]
  self.__delitem__(key)
  return value

remove(elem)

Removes an item from the list. Similar to list.remove().

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
325
326
327
328
def remove(self, elem: _T) -> None:
  """Removes an item from the list. Similar to list.remove()."""
  self._values.remove(elem)
  self._message_listener.Modified()

RepeatedScalarFieldContainer

Bases: BaseContainer[_T], MutableSequence[_T]

Simple, type-checked, list-like container for holding repeated scalars.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
class RepeatedScalarFieldContainer(BaseContainer[_T], MutableSequence[_T]):
  """Simple, type-checked, list-like container for holding repeated scalars."""

  # Disallows assignment to other attributes.
  __slots__ = ['_type_checker']

  def __init__(
      self,
      message_listener: Any,
      type_checker: Any,
  ) -> None:
    """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.
    """
    super().__init__(message_listener)
    self._type_checker = type_checker

  def append(self, value: _T) -> None:
    """Appends an item to the list. Similar to list.append()."""
    self._values.append(self._type_checker.CheckValue(value))
    if not self._message_listener.dirty:
      self._message_listener.Modified()

  def insert(self, key: int, value: _T) -> None:
    """Inserts the item at the specified position. Similar to list.insert()."""
    self._values.insert(key, self._type_checker.CheckValue(value))
    if not self._message_listener.dirty:
      self._message_listener.Modified()

  def extend(self, elem_seq: Iterable[_T]) -> None:
    """Extends by appending the given iterable. Similar to list.extend()."""
    if elem_seq is None:
      return
    try:
      elem_seq_iter = iter(elem_seq)
    except TypeError:
      if not elem_seq:
        # silently ignore falsy inputs :-/.
        # TODO(ptucker): Deprecate this behavior. b/18413862
        return
      raise

    new_values = [self._type_checker.CheckValue(elem) for elem in elem_seq_iter]
    if new_values:
      self._values.extend(new_values)
    self._message_listener.Modified()

  def MergeFrom(
      self,
      other: Union['RepeatedScalarFieldContainer[_T]', Iterable[_T]],
  ) -> None:
    """Appends the contents of another repeated field of the same type to this
    one. We do not check the types of the individual fields.
    """
    self._values.extend(other)
    self._message_listener.Modified()

  def remove(self, elem: _T):
    """Removes an item from the list. Similar to list.remove()."""
    self._values.remove(elem)
    self._message_listener.Modified()

  def pop(self, key: Optional[int] = -1) -> _T:
    """Removes and returns an item at a given index. Similar to list.pop()."""
    value = self._values[key]
    self.__delitem__(key)
    return value

  @overload
  def __setitem__(self, key: int, value: _T) -> None:
    ...

  @overload
  def __setitem__(self, key: slice, value: Iterable[_T]) -> None:
    ...

  def __setitem__(self, key, value) -> None:
    """Sets the item on the specified position."""
    if isinstance(key, slice):
      if key.step is not None:
        raise ValueError('Extended slices not supported')
      self._values[key] = map(self._type_checker.CheckValue, value)
      self._message_listener.Modified()
    else:
      self._values[key] = self._type_checker.CheckValue(value)
      self._message_listener.Modified()

  def __delitem__(self, key: Union[int, slice]) -> None:
    """Deletes the item at the specified position."""
    del self._values[key]
    self._message_listener.Modified()

  def __eq__(self, other: Any) -> bool:
    """Compares the current instance with another one."""
    if self is other:
      return True
    # Special case for the same type which should be common and fast.
    if isinstance(other, self.__class__):
      return other._values == self._values
    # We are presumably comparing against some other sequence type.
    return other == self._values

  def __deepcopy__(
      self,
      unused_memo: Any = None,
  ) -> 'RepeatedScalarFieldContainer[_T]':
    clone = RepeatedScalarFieldContainer(
        copy.deepcopy(self._message_listener), self._type_checker)
    clone.MergeFrom(self)
    return clone

  def __reduce__(self, **kwargs) -> NoReturn:
    raise pickle.PickleError(
        "Can't pickle repeated scalar fields, convert to list first")

MergeFrom(other)

Appends the contents of another repeated field of the same type to this one. We do not check the types of the individual fields.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
178
179
180
181
182
183
184
185
186
def MergeFrom(
    self,
    other: Union['RepeatedScalarFieldContainer[_T]', Iterable[_T]],
) -> None:
  """Appends the contents of another repeated field of the same type to this
  one. We do not check the types of the individual fields.
  """
  self._values.extend(other)
  self._message_listener.Modified()

__delitem__(key)

Deletes the item at the specified position.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
218
219
220
221
def __delitem__(self, key: Union[int, slice]) -> None:
  """Deletes the item at the specified position."""
  del self._values[key]
  self._message_listener.Modified()

__eq__(other)

Compares the current instance with another one.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
223
224
225
226
227
228
229
230
231
def __eq__(self, other: Any) -> bool:
  """Compares the current instance with another one."""
  if self is other:
    return True
  # Special case for the same type which should be common and fast.
  if isinstance(other, self.__class__):
    return other._values == self._values
  # We are presumably comparing against some other sequence type.
  return other == self._values

__init__(message_listener, type_checker)

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.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
def __init__(
    self,
    message_listener: Any,
    type_checker: Any,
) -> None:
  """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.
  """
  super().__init__(message_listener)
  self._type_checker = type_checker

__setitem__(key, value)

__setitem__(key: int, value: _T) -> None
__setitem__(key: slice, value: Iterable[_T]) -> None

Sets the item on the specified position.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
207
208
209
210
211
212
213
214
215
216
def __setitem__(self, key, value) -> None:
  """Sets the item on the specified position."""
  if isinstance(key, slice):
    if key.step is not None:
      raise ValueError('Extended slices not supported')
    self._values[key] = map(self._type_checker.CheckValue, value)
    self._message_listener.Modified()
  else:
    self._values[key] = self._type_checker.CheckValue(value)
    self._message_listener.Modified()

append(value)

Appends an item to the list. Similar to list.append().

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
148
149
150
151
152
def append(self, value: _T) -> None:
  """Appends an item to the list. Similar to list.append()."""
  self._values.append(self._type_checker.CheckValue(value))
  if not self._message_listener.dirty:
    self._message_listener.Modified()

extend(elem_seq)

Extends by appending the given iterable. Similar to list.extend().

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
def extend(self, elem_seq: Iterable[_T]) -> None:
  """Extends by appending the given iterable. Similar to list.extend()."""
  if elem_seq is None:
    return
  try:
    elem_seq_iter = iter(elem_seq)
  except TypeError:
    if not elem_seq:
      # silently ignore falsy inputs :-/.
      # TODO(ptucker): Deprecate this behavior. b/18413862
      return
    raise

  new_values = [self._type_checker.CheckValue(elem) for elem in elem_seq_iter]
  if new_values:
    self._values.extend(new_values)
  self._message_listener.Modified()

insert(key, value)

Inserts the item at the specified position. Similar to list.insert().

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
154
155
156
157
158
def insert(self, key: int, value: _T) -> None:
  """Inserts the item at the specified position. Similar to list.insert()."""
  self._values.insert(key, self._type_checker.CheckValue(value))
  if not self._message_listener.dirty:
    self._message_listener.Modified()

pop(key=-1)

Removes and returns an item at a given index. Similar to list.pop().

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
193
194
195
196
197
def pop(self, key: Optional[int] = -1) -> _T:
  """Removes and returns an item at a given index. Similar to list.pop()."""
  value = self._values[key]
  self.__delitem__(key)
  return value

remove(elem)

Removes an item from the list. Similar to list.remove().

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
188
189
190
191
def remove(self, elem: _T):
  """Removes an item from the list. Similar to list.remove()."""
  self._values.remove(elem)
  self._message_listener.Modified()

ScalarMap

Bases: MutableMapping[_K, _V]

Simple, type-checked, dict-like container for holding repeated scalars.

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
class ScalarMap(MutableMapping[_K, _V]):
  """Simple, type-checked, dict-like container for holding repeated scalars."""

  # Disallows assignment to other attributes.
  __slots__ = ['_key_checker', '_value_checker', '_values', '_message_listener',
               '_entry_descriptor']

  def __init__(
      self,
      message_listener: Any,
      key_checker: Any,
      value_checker: Any,
      entry_descriptor: Any,
  ) -> None:
    """
    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.
    """
    self._message_listener = message_listener
    self._key_checker = key_checker
    self._value_checker = value_checker
    self._entry_descriptor = entry_descriptor
    self._values = {}

  def __getitem__(self, key: _K) -> _V:
    try:
      return self._values[key]
    except KeyError:
      key = self._key_checker.CheckValue(key)
      val = self._value_checker.DefaultValue()
      self._values[key] = val
      return val

  def __contains__(self, item: _K) -> bool:
    # We check the key's type to match the strong-typing flavor of the API.
    # Also this makes it easier to match the behavior of the C++ implementation.
    self._key_checker.CheckValue(item)
    return item in self._values

  @overload
  def get(self, key: _K) -> Optional[_V]:
    ...

  @overload
  def get(self, key: _K, default: _T) -> Union[_V, _T]:
    ...

  # We need to override this explicitly, because our defaultdict-like behavior
  # will make the default implementation (from our base class) always insert
  # the key.
  def get(self, key, default=None):
    if key in self:
      return self[key]
    else:
      return default

  def __setitem__(self, key: _K, value: _V) -> _T:
    checked_key = self._key_checker.CheckValue(key)
    checked_value = self._value_checker.CheckValue(value)
    self._values[checked_key] = checked_value
    self._message_listener.Modified()

  def __delitem__(self, key: _K) -> None:
    del self._values[key]
    self._message_listener.Modified()

  def __len__(self) -> int:
    return len(self._values)

  def __iter__(self) -> Iterator[_K]:
    return iter(self._values)

  def __repr__(self) -> str:
    return repr(self._values)

  def MergeFrom(self, other: 'ScalarMap[_K, _V]') -> None:
    self._values.update(other._values)
    self._message_listener.Modified()

  def InvalidateIterators(self) -> None:
    # It appears that the only way to reliably invalidate iterators to
    # self._values is to ensure that its size changes.
    original = self._values
    self._values = original.copy()
    original[None] = None

  # This is defined in the abstract base, but we can do it much more cheaply.
  def clear(self) -> None:
    self._values.clear()
    self._message_listener.Modified()

  def GetEntryClass(self) -> Any:
    return self._entry_descriptor._concrete_class

__init__(message_listener, key_checker, value_checker, entry_descriptor)

Parameters:

Name Type Description Default
message_listener Any

A MessageListener implementation. The ScalarMap will call this object's Modified() method when it is modified.

required
key_checker Any

A type_checkers.ValueChecker instance to run on keys inserted into this container.

required
value_checker Any

A type_checkers.ValueChecker instance to run on values inserted into this container.

required
entry_descriptor Any

The MessageDescriptor of a map entry: key and value.

required
Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
def __init__(
    self,
    message_listener: Any,
    key_checker: Any,
    value_checker: Any,
    entry_descriptor: Any,
) -> None:
  """
  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.
  """
  self._message_listener = message_listener
  self._key_checker = key_checker
  self._value_checker = value_checker
  self._entry_descriptor = entry_descriptor
  self._values = {}

UnknownFieldSet

UnknownField container

Source code in client/ayon_hiero/vendor/google/protobuf/internal/containers.py
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
class UnknownFieldSet:
  """UnknownField container"""

  # Disallows assignment to other attributes.
  __slots__ = ['_values']

  def __init__(self):
    self._values = []

  def __getitem__(self, index):
    if self._values is None:
      raise ValueError('UnknownFields does not exist. '
                       'The parent message might be cleared.')
    size = len(self._values)
    if index < 0:
      index += size
    if index < 0 or index >= size:
      raise IndexError('index %d out of range'.index)

    return UnknownFieldRef(self, index)

  def _internal_get(self, index):
    return self._values[index]

  def __len__(self):
    if self._values is None:
      raise ValueError('UnknownFields does not exist. '
                       'The parent message might be cleared.')
    return len(self._values)

  def _add(self, field_number, wire_type, data):
    unknown_field = _UnknownField(field_number, wire_type, data)
    self._values.append(unknown_field)
    return unknown_field

  def __iter__(self):
    for i in range(len(self)):
      yield UnknownFieldRef(self, i)

  def _extend(self, other):
    if other is None:
      return
    # pylint: disable=protected-access
    self._values.extend(other._values)

  def __eq__(self, other):
    if self is other:
      return True
    # Sort unknown fields because their order shouldn't
    # affect equality test.
    values = list(self._values)
    if other is None:
      return not values
    values.sort()
    # pylint: disable=protected-access
    other_values = sorted(other._values)
    return values == other_values

  def _clear(self):
    for value in self._values:
      # pylint: disable=protected-access
      if isinstance(value._data, UnknownFieldSet):
        value._data._clear()  # pylint: disable=protected-access
    self._values = None