~ubuntu-branches/ubuntu/trusty/protobuf/trusty-proposed

« back to all changes in this revision

Viewing changes to python/google/protobuf/internal/containers.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-05-31 14:41:47 UTC
  • mfrom: (2.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20110531144147-s41g5fozgvyo462l
Tags: 2.4.0a-2ubuntu1
* Merge with Debian; remaining changes:
  - Fix linking with -lpthread.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
    # The concrete classes should define __eq__.
73
73
    return not self == other
74
74
 
 
75
  def __hash__(self):
 
76
    raise TypeError('unhashable object')
 
77
 
75
78
  def __repr__(self):
76
79
    return repr(self._values)
77
80
 
 
81
  def sort(self, sort_function=cmp):
 
82
    self._values.sort(sort_function)
 
83
 
78
84
 
79
85
class RepeatedScalarFieldContainer(BaseContainer):
80
86
 
198
204
    super(RepeatedCompositeFieldContainer, self).__init__(message_listener)
199
205
    self._message_descriptor = message_descriptor
200
206
 
201
 
  def add(self):
202
 
    new_element = self._message_descriptor._concrete_class()
 
207
  def add(self, **kwargs):
 
208
    """Adds a new element at the end of the list and returns it. Keyword
 
209
    arguments may be used to initialize the element.
 
210
    """
 
211
    new_element = self._message_descriptor._concrete_class(**kwargs)
203
212
    new_element._SetListener(self._message_listener)
204
213
    self._values.append(new_element)
205
214
    if not self._message_listener.dirty:
206
215
      self._message_listener.Modified()
207
216
    return new_element
208
217
 
209
 
  def MergeFrom(self, other):
210
 
    """Appends the contents of another repeated field of the same type to this
211
 
    one, copying each individual message.
 
218
  def extend(self, elem_seq):
 
219
    """Extends by appending the given sequence of elements of the same type
 
220
    as this one, copying each individual message.
212
221
    """
213
222
    message_class = self._message_descriptor._concrete_class
214
223
    listener = self._message_listener
215
224
    values = self._values
216
 
    for message in other._values:
 
225
    for message in elem_seq:
217
226
      new_element = message_class()
218
227
      new_element._SetListener(listener)
219
228
      new_element.MergeFrom(message)
220
229
      values.append(new_element)
221
230
    listener.Modified()
222
231
 
 
232
  def MergeFrom(self, other):
 
233
    """Appends the contents of another repeated field of the same type to this
 
234
    one, copying each individual message.
 
235
    """
 
236
    self.extend(other._values)
 
237
 
223
238
  def __getslice__(self, start, stop):
224
239
    """Retrieves the subset of items from between the specified indices."""
225
240
    return self._values[start:stop]