Commits

Jan Borsodi  committed 2c6dade Merge

Merged in 0.3 fixes.

  • Participants
  • Parent commits a82360a, bd2a180
  • Branches release-0.x

Comments (0)

Files changed (3)

+0.3.1 - 2010-12-01
+------------------
+
+proto
+~~~~~
+
+* Fixed parsing of default values for enum fields. Some proto files had
+  incorrectly used numbers for default values. This is now supported by
+  looking for the enum entry with the same value.
+
 0.3 - 2010-10-27
 ----------------
 

File hob/parser.py

         if isinstance(self._item, Field) and self._item.message:
             def set_default_enum(sym, item):
                 if isinstance(sym.owner.message, Enum):
+                    # Compatibility with code that expects a number in item.default
+                    if isinstance(item, EnumValue):
+                        sym.owner.setDefaultValue(item.value)
+                        sym.owner.setDefaultText(str(item.value))
                     sym.owner.setDefaultObject(item)
                 else:
                     raise BuildError("Messages can't have default values")

File hob/proto.py

         if current:
             while current:
                 for child in current.items:
-                    if child.name == path[0]:
+                    num = None
+                    if isinstance(child, EnumValue):
+                        try:
+                            num = int(path[0])
+                        except ValueError:
+                            pass
+                    if child.name == path[0] or (num is not None and child.value == num):
                         item = child
                         if path[1:]:
                             item = msg_find(item, path[1:])
         self.default = value
         self.default_object = value
 
+    def setDefaultValue(self, value):
+        self.default = value
+
     def setDefaultText(self, text):
         self.default_text = text