My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones    
 
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
#!/usr/bin/env python
#
# Library: pyflowctrl
# Module: filereader2
# Dependency: core3
# Examples:
#
#

import os
from core3 import Stream, Process, EmptyStream
from core3 import WAITING, PROCESSING
from streams.stdiostreams1 import StandardErrorStream

class FileReader(Process):
''' file reader '''

def __init__(self):
super(FileReader, self).__init__()
self.io = {
'input': Stream(data_type='path'),
'output': Stream(data_type=('path', 'data')),
}

def main(self):
while True:
try:
path = self.io['input'].get()
except EmptyStream:
yield WAITING
continue

if os.path.isfile(path):
data = open(path, 'r').read()
self.io['output'].put((path, data))
yield PROCESSING

Change log

0c95c67ab88b by ownport <ownport> on Aug 14, 2011   Diff
pyflowctrl: processes FileReader,
HTMLSpecials, TextProcessing, TreeWalker
migrated to core3
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 919 bytes, 36 lines
Powered by Google Project Hosting