<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from . base import BaseScanner <EOL> import fsevents <EOL> import time <EOL> import sys <EOL> class FSEventsScanner ( BaseScanner ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( FSEventsScanner , self ) . __init__ ( * args , ** kwargs ) <EOL> self . _observer = self . _generate_observer ( ) <EOL> def _generate_observer ( self ) : <EOL> observer = fsevents . Observer ( ) <EOL> for path in self . paths : <EOL> stream = fsevents . Stream ( self . _callback , path , file_events = True ) <EOL> observer . schedule ( stream ) <EOL> return observer <EOL> def loop ( self , sleep_time = None ) : <EOL> self . log ( "<STR_LIT>" ) <EOL> self . trigger_init ( ) <EOL> self . _observer . start ( ) <EOL> try : <EOL> while <NUM_LIT:1> : <EOL> time . sleep ( <NUM_LIT> ) <EOL> except ( KeyboardInterrupt , OSError , IOError ) : <EOL> self . stop ( ) <EOL> def stop ( self ) : <EOL> try : <EOL> from io import StringIO <EOL> except : <EOL> try : <EOL> from cStringIO import StringIO <EOL> except : <EOL> from StringIO import StringIO <EOL> old_err , old_out = sys . stderr , sys . stdout <EOL> sys . stderr , sys . stdout = StringIO ( ) , StringIO ( ) <EOL> self . _observer . stop ( ) <EOL> sys . stderr , sys . stdout = old_err , old_out <EOL> def _callback ( self , event ) : <EOL> if not self . is_valid_type ( event . name ) : <EOL> return <EOL> if event . mask & ( fsevents . IN_MODIFY ) : <EOL> self . trigger_modified ( event . name ) <EOL> if event . mask & fsevents . IN_CREATE : <EOL> self . trigger_created ( event . name ) <EOL> if event . mask & fsevents . IN_DELETE : <EOL> self . trigger_deleted ( event . name ) </s>
