Commits

Jan Borsodi committed fc899cf Merge

Merged in changes from 0.3.1.

Comments (0)

Files changed (4)

+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
 ----------------
 
 """A multi-language code generator for the Opera Scope Protocol. Code is generated from Google Protocol Buffer definitions.
 """
 
-__version_num__ = (0, 3)
+__version_num__ = (0, 3, 1)
 __version__ = ".".join(map(str, __version_num__))
 __author__ = "Jan Borsodi, Christian Krebs"
 __author_email__ = "jborsodi@opera.com, chrisk@opera.com"
         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")
         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