def test_behavior_ordered_set(self): dir_mod_event = DirModifiedEvent("/path/x") file_mod_event = FileModifiedEvent('/path/y') event_list = [ dir_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, file_mod_event, file_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, file_mod_event, file_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, file_mod_event, file_mod_event, file_mod_event, file_mod_event, ] event_set = set(event_list) event_queue = OrderedSetQueue() for event in event_list: event_queue.put(event) def event_consumer(in_queue): events = [] while True: try: event = in_queue.get(block=True, timeout=0.2) events.append(event) in_queue.task_done() except queue.Empty: break # Check set behavior. assert_true(len(set(events)) == len(events)) assert_equal(set(events), event_set) # Check order. assert_equal(events[0], dir_mod_event) assert_equal(events[1], file_mod_event) consumer_thread = threading.Thread(target=event_consumer, args=(event_queue,)) consumer_thread.start() consumer_thread.join()
def test_behavior_ordered_set(self): dir_mod_event = DirModifiedEvent("/path/x") file_mod_event = FileModifiedEvent("/path/y") event_list = [ dir_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, file_mod_event, file_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, file_mod_event, file_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, dir_mod_event, file_mod_event, file_mod_event, file_mod_event, file_mod_event, ] event_set = set(event_list) event_queue = OrderedSetQueue() for event in event_list: event_queue.put(event) def event_consumer(in_queue): events = [] while True: try: event = in_queue.get(block=True, timeout=0.2) events.append(event) in_queue.task_done() except queue.Empty: break # Check set behavior. assert_true(len(set(events)) == len(events)) assert_equal(set(events), event_set) # Check order. assert_equal(events[0], dir_mod_event) assert_equal(events[1], file_mod_event) consumer_thread = threading.Thread(target=event_consumer, args=(event_queue,)) consumer_thread.start() consumer_thread.join()
def __init__(self, path, **kwargs): """Create observer for the directory at `path`.""" Observer.__init__(self, **kwargs) # replace default event queue with ordered set queue to disallow # duplicate events even if added out of order self._event_queue = OrderedSetQueue() RegexMatchingEventHandler.__init__(self) self.path = os.path.abspath(path) self.root_observer = Observer(**kwargs) self.root_watch = None self._stopped_handlers = dict() self._dispatching_enabled = True
def __init__(self, path, force_polling=False, **kwargs): """Create observer for the directory at `path`.""" if force_polling: observer_class = PollingObserver else: observer_class = Observer self.root_observer = observer_class(**kwargs) # get proper emitter class from root_observer instance of observer_class BaseObserver.__init__(self, emitter_class=self.root_observer._emitter_class, **kwargs) # replace default event queue with ordered set queue to disallow # duplicate events even if added out of order self._event_queue = OrderedSetQueue() RegexMatchingEventHandler.__init__(self) self.path = os.path.abspath(path) self.root_watch = None self._stopped_handlers = dict() self._dispatching_enabled = True
"""read_string(string, bool) -> (string, bool)""" buffer = buffer.replace('\t', ' ').strip() result = '' i = 0 while i < len(buffer) : if buffer[i] == '/' and i + 1 < len(buffer): if buffer[i + 1] == '/' : return (result, found_comment, brace_level + result.count('{') - result.count('}')) elif buffer[i + 1] == '*' : found_comment = True i += 1 elif not found_comment : result += '/' elif found_comment : if buffer[i] == '*' and i + 1 < len(buffer) and buffer[i + 1] == '/' : found_comment = False i += 1 elif not (i > 0 and buffer[i] == ' ' and buffer[i - 1] == ' '): result += buffer[i] i += 1 return (result, found_comment, brace_level + result.count('{') - result.count('}')) to_process = OrderedSetQueue() nodes = dict() # map files to nodes include_dir = StringWrapper() file_observer = watchdog.observers.Observer() process_thread = ProcessQueueThread()