24 lines
855 B
Python
24 lines
855 B
Python
class Formatter(object):
|
|
"""Formatters are callable objects who always accept a generator.
|
|
The generator represents the output stream of an executing program.
|
|
Formatters are special commands which produce no output themselves.
|
|
Instead, they always write to the standard out of the program. """
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
# Always require no arguments
|
|
pass
|
|
|
|
def __call__(self, input_generator):
|
|
raise NotImplementedError(
|
|
"You must extend a Formatter and implement the __call__ method")
|
|
|
|
|
|
class Printer(Formatter):
|
|
"""Simple formatter which accepts any object from the input
|
|
generator and simply prints it as if it were a string."""
|
|
|
|
def __call__(self, input_generator):
|
|
for line in input_generator:
|
|
print(str(line.decode('utf-8')))
|
|
return None
|