Revisit telethon_generator (closes #724)

This commit is contained in:
Lonami Exo
2018-04-01 12:46:44 +02:00
parent 7bc021bba4
commit cb226e7f45
2 changed files with 130 additions and 146 deletions

View File

@@ -16,7 +16,7 @@ class SourceBuilder:
"""
self.write(' ' * (self.current_indent * self.indent_size))
def write(self, string):
def write(self, string, *args, **kwargs):
"""Writes a string into the source code,
applying indentation if required
"""
@@ -26,13 +26,16 @@ class SourceBuilder:
if string.strip():
self.indent()
self.out_stream.write(string)
if args or kwargs:
self.out_stream.write(string.format(*args, **kwargs))
else:
self.out_stream.write(string)
def writeln(self, string=''):
def writeln(self, string='', *args, **kwargs):
"""Writes a string into the source code _and_ appends a new line,
applying indentation if required
"""
self.write(string + '\n')
self.write(string + '\n', *args, **kwargs)
self.on_new_line = True
# If we're writing a block, increment indent for the next time