File: cat.py

package info (click to toggle)
circuits 3.2.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,980 kB
  • sloc: python: 17,583; javascript: 3,226; makefile: 100
file content (38 lines) | stat: -rwxr-xr-x 877 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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 File, stdout, 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()