PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/examples/cat.py

https://bitbucket.org/prologic/circuits/
Python | 42 lines | 39 code | 2 blank | 1 comment | 0 complexity | df5a4d1e2f34b854be4c145836245b5a MD5 | raw file
 1#!/usr/bin/env python
 2
 3
 4"""Clone of the standard UNIX "cat" command.
 5
 6This example shows how you can utilize some of the buitlin I/O components
 7in circuits to write a very simple clone of the standard UNIX "cat" command.
 8"""
 9
10
11import sys
12
13
14from circuits.io import stdout, File, write
15
16
17class Cat(File):
18
19    # This adds the already instantiated stdout instnace
20    stdout = stdout
21
22    def read(self, data):
23        """Read Event Handler
24
25        This is fired by the File Component when there is data to be read
26        from the underlying file that was opened.
27        """
28
29        self.fire(write(data), stdout)
30
31    def eof(self):
32        """End Of File Event
33
34        This is fired by the File Component when the underlying input file
35        has been exhcuasted.
36        """
37
38        raise SystemExit(0)
39
40
41# Start and "run" the system.
42Cat(sys.argv[1]).run()