This repository has been archived on 2015-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
psh/formatters.py
2015-02-20 18:27:21 -05:00

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