Index: third_party/protobuf/conformance/update_failure_list.py |
diff --git a/third_party/protobuf/python/google/protobuf/pyext/cpp_message.py b/third_party/protobuf/conformance/update_failure_list.py |
old mode 100644 |
new mode 100755 |
similarity index 57% |
copy from third_party/protobuf/python/google/protobuf/pyext/cpp_message.py |
copy to third_party/protobuf/conformance/update_failure_list.py |
index b215211ee581f2bfa4fa8d06cf3ca3fc27941f56..69f210e37c3c65e9a5fc5f4ed8e38a217e0a3b38 |
--- a/third_party/protobuf/python/google/protobuf/pyext/cpp_message.py |
+++ b/third_party/protobuf/conformance/update_failure_list.py |
@@ -1,3 +1,4 @@ |
+#!/usr/bin/env python |
# Protocol Buffers - Google's data interchange format |
# Copyright 2008 Google Inc. All rights reserved. |
# https://developers.google.com/protocol-buffers/ |
@@ -28,38 +29,45 @@ |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-"""Protocol message implementation hooks for C++ implementation. |
+"""Script to update a failure list file to add/remove failures. |
-Contains helper functions used to create protocol message classes from |
-Descriptor objects at runtime backed by the protocol buffer C++ API. |
+This is sort of like comm(1), except it recognizes comments and ignores them. |
""" |
-__author__ = 'tibell@google.com (Johan Tibell)' |
+import argparse |
+import fileinput |
-from google.protobuf.pyext import _message |
+parser = argparse.ArgumentParser( |
+ description='Adds/removes failures from the failure list.') |
+parser.add_argument('filename', type=str, help='failure list file to update') |
+parser.add_argument('--add', dest='add_list', action='append') |
+parser.add_argument('--remove', dest='remove_list', action='append') |
+args = parser.parse_args() |
-class GeneratedProtocolMessageType(_message.MessageMeta): |
+add_set = set() |
+remove_set = set() |
- """Metaclass for protocol message classes created at runtime from Descriptors. |
+for add_file in (args.add_list or []): |
+ with open(add_file) as f: |
+ for line in f: |
+ add_set.add(line) |
- The protocol compiler currently uses this metaclass to create protocol |
- message classes at runtime. Clients can also manually create their own |
- classes at runtime, as in this example: |
+for remove_file in (args.remove_list or []): |
+ with open(remove_file) as f: |
+ for line in f: |
+ if line in add_set: |
+ raise "Asked to both add and remove test: " + line |
+ remove_set.add(line.strip()) |
- mydescriptor = Descriptor(.....) |
- class MyProtoClass(Message): |
- __metaclass__ = GeneratedProtocolMessageType |
- DESCRIPTOR = mydescriptor |
- myproto_instance = MyProtoClass() |
- myproto.foo_field = 23 |
- ... |
+add_list = sorted(add_set, reverse=True) |
- The above example will not work for nested types. If you wish to include them, |
- use reflection.MakeClass() instead of manually instantiating the class in |
- order to create the appropriate class structure. |
- """ |
+existing_list = file(args.filename).read() |
- # Must be consistent with the protocol-compiler code in |
- # proto2/compiler/internal/generator.*. |
- _DESCRIPTOR_KEY = 'DESCRIPTOR' |
+with open(args.filename, "w") as f: |
+ for line in existing_list.splitlines(True): |
+ test = line.split("#")[0].strip() |
+ while len(add_list) > 0 and test > add_list[-1]: |
+ f.write(add_list.pop()) |
+ if test not in remove_set: |
+ f.write(line) |