File: 0001-Python-3.11-compatibility.patch

package info (click to toggle)
python-lepl 5.1.3-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,760 kB
  • sloc: python: 19,614; makefile: 2
file content (217 lines) | stat: -rw-r--r-- 8,074 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
From: Boyuan Yang <byang@debian.org>
Date: Sun, 28 Jul 2024 12:46:54 -0400
Subject: Python 3.11 compatibility

Forwarded: no
---
 src/lepl/apps/rfc3696.py                    |  2 +-
 src/lepl/lexer/lines/_example/line_aware.py |  8 ++++----
 src/lepl/matchers/derived.py                |  2 +-
 src/lepl/matchers/operators.py              |  4 ++--
 src/lepl/matchers/support.py                | 20 ++++++++++----------
 src/lepl/regexp/str.py                      |  2 +-
 src/lepl/stream/factory.py                  |  5 ++++-
 src/lepl/support/graph.py                   |  6 +++++-
 8 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/src/lepl/apps/rfc3696.py b/src/lepl/apps/rfc3696.py
index 1477b44..f333139 100644
--- a/src/lepl/apps/rfc3696.py
+++ b/src/lepl/apps/rfc3696.py
@@ -425,7 +425,7 @@ def HttpUrl():
 
 
 def MailToUrl():
-    '''
+    r'''
     Generate a validator for email addresses, according to RFC3696, which 
     returns True if the URL is valid, and False otherwise.
     
diff --git a/src/lepl/lexer/lines/_example/line_aware.py b/src/lepl/lexer/lines/_example/line_aware.py
index d1421d9..d3d861c 100644
--- a/src/lepl/lexer/lines/_example/line_aware.py
+++ b/src/lepl/lexer/lines/_example/line_aware.py
@@ -67,8 +67,8 @@ class LineAwareTest(TestCase):
         
     def test_extend(self):
         #basicConfig(level=DEBUG)
-        contents = Token('[a-z]+')[:] > list
-        parens = Token('\(') & contents & Token('\)') > list
+        contents = Token(r'[a-z]+')[:] > list
+        parens = Token(r'\(') & contents & Token(r'\)') > list
         line = Line(contents & Optional(Extend(parens)))
         lines = line[:]
         lines.config.lines()
@@ -80,8 +80,8 @@ class LineAwareTest(TestCase):
         This returned None.
         '''
         #basicConfig(level=DEBUG)
-        contents = Token('[a-z]+')[:] > list
-        parens = Token('\(') & contents & Token('\)') > list
+        contents = Token(r'[a-z]+')[:] > list
+        parens = Token(r'\(') & contents & Token(r'\)') > list
         line = Line(contents & Optional(Extend(parens)))
         lines = line[:]
         lines.config.lines().record_deepest()
diff --git a/src/lepl/matchers/derived.py b/src/lepl/matchers/derived.py
index ba568c0..7d0c7a2 100644
--- a/src/lepl/matchers/derived.py
+++ b/src/lepl/matchers/derived.py
@@ -219,7 +219,7 @@ def args(function):
 
 
 def KApply(matcher, function, raw=False):
-    '''
+    r'''
     Apply an arbitrary function to named arguments (**\****).
     The function should typically expect and return a list.
     It can be used indirectly by placing ``**=`` to the right of the matcher.
diff --git a/src/lepl/matchers/operators.py b/src/lepl/matchers/operators.py
index f8c33a1..168de67 100644
--- a/src/lepl/matchers/operators.py
+++ b/src/lepl/matchers/operators.py
@@ -38,7 +38,7 @@ from lepl.support.context import Namespace, NamespaceMixin, Scope
 from lepl.support.lib import open_stop, fmt, basestring
 
 
-DIGITS = compile_('^(-?\d+)(.*)')
+DIGITS = compile_(r'^(-?\d+)(.*)')
 
 def RepeatWrapper(matcher, start, stop, step, separator, add, reduce):
     '''Parse `step` if it is a string.'''
@@ -682,7 +682,7 @@ class OperatorMixin(NamespaceMixin):
         return self._lookup(MAP)(self, function) 
         
     def __pow__(self, function):
-        '''
+        r'''
         **self \** function** - Process the results (\**kargs).
         
         Apply a function to keyword arguments
diff --git a/src/lepl/matchers/support.py b/src/lepl/matchers/support.py
index 724db36..44ac811 100644
--- a/src/lepl/matchers/support.py
+++ b/src/lepl/matchers/support.py
@@ -32,7 +32,7 @@ Support classes for matchers.
 '''
 
 from abc import ABCMeta
-from inspect import getargspec
+from inspect import getfullargspec
 
 from lepl.core.config import ParserMixin
 from lepl.core.parser import GeneratorWrapper, tagged
@@ -241,9 +241,9 @@ class BaseFactoryMatcher(FactoryMatcher):
             # factory is a dummy generated in make_factory below)
             def empty(): return
             document(empty, self.factory.factory)
-            spec = getargspec(empty)
+            spec = getfullargspec(empty)
         except:
-            spec = getargspec(self.factory)
+            spec = getfullargspec(self.factory)
         names = list(spec.args)
         defaults = dict(zip(names[::-1], spec.defaults[::-1] if spec.defaults else []))
         for name in names:
@@ -267,8 +267,8 @@ class BaseFactoryMatcher(FactoryMatcher):
                                        "{0!r} in {1}(...)", 
                                        self.__args[0], self._small_str))
         if self.__kargs:
-            if spec.keywords:
-                self.__kargs(**{spec.keywords: self.__kargs})
+            if spec.varkw:
+                self.__kargs(**{spec.varkw: self.__kargs})
             else:
                 name = list(self.__kargs.keys())[0]
                 value = self.__kargs[name]
@@ -460,7 +460,7 @@ def check_matcher(matcher):
     Check that the signature takes support + stream.
     '''
     check_args(matcher)
-    spec = getargspec(matcher)
+    spec = getfullargspec(matcher)
     if len(spec.args) != 2:
         raise TypeError(fmt(
 '''The function {0} cannot be used as a matcher because it does not have
@@ -482,7 +482,7 @@ def check_args(func):
     extensions...
     '''
     try:
-        getargspec(func)
+        getfullargspec(func)
     except Exception as e:
         raise TypeError(fmt(
 '''The function {0} uses Python 3 style parameters (keyword only, etc).
@@ -494,7 +494,7 @@ def check_modifiers(func, modifiers):
     '''
     Check that any modifiers match the function declaration.
     '''
-    argspec = getargspec(func)
+    argspec = getfullargspec(func)
     for name in modifiers:
         if name not in argspec.args:
             raise TypeError(
@@ -506,7 +506,7 @@ def apply_modifiers(func, args, kargs, modifiers, margs, mkargs):
     '''
     Modify values in args and kargs.
     '''
-    spec = getargspec(func)
+    spec = getfullargspec(func)
     names = list(spec.args)
     defaults = dict(zip(names[::-1], spec.defaults[::-1] if spec.defaults else []))
     newargs = []
@@ -537,7 +537,7 @@ def apply_modifiers(func, args, kargs, modifiers, margs, mkargs):
     elif args:
         raise TypeError(fmt("Unexpected argument {0!r} for {1}(...)", 
                                args[0], func.__name__))
-    if spec.keywords:
+    if spec.varkw:
         for name in kargs:
             newkargs[name] = mkargs(kargs[name])
     elif kargs:
diff --git a/src/lepl/regexp/str.py b/src/lepl/regexp/str.py
index 88e94d3..866b4ce 100644
--- a/src/lepl/regexp/str.py
+++ b/src/lepl/regexp/str.py
@@ -45,7 +45,7 @@ Characters that must be escaped.
 
 
 class StrParser(LogMixin):
-    '''
+    r'''
     Construct a parser for string based expressions.
     
     We need a clear policy on backslashes.  To be as backwards compatible as
diff --git a/src/lepl/stream/factory.py b/src/lepl/stream/factory.py
index af8f3e9..2eb0dee 100644
--- a/src/lepl/stream/factory.py
+++ b/src/lepl/stream/factory.py
@@ -28,7 +28,10 @@
 # MPL or the LGPL License.
 
 
-from collections import Iterable
+try:
+    from collections.abc import Iterable
+except ImportError:
+    from collections import Iterable
 
 from lepl.stream.simple import SequenceHelper, StringHelper, ListHelper
 from lepl.stream.iter import IterableHelper, Cons
diff --git a/src/lepl/support/graph.py b/src/lepl/support/graph.py
index 12ac358..e1005e2 100644
--- a/src/lepl/support/graph.py
+++ b/src/lepl/support/graph.py
@@ -59,7 +59,11 @@ on constructors described above: the walker takes a visitor sub-class and
 calls it in a way that replicates the original calls to the node constructors.
 '''
 
-from collections import Sequence, deque
+try:
+    from collections import Sequence, deque
+except ImportError:
+    from collections.abc import Sequence
+    from collections import deque
 
 from lepl.support.lib import compose, safe_in, safe_add, empty, fmt,\
     fallback_add