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
8Upstream-Status: Submitted [https://github.com/seb-m/pyinotify/pull/205]
9
10Signed-off-by: Mingli Yu <mingli.yu@windriver.com>
11
12---
13 python3/pyinotify.py | 50 +++++++++++++++++++++++++-------------------
14 1 file changed, 28 insertions(+), 22 deletions(-)
15
16diff --git a/python3/pyinotify.py b/python3/pyinotify.py
17index bc24313..f4a5a90 100755
18--- a/python3/pyinotify.py
19+++ b/python3/pyinotify.py
20@@ -68,7 +68,6 @@ from collections import deque
21 from datetime import datetime, timedelta
22 import time
23 import re
24-import asyncore
25 import glob
26 import locale
27 import subprocess
28@@ -1494,33 +1493,40 @@ class ThreadedNotifier(threading.Thread, Notifier):
29         self.loop()
30
31
32-class AsyncNotifier(asyncore.file_dispatcher, Notifier):
33-    """
34-    This notifier inherits from asyncore.file_dispatcher in order to be able to
35-    use pyinotify along with the asyncore framework.
36+try:
37+    import asyncore
38
39-    """
40-    def __init__(self, watch_manager, default_proc_fun=None, read_freq=0,
41-                 threshold=0, timeout=None, channel_map=None):
42+    class AsyncNotifier(asyncore.file_dispatcher, Notifier):
43         """
44-        Initializes the async notifier. The only additional parameter is
45-        'channel_map' which is the optional asyncore private map. See
46-        Notifier class for the meaning of the others parameters.
47+        This notifier inherits from asyncore.file_dispatcher in order to be able to
48+        use pyinotify along with the asyncore framework.
49
50         """
51-        Notifier.__init__(self, watch_manager, default_proc_fun, read_freq,
52-                          threshold, timeout)
53-        asyncore.file_dispatcher.__init__(self, self._fd, channel_map)
54+        def __init__(self, watch_manager, default_proc_fun=None, read_freq=0,
55+                     threshold=0, timeout=None, channel_map=None):
56+            """
57+            Initializes the async notifier. The only additional parameter is
58+            'channel_map' which is the optional asyncore private map. See
59+            Notifier class for the meaning of the others parameters.
60
61-    def handle_read(self):
62-        """
63-        When asyncore tells us we can read from the fd, we proceed processing
64-        events. This method can be overridden for handling a notification
65-        differently.
66+            """
67+            Notifier.__init__(self, watch_manager, default_proc_fun, read_freq,
68+                              threshold, timeout)
69+            asyncore.file_dispatcher.__init__(self, self._fd, channel_map)
70
71-        """
72-        self.read_events()
73-        self.process_events()
74+        def handle_read(self):
75+            """
76+            When asyncore tells us we can read from the fd, we proceed processing
77+            events. This method can be overridden for handling a notification
78+            differently.
79+
80+            """
81+            self.read_events()
82+            self.process_events()
83+except ImportError:
84+    # asyncore was removed in Python 3.12, but try the import instead of a
85+    # version check in case the compatibility package is installed.
86+    pass
87
88
89 class TornadoAsyncNotifier(Notifier):
90--
912.25.1
92
93