Commits

Kyle Schaffrick committed 45e5d20

Decorate Python reserved words in AMQP specification.

Comments (0)

Files changed (1)

 from lxml import etree
 
 
+def decorate_keyword(kw):
+    if kw in ['global']:
+        return kw + '_'
+    else:
+        return kw
+
+
 def build_amqp_methods(filename):
     defs_tree = etree.parse(filename)
     defs = {}
         pack_data[ pd.pop('type') ] = pd
 
     for class_ in defs_tree.xpath("//class"):
-        class_name = class_.attrib['name']
+        class_name = decorate_keyword(class_.attrib['name'])
 
         md = {}
         defs[class_name] = {
 
         for method in class_.xpath("method"):
             fl = []
+            method_name = decorate_keyword(method.attrib['name'])
             method_data = {
                     'id': int(method.attrib['id']),
                     'fields': fl,
-                    'name': method.attrib['name'] }
-            md[ method.attrib['name'] ] = method_data
+                    'name': method_name }
+            md[method_name] = method_data
 
             for field in method.xpath("field"):
-                field_data = {'name': field.attrib['name']}
+                field_data = {'name': decorate_keyword(field.attrib['name']) }
                 field_data.update(pack_data[ field.attrib['type'] ])
                 fl.append(field_data)
 
         for i, field in enumerate(class_.xpath("field")):
             bit -= 1
             field_data = {
-                    'name': field.attrib['name'],
+                    'name': decorate_keyword(field.attrib['name']),
                     'pos': i,
                     'bitmask': 1 << bit }
             field_data.update(pack_data[ field.attrib['type'] ])