Commits

Jan Borsodi committed 0eb9d28

Moved another proto function.

  • Participants
  • Parent commits 906472e

Comments (0)

Files changed (2)

File opprotoc/proto.py

              ,Proto.Message: "Message"
              }
     return ptypes[ptype]
+
+def proto_default(field):
+    if field.type == Proto.Bool:
+        if field.default:
+            return "true"
+        else:
+            return "false"
+    elif field.type == Proto.String:
+        return repr(field.default)
+    elif field.type == Proto.Bytes:
+        return repr(field.default)
+    elif field.type == Proto.Message:
+        raise Exception("Cannot use default values for field with type Message")
+    else:
+        return str(field.default)

File opprotoc/script.py

 import sys
 import re
 import random
-from opprotoc.proto import Proto, Quantifier, Field, Message, Command, Request, Response, Event, Service, protoname
+from opprotoc.proto import Proto, Quantifier, Field, Message, Command, Request, Response, Event, Service, protoname, proto_default
 from opprotoc.utils import tablify, dashed_name
 
 # TODO: Response object is not longer needed, instead let the requets object point to the response message
                     self.text += "// Old syntax (STP/0 core-2.2)\n"
                     self.text += command.response.core_2_2 + "\n"
 
-def proto_default(field):
-    if field.type == Proto.Bool:
-        if field.default:
-            return "true"
-        else:
-            return "false"
-    elif field.type == Proto.String:
-        return repr(field.default)
-    elif field.type == Proto.Bytes:
-        return repr(field.default)
-    elif field.type == Proto.Message:
-        raise Exception("Cannot use default values for field with type Message")
-    else:
-        return str(field.default)
-
 class TextMessageGenerator(object):
     message = None