From 965f672842e8a20e187027e0ca37a6990de0225b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florent=20Thi=C3=A9ry?= Date: Thu, 2 Jul 2020 09:59:32 +0200 Subject: [PATCH] add support for pathlib objects, improve logging, fixes #187 --- python3/pyinotify.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/python3/pyinotify.py b/python3/pyinotify.py index bc24313..47f83d2 100755 --- a/python3/pyinotify.py +++ b/python3/pyinotify.py @@ -1903,9 +1903,16 @@ def add_watch(self, path, mask, proc_fun=None, rec=False, # normalize args as list elements for npath in self.__format_param(path): - # Require that path be a unicode string + # attempt to cast to string so that pathlib objects are supported + try: + npath = str(path) + except ValueError: + pass + + # require that path be a unicode string if not isinstance(npath, str): ret_[path] = -3 + log.error('add_watch: invalid path "%s"' % repr(path)) continue # unix pathname pattern expansion