Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: third_party/protobuf/python/google/protobuf/internal/containers.py

Issue 6737030: third_party/protobuf: update to upstream r371 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/python/google/protobuf/internal/containers.py
diff --git a/third_party/protobuf/python/google/protobuf/internal/containers.py b/third_party/protobuf/python/google/protobuf/internal/containers.py
index 5cc7d6d0c1105ffd3a7272fd35c4216e2abdcafc..097a3c269080eeed441d21b1938e304645ec47b5 100755
--- a/third_party/protobuf/python/google/protobuf/internal/containers.py
+++ b/third_party/protobuf/python/google/protobuf/internal/containers.py
@@ -72,9 +72,15 @@ class BaseContainer(object):
# The concrete classes should define __eq__.
return not self == other
+ def __hash__(self):
+ raise TypeError('unhashable object')
+
def __repr__(self):
return repr(self._values)
+ def sort(self, sort_function=cmp):
+ self._values.sort(sort_function)
+
class RepeatedScalarFieldContainer(BaseContainer):
@@ -198,28 +204,37 @@ class RepeatedCompositeFieldContainer(BaseContainer):
super(RepeatedCompositeFieldContainer, self).__init__(message_listener)
self._message_descriptor = message_descriptor
- def add(self):
- new_element = self._message_descriptor._concrete_class()
+ def add(self, **kwargs):
+ """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 MergeFrom(self, other):
- """Appends the contents of another repeated field of the same type to this
- one, copying each individual message.
+ def extend(self, elem_seq):
+ """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 other._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):
+ """Appends the contents of another repeated field of the same type to this
+ one, copying each individual message.
+ """
+ self.extend(other._values)
+
def __getslice__(self, start, stop):
"""Retrieves the subset of items from between the specified indices."""
return self._values[start:stop]

Powered by Google App Engine
This is Rietveld 408576698