1From 478d595a7d086423733e9f5da5edfe9f1df48682 Mon Sep 17 00:00:00 2001
2From: Troy Curtis Jr <troy@troycurtisjr.com>
3Date: Thu, 10 Aug 2023 21:51:15 -0400
4Subject: [PATCH] Make asyncore support optional for Python 3.
5
6Fixes #204.
7---
8 python3/pyinotify.py | 50 +++++++++++++++++++++++++-------------------
9 1 file changed, 28 insertions(+), 22 deletions(-)
10
11diff --git a/python3/pyinotify.py b/python3/pyinotify.py
12index bc24313..f4a5a90 100755
13--- a/python3/pyinotify.py
14+++ b/python3/pyinotify.py
15@@ -68,7 +68,6 @@ def __init__(self, version):
16 from datetime import datetime, timedelta
17 import time
18 import re
19-import asyncore
20 import glob
21 import locale
22 import subprocess
23@@ -1494,33 +1493,40 @@ def run(self):
24 self.loop()
25
26
27-class AsyncNotifier(asyncore.file_dispatcher, Notifier):
28- """
29- This notifier inherits from asyncore.file_dispatcher in order to be able to
30- use pyinotify along with the asyncore framework.
31+try:
32+ import asyncore
33
34- """
35- def __init__(self, watch_manager, default_proc_fun=None, read_freq=0,
36- threshold=0, timeout=None, channel_map=None):
37+ class AsyncNotifier(asyncore.file_dispatcher, Notifier):
38 """
39- Initializes the async notifier. The only additional parameter is
40- 'channel_map' which is the optional asyncore private map. See
41- Notifier class for the meaning of the others parameters.
42+ This notifier inherits from asyncore.file_dispatcher in order to be able to
43+ use pyinotify along with the asyncore framework.
44
45 """
46- Notifier.__init__(self, watch_manager, default_proc_fun, read_freq,
47- threshold, timeout)
48- asyncore.file_dispatcher.__init__(self, self._fd, channel_map)
49+ def __init__(self, watch_manager, default_proc_fun=None, read_freq=0,
50+ threshold=0, timeout=None, channel_map=None):
51+ """
52+ Initializes the async notifier. The only additional parameter is
53+ 'channel_map' which is the optional asyncore private map. See
54+ Notifier class for the meaning of the others parameters.
55
56- def handle_read(self):
57- """
58- When asyncore tells us we can read from the fd, we proceed processing
59- events. This method can be overridden for handling a notification
60- differently.
61+ """
62+ Notifier.__init__(self, watch_manager, default_proc_fun, read_freq,
63+ threshold, timeout)
64+ asyncore.file_dispatcher.__init__(self, self._fd, channel_map)
65
66- """
67- self.read_events()
68- self.process_events()
69+ def handle_read(self):
70+ """
71+ When asyncore tells us we can read from the fd, we proceed processing
72+ events. This method can be overridden for handling a notification
73+ differently.
74+
75+ """
76+ self.read_events()
77+ self.process_events()
78+except ImportError:
79+ # asyncore was removed in Python 3.12, but try the import instead of a
80+ # version check in case the compatibility package is installed.
81+ pass
82
83
84 class TornadoAsyncNotifier(Notifier):