Exemplo n.º 1
0
 def schedule(self, event_handler, path, recursive=False):
     # Fix for issue #26: Trace/BPT error when given a unicode path
     # string. https://github.com/gorakhargosh/watchdog/issues#issue/26
     if isinstance(path, unicode):
         #path = unicode(path, 'utf-8')
         path = unicodedata.normalize('NFC', path).encode('utf-8')
     BaseObserver.schedule(self, event_handler, path, recursive)
Exemplo n.º 2
0
def observer2():
    obs = BaseObserver(EventEmitter)
    yield obs
    obs.stop()
    try:
        obs.join()
    except RuntimeError:
        pass
Exemplo n.º 3
0
 def __init__(self, stat, listdir, polling_interval=1):
     """
     :param stat: stat function. See ``os.stat`` for details.
     :param listdir: listdir function. See ``os.listdir`` for details.
     :type polling_interval: float
     :param polling_interval: interval in seconds between polling the file system.
     """
     emitter_cls = partial(PollingEmitter, stat=stat, listdir=listdir)
     BaseObserver.__init__(self, emitter_class=emitter_cls, timeout=polling_interval)
Exemplo n.º 4
0
    def schedule(self, event_handler, path, recursive = False):
        try:
            str_class = unicode
        except NameError:
            str_class = str

        if isinstance(path, str_class):
            path = unicodedata.normalize('NFC', path)
            if sys.version_info < (3,):
                path = path.encode('utf-8')
        return BaseObserver.schedule(self, event_handler, path, recursive)
Exemplo n.º 5
0
    def schedule(self, event_handler, path, recursive=False):
        # Python 2/3 compat
        try:
            str_class = unicode
        except NameError:
            str_class = str

        # Fix for issue #26: Trace/BPT error when given a unicode path
        # string. https://github.com/gorakhargosh/watchdog/issues#issue/26
        if isinstance(path, str_class):
            #path = unicode(path, 'utf-8')
            path = unicodedata.normalize('NFC', path).encode('utf-8')
        return BaseObserver.schedule(self, event_handler, path, recursive)
Exemplo n.º 6
0
    def schedule(self, event_handler, path, recursive=False):
        # Python 2/3 compat
        try:
            str_class = unicode
        except NameError:
            str_class = str

        # Fix for issue #26: Trace/BPT error when given a unicode path
        # string. https://github.com/gorakhargosh/watchdog/issues#issue/26
        if isinstance(path, str_class):
            #path = unicode(path, 'utf-8')
            path = unicodedata.normalize('NFC', path)
            # We only encode the path in Python 2 for backwards compatibility.
            # On Python 3 we want the path to stay as unicode if possible for
            # the sake of path matching not having to be rewritten to use the
            # bytes API instead of strings. The _watchdog_fsevent.so code for
            # Python 3 can handle both str and bytes paths, which is why we
            # do not HAVE to encode it with Python 3. The Python 2 code in
            # _watchdog_fsevents.so was not changed for the sake of backwards
            # compatibility.
            if sys.version_info < (3,):
                path = path.encode('utf-8')
        return BaseObserver.schedule(self, event_handler, path, recursive)
Exemplo n.º 7
0
 def __init__(self):
     BaseObserver.__init__(self, None)
Exemplo n.º 8
0
    def test_basic(self):
        observer = BaseObserver(EventEmitter)
        handler = LoggingEventHandler()

        watch = observer.schedule(handler, "/foobar", True)
        observer.add_handler_for_watch(handler, watch)
        observer.add_handler_for_watch(handler, watch)
        observer.remove_handler_for_watch(handler, watch)
        self.assertRaises(KeyError, observer.remove_handler_for_watch, handler,
                          watch)
        observer.unschedule(watch)
        self.assertRaises(KeyError, observer.unschedule, watch)

        watch = observer.schedule(handler, "/foobar", True)
        observer.event_queue.put((FileModifiedEvent("/foobar"), watch))
        observer.start()
        time.sleep(1)
        observer.unschedule_all()
        observer.stop()
Exemplo n.º 9
0
 def schedule(self, event_handler, path, recursive=False):
     # Fix for issue #26: Trace/BPT error when given a unicode path
     # string. https://github.com/gorakhargosh/watchdog/issues#issue/26
     if isinstance(path, str):
         path = unicodedata.normalize('NFC', path)
     return BaseObserver.schedule(self, event_handler, path, recursive)
 def __init__(self, timeout=DEFAULT_OBSERVER_TIMEOUT):
     BaseObserver.__init__(self, emitter_class=WindowsApiAsyncEmitter,
                           timeout=timeout)
 def __init__(self, timeout=DEFAULT_OBSERVER_TIMEOUT):
     BaseObserver.__init__(self, emitter_class=PollingEmitterWithState, timeout=timeout)
Exemplo n.º 12
0
 def __init__(self, make_snapshot, polling_interval=1):
   constructor = partial(Poller, make_snapshot=make_snapshot)
   BaseObserver.__init__(self, constructor, polling_interval)
Exemplo n.º 13
0
 def __init__(self):
     BaseObserver.__init__(self, None)
Exemplo n.º 14
0
def test_observer_basic():
    observer = BaseObserver(EventEmitter)
    handler = LoggingEventHandler()

    watch = observer.schedule(handler, '/foobar', True)
    observer.add_handler_for_watch(handler, watch)
    observer.add_handler_for_watch(handler, watch)
    observer.remove_handler_for_watch(handler, watch)
    with pytest.raises(KeyError):
        observer.remove_handler_for_watch(handler, watch)
    observer.unschedule(watch)
    with pytest.raises(KeyError):
        observer.unschedule(watch)

    watch = observer.schedule(handler, '/foobar', True)
    observer.event_queue.put((FileModifiedEvent('/foobar'), watch))
    observer.start()
    time.sleep(1)
    observer.unschedule_all()
    observer.stop()
    observer.join()
Exemplo n.º 15
0
 def __init__(self, timeout=DEFAULT_OBSERVER_TIMEOUT, generate_full_events=False):
     if (generate_full_events):
         BaseObserver.__init__(self, emitter_class=InotifyFullEmitter, timeout=timeout)
     else:
         BaseObserver.__init__(self, emitter_class=InotifyEmitter,
                           timeout=timeout)
Exemplo n.º 16
0
  def test_basic(self):
    observer = BaseObserver(EventEmitter)
    handler = LoggingEventHandler()

    watch = observer.schedule(handler, '/foobar', True)
    observer.add_handler_for_watch(handler, watch)
    observer.add_handler_for_watch(handler, watch)
    observer.remove_handler_for_watch(handler, watch)
    self.assertRaises(KeyError,
                      observer.remove_handler_for_watch, handler, watch)
    observer.unschedule(watch)
    self.assertRaises(KeyError, observer.unschedule, watch)

    watch = observer.schedule(handler, '/foobar', True)
    observer.event_queue.put((FileModifiedEvent('/foobar'), watch))
    observer.start()
    time.sleep(1)
    observer.unschedule_all()
    observer.stop()
Exemplo n.º 17
0
def observer2():
    obs = BaseObserver(EventEmitter)
    yield obs
    obs.stop()
Exemplo n.º 18
0
 def __init__(self, timeout=DEFAULT_OBSERVER_TIMEOUT):
     BaseObserver.__init__(self, emitter_class=MistWatchdogPollingEmitter, timeout=timeout)
Exemplo n.º 19
0
 def __init__(self, stat, listdir, polling_interval=1):
    
     emitter_cls = partial(PollingEmitter, stat=stat, listdir=listdir)
     BaseObserver.__init__(self, emitter_class=emitter_cls, timeout=polling_interval)
Exemplo n.º 20
0
 def __init__(self, timeout=DEFAULT_OBSERVER_TIMEOUT):
     BaseObserver.__init__(self,
                           emitter_class=FSEventsEmitter,
                           timeout=timeout)
Exemplo n.º 21
0
 def __init__(self, timeout=DEFAULT_OBSERVER_TIMEOUT):
     BaseObserver.__init__(self,
                           emitter_class=WindowsApiEmitter,
                           timeout=timeout)
Exemplo n.º 22
0
 def __init__(self, timeout=DEFAULT_OBSERVER_TIMEOUT, generate_full_events=False):
     if (generate_full_events):
         BaseObserver.__init__(self, emitter_class=InotifyFullEmitter, timeout=timeout)
     else:
         BaseObserver.__init__(self, emitter_class=InotifyEmitter,
                           timeout=timeout)
Exemplo n.º 23
0
 def __init__(self, timeout=DEFAULT_OBSERVER_TIMEOUT):
   BaseObserver.__init__(self, emitter_class=InotifyEmitter,
                         timeout=timeout)
Exemplo n.º 24
0
    def __init__(self, stat, listdir, polling_interval=1):

        emitter_cls = partial(PollingEmitter, stat=stat, listdir=listdir)
        BaseObserver.__init__(self,
                              emitter_class=emitter_cls,
                              timeout=polling_interval)