Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Converter():
- def __init__(self, obj):
- self.obj = obj
- self.indentCount = 0
- self.currentVarNum = 0
- self.result = ''
- def indent(self, delta = 0):
- tabs = ''
- for i in range(self.indentCount + delta):
- tabs += '\t'
- return tabs
- def convert(self):
- for o in self.obj:
- self.convertObj(o)
- return self.result
- def convertObj(self, o, parent = None):
- if o['type'] == 'obj':
- if parent:
- parent['val'].append({
- 'key': o['key'],
- 'type': 'val',
- 'dataType': o['key'].upper()
- })
- self.currentVarNum = 0
- self.result += self.indent() +'message '+ o['key'] +' {\n'
- self.indentCount += 1
- for pair in o['val']:
- self.convertObj(pair, o)
- self.indentCount -= 1
- self.result += self.indent() + '}\n'
- elif o['type'] == 'val' and o['dataType'] != 'null':
- self.currentVarNum += 1
- self.result += self.indent() + 'required '+ o['dataType'] +' '+ o['key'] +' = '+ str(self.currentVarNum) +'\n'
- def error(message):
- raise Exception('[CONVERTER][ERROR] ' + message);
Add Comment
Please, Sign In to add comment