/examples/cat.py
https://bitbucket.org/prologic/circuits/ · Python · 42 lines · 14 code · 15 blank · 13 comment · 0 complexity · df5a4d1e2f34b854be4c145836245b5a MD5 · raw file
- #!/usr/bin/env python
- """Clone of the standard UNIX "cat" command.
- This example shows how you can utilize some of the buitlin I/O components
- in circuits to write a very simple clone of the standard UNIX "cat" command.
- """
- import sys
- from circuits.io import stdout, File, write
- class Cat(File):
- # This adds the already instantiated stdout instnace
- stdout = stdout
- def read(self, data):
- """Read Event Handler
- This is fired by the File Component when there is data to be read
- from the underlying file that was opened.
- """
- self.fire(write(data), stdout)
- def eof(self):
- """End Of File Event
- This is fired by the File Component when the underlying input file
- has been exhcuasted.
- """
- raise SystemExit(0)
- # Start and "run" the system.
- Cat(sys.argv[1]).run()