Ejemplo n.º 1
0
 def setUp(self):
   self.events = []
   
   def emit(event):
     self.events.append(event)
   
   self.poll = seastorm_watch_filesystem.watch('files', emit)
 def getEvents(self):
   self.send_response(200)
   self.send_header('Content-Type', 'text/event-stream')
   self.sendCorsHeaders()
   self.end_headers()
   
   def emit(filename):
     # Make sure that a filename with newlines does not break the event format
     # or inject events.
     escapedFilename = filename.replace('\n', '').replace('\r', '')
     self.wfile.write('data: ' + str(escapedFilename) + '\n\n')
   
   poll = seastorm_watch_filesystem.watch(self.watchPath, emit)
   
   while True:
     poll()
     time.sleep(self.pollInterval)