def main(): direction_filter = filter_on_field(field='direction', val='North Bound', target=bus_info_printer()) route_filter = filter_on_field(field='route', val='22', target=direction_filter) xml.sax.parse( source='allroutes.xml', handler=EventHandler(target=buses_to_dicts(target=route_filter)))
def main(): # Start a new subprocess, which wraps some connected coroutines, and # listening on a pipe. p = subprocess.Popen(['python3', 'coprocess_bus.py'], stdin=subprocess.PIPE) # Set a sender coroutine to send data to the pipe that the new subprocess is # listening on sender = send_to(p.stdin) xml.sax.parse( source='allroutes.xml', handler=EventHandler(target=buses_to_dicts(target=sender)) )
messages.put(GeneratorExit) @coroutine def bus_locations(): while True: bus = (yield) print "%(route)s,%(id)s,\"%(direction)s\","\ "%(latitude)s,%(longitude)s" % bus xml.sax.parse( "buses.xml", EventHandler( buses_to_dicts( filter_on_field( "route", "147", filter_on_field("direction", "North Bound", bus_locations()))))) expat_parse( open("buses.xml"), buses_to_dicts( filter_on_field( "route", "147", filter_on_field("direction", "North Bound", bus_locations())))) xml.sax.parse( "buses.xml", EventHandler( buses_to_dicts( threaded(
def sendto(f): try: while True: item = (yield) pickle.dump(item, f) f.flush() except StopIteration: f.close() def recvfrom(f, target): try: while True: item = pickle.load(f) target.send(item) except EOFError: target.close() # Example use if __name__ == '__main__': import xml.sax from cosax import EventHandler from buses import (buses_to_dicts, filter_on_field, bus_locations) import subprocess p = subprocess.Popen(['python', 'busproc.py'], stdin=subprocess.PIPE) xml.sax.parse('allroutes.xml', EventHandler(buses_to_dicts(sendto(p.stdin))))
while True: d = yield if d.get(fieldname) == value: target.send(d) @coroutine def bus_locations(): while True: bus = yield print('%(route)s,%(id)s,"%(direction)s",' "%(latitude)s,%(longitude)s" % bus) # Example if __name__ == "__main__": import xml.sax from cosax import EventHandler xml.sax.parse( "allroutes.xml", EventHandler( buses_to_dicts( filter_on_field( "route", "22", filter_on_field("direction", "North Bound", bus_locations()), ) ) ), )
if d.get(fieldname) == value: target.send(d) @coroutine def bus_locations(): while True: bus = yield print("%(route)s,%(id)s, %(direction)s , %(latitude)s, %(longitude)s" % bus) if __name__ == '__main__': import xml.sax from cosax import EventHandler xml.sax.parse( 'allroutes.xml', EventHandler( buses_to_dicts( filter_on_field( "route", '147', filter_on_field('revenue', 'true', bus_locations()))))) from coexpat import expat_parse expat_parse( open('allroutes.xml'), buses_to_dicts( filter_on_field( "route", '147', filter_on_field('revenue', 'true', bus_locations()))))
try: while True: item = conn.recv() if item is GeneratorExit: target.close() return # item = pickle.load(f) target.send(item) except EOFError: print('eof error') target.close() if __name__ == '__main__': write_conn, read_conn = Pipe() p = Process(target=recvfrom, args=( read_conn, filter_on_field("route", "22", filter_on_field("direction", "North Bound", bus_locations())) )) p.start() xml.sax.parse('allroutes.xml', EventHandler( buses_to_dicts(sendto(write_conn)) )) print('======== done.')
target.close() return else: target.send(item) Thread(target=run_target).start() try: while True: item = (yield) messages.put(item) except GeneratorExit: messages.put(GeneratorExit) # Example use if __name__ == '__main__': import xml.sax from cosax import EventHandler from buses import (buses_to_dicts, filter_on_field, bus_locations) xml.sax.parse( 'allroutes.xml', EventHandler( buses_to_dicts( threaded( filter_on_field( 'route', '22', filter_on_field('direction', 'North Bound', bus_locations()))))))