本文整理汇总了Python中watchdog.observers.api.BaseObserver.schedule方法的典型用法代码示例。如果您正苦于以下问题:Python BaseObserver.schedule方法的具体用法?Python BaseObserver.schedule怎么用?Python BaseObserver.schedule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类watchdog.observers.api.BaseObserver
的用法示例。
在下文中一共展示了BaseObserver.schedule方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: schedule
# 需要导入模块: from watchdog.observers.api import BaseObserver [as 别名]
# 或者: from watchdog.observers.api.BaseObserver import schedule [as 别名]
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)
示例2: test_basic
# 需要导入模块: from watchdog.observers.api import BaseObserver [as 别名]
# 或者: from watchdog.observers.api.BaseObserver import schedule [as 别名]
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()
示例3: schedule
# 需要导入模块: from watchdog.observers.api import BaseObserver [as 别名]
# 或者: from watchdog.observers.api.BaseObserver import schedule [as 别名]
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)
示例4: schedule
# 需要导入模块: from watchdog.observers.api import BaseObserver [as 别名]
# 或者: from watchdog.observers.api.BaseObserver import schedule [as 别名]
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)
示例5: schedule
# 需要导入模块: from watchdog.observers.api import BaseObserver [as 别名]
# 或者: from watchdog.observers.api.BaseObserver import schedule [as 别名]
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)