View | Details | Raw Unified | Return to bug 104451
Collapse All | Expand All

(-)files/patch-python25 (+307 lines)
Added Link Here
1
Index: parse/_pattern.py
2
===================================================================
3
--- parse/_pattern.py	(revision 3816)
4
+++ parse/_pattern.py	(revision 3817)
5
@@ -15,7 +15,7 @@
6
 # every time. The Song proxy might also get in the way.
7
 
8
 import os
9
-import sre
10
+import re
11
 
12
 import util
13
 
14
@@ -43,16 +43,16 @@
15
                 str(self._reverse[self.type]) +
16
                 "), lexeme=" + repr(self.lexeme) + ">")
17
 
18
-class PatternLexer(sre.Scanner):
19
+class PatternLexer(re.Scanner):
20
     def __init__(self, s):
21
         self.string = s.strip()
22
-        sre.Scanner.__init__(self,
23
+        re.Scanner.__init__(self,
24
                              [(r"([^<>|\\]|\\.)+", self.text),
25
                               (r"[<>|]", self.table),
26
                               ])
27
 
28
     def text(self, scanner, string):
29
-        return PatternLexeme(TEXT, sre.sub(r"\\(.)", r"\1", string))
30
+        return PatternLexeme(TEXT, re.sub(r"\\(.)", r"\1", string))
31
     def table(self, scanner, string):
32
         return PatternLexeme(
33
             {"|": COND, "<": OPEN, ">": CLOSE}[string], string)
34
Index: parse/_query.py
35
===================================================================
36
--- parse/_query.py	(revision 3816)
37
+++ parse/_query.py	(revision 3817)
38
@@ -10,7 +10,7 @@
39
 # but it could use some cleaning up. It builds the requisite match.*
40
 # objects as it goes, which is where the interesting stuff will happen.
41
 
42
-import sre
43
+import re
44
 
45
 import parse._match as match
46
 
47
@@ -22,10 +22,10 @@
48
 class ParseError(error): pass
49
 class LexerError(error): pass
50
 
51
-class QueryLexer(sre.Scanner):
52
+class QueryLexer(re.Scanner):
53
     def __init__(self, s):
54
         self.string = s.strip()
55
-        sre.Scanner.__init__(self,
56
+        re.Scanner.__init__(self,
57
                              [(r"/([^/\\]|\\.)*/", self.regexp),
58
                               (r'"([^"\\]|\\.)*"', self.str_to_re),
59
                               (r"'([^'\\]|\\.)*'", self.str_to_re),
60
@@ -42,7 +42,7 @@
61
         if isinstance(string, unicode): string = string.encode('utf-8')
62
         string = string[1:-1].decode('string_escape')
63
         string = string.decode('utf-8')
64
-        return QueryLexeme(RE, "^%s$" % sre.escape(string))
65
+        return QueryLexeme(RE, "^%s$" % re.escape(string))
66
 
67
     def tag(self, scanner, string):
68
         return QueryLexeme(TAG, string.strip())
69
@@ -190,24 +190,24 @@
70
     def MatchTag(self):
71
         tag = self.lookahead.lexeme
72
         self.match(TAG)
73
-        try: return sre.compile(sre.escape(tag), sre.IGNORECASE | sre.UNICODE)
74
-        except sre.error:
75
+        try: return re.compile(re.escape(tag), re.IGNORECASE | re.UNICODE)
76
+        except re.error:
77
             raise ParseError("The regular expression was invalid")
78
 
79
     def Regexp(self):
80
-        re = self.lookahead.lexeme
81
+        regex = self.lookahead.lexeme
82
         self.match(RE)
83
-        mods = sre.MULTILINE | sre.UNICODE | sre.IGNORECASE
84
+        mods = re.MULTILINE | re.UNICODE | re.IGNORECASE
85
         if self.lookahead.type == TAG:
86
             s = self.lookahead.lexeme.lower()
87
-            if "c" in s: mods &= ~sre.IGNORECASE
88
-            if "i" in s: mods |= sre.IGNORECASE
89
-            if "s" in s: mods |= sre.DOTALL
90
-            if "l" in s: mods = (mods & ~sre.UNICODE) | sre.LOCALE
91
+            if "c" in s: mods &= ~re.IGNORECASE
92
+            if "i" in s: mods |= re.IGNORECASE
93
+            if "s" in s: mods |= re.DOTALL
94
+            if "l" in s: mods = (mods & ~re.UNICODE) | re.LOCALE
95
             self.match(TAG)
96
-        try: return sre.compile(re, mods)
97
-        except sre.error:
98
-            raise ParseError("The regular expression /%s/ is invalid." % re)
99
+        try: return re.compile(regex, mods)
100
+        except re.error:
101
+            raise ParseError("The regular expression /%s/ is invalid." % regex)
102
 
103
     def match(self, *tokens):
104
         if tokens == [EOF] and self.lookahead.type == EOF:
105
@@ -227,7 +227,7 @@
106
     if not isinstance(string, unicode): string = string.decode('utf-8')
107
     if string == "": return match.Inter([])
108
     elif not set("#=").intersection(string):
109
-        parts = ["%s = /%s/" % (", ".join(star), sre.escape(p))
110
+        parts = ["%s = /%s/" % (", ".join(star), re.escape(p))
111
                  for p in string.split()]
112
         string = "&(" + ",".join(parts) + ")"
113
     return QueryParser(QueryLexer(string)).StartQuery()
114
Index: qltk/remote.py
115
===================================================================
116
--- qltk/remote.py	(revision 3816)
117
+++ qltk/remote.py	(revision 3817)
118
@@ -9,7 +9,7 @@
119
 
120
 import os
121
 import random
122
-import sre
123
+import re
124
 
125
 import gobject
126
 import gtk
127
@@ -162,7 +162,7 @@
128
         for added in library.scan([filename]): pass
129
         if window.browser.can_filter(None):
130
             window.browser.set_text(
131
-                "filename = /^%s/c" % sre.escape(filename))
132
+                "filename = /^%s/c" % re.escape(filename))
133
             window.browser.activate()
134
         else:
135
             basepath = filename + "/"
136
Index: qltk/cbes.py
137
===================================================================
138
--- qltk/cbes.py	(revision 3816)
139
+++ qltk/cbes.py	(revision 3817)
140
@@ -241,8 +241,8 @@
141
                 if not os.path.isdir(os.path.dirname(filename)):
142
                     os.makedirs(os.path.dirname(filename))
143
 
144
-            saved = file(filename + ".saved", "wU")
145
-            memory = file(filename, "wU")
146
+            saved = file(filename + ".saved", "w")
147
+            memory = file(filename, "w")
148
             target = saved
149
             for row in self.get_model():
150
                 if row[0] is None: target = memory
151
Index: qltk/renamefiles.py
152
===================================================================
153
--- qltk/renamefiles.py	(revision 3816)
154
+++ qltk/renamefiles.py	(revision 3817)
155
@@ -8,7 +8,7 @@
156
 # $Id: quodlibet-0.23.1-python25.patch,v 1.1 2006/09/25 02:05:35 tcort Exp $
157
 
158
 import os
159
-import sre
160
+import re
161
 import unicodedata
162
 
163
 import gtk
164
@@ -38,7 +38,7 @@
165
         new = u"".join(map(lambda s: (s in self.BAD and "_") or s, filename))
166
         parts = new.split(os.sep)
167
         def fix_end(string):
168
-            return sre.sub(r'[\. ]$', "_", string)
169
+            return re.sub(r'[\. ]$', "_", string)
170
         return unicode(os.sep).join(map(fix_end, parts))
171
 
172
 class StripDiacriticals(FilterCheckButton):
173
Index: qltk/tagsfrompath.py
174
===================================================================
175
--- qltk/tagsfrompath.py	(revision 3816)
176
+++ qltk/tagsfrompath.py	(revision 3817)
177
@@ -8,7 +8,7 @@
178
 # $Id: quodlibet-0.23.1-python25.patch,v 1.1 2006/09/25 02:05:35 tcort Exp $
179
 
180
 import os
181
-import sre
182
+import re
183
 
184
 import gtk
185
 
186
@@ -29,7 +29,7 @@
187
         self.slashes = len(pattern) - len(pattern.replace(os.path.sep,'')) + 1
188
         self.pattern = None
189
         # patterns look like <tagname> non regexy stuff <tagname> ...
190
-        pieces = sre.split(r'(<[A-Za-z0-9_]+>)', pattern)
191
+        pieces = re.split(r'(<[A-Za-z0-9_]+>)', pattern)
192
         override = { '<tracknumber>': r'\d\d?', '<discnumber>': r'\d\d??' }
193
         for i, piece in enumerate(pieces):
194
             if not piece: continue
195
@@ -38,7 +38,7 @@
196
                 pieces[i] = '(?P%s%s)' % (piece, override.get(piece, '.+?'))
197
                 self.headers.append(piece[1:-1].encode("ascii", "replace"))
198
             else:
199
-                pieces[i] = sre.escape(piece)
200
+                pieces[i] = re.escape(piece)
201
 
202
         # some slight magic to anchor searches "nicely"
203
         # nicely means if it starts with a <tag>, anchor with a /
204
@@ -52,7 +52,7 @@
205
                 and not pattern.endswith('<discnumber>'):
206
             pieces.append(r'(?:\.\w+)$')
207
 
208
-        self.pattern = sre.compile(''.join(pieces))
209
+        self.pattern = re.compile(''.join(pieces))
210
 
211
     def match(self, song):
212
         if isinstance(song, dict):
213
@@ -125,7 +125,7 @@
214
         if songs: pattern_text = self.combo.child.get_text().decode("utf-8")
215
         else: pattern_text = ""
216
         try: pattern = TagsFromPattern(pattern_text)
217
-        except sre.error:
218
+        except re.error:
219
             qltk.ErrorMessage(
220
                 self, _("Invalid pattern"),
221
                 _("The pattern\n\t<b>%s</b>\nis invalid. "
222
Index: util/__init__.py
223
===================================================================
224
--- util/__init__.py	(revision 3816)
225
+++ util/__init__.py	(revision 3817)
226
@@ -9,7 +9,7 @@
227
 import gettext
228
 import locale
229
 import os
230
-import sre
231
+import re
232
 import sys
233
 
234
 from const import FSCODING as fscoding, ENCODING
235
@@ -26,7 +26,13 @@
236
     t.install()
237
 
238
 def python_init():
239
-    sre.escape = re_esc
240
+    re.escape = re_esc
241
+    # Python 2.4 has sre.Scanner but not re.Scanner. Python 2.5 has
242
+    # deprecated sre and moved Scanner to re.
243
+    try: re.Scanner
244
+    except AttributeError:
245
+        from sre import Scanner
246
+        re.Scanner = Scanner
247
 
248
 def re_esc(str, BAD="/.^$*+?{,\\[]|()<>#=!:"):
249
     needs_escape = lambda c: (c in BAD and "\\" + c) or c
250
@@ -237,7 +243,7 @@
251
     """Unescape a string in a manner suitable for XML/Pango."""
252
     return str.replace("&lt;", "<").replace("&gt;", ">").replace("&amp;", "&")
253
 
254
-def parse_time(timestr, err=(ValueError, sre.error)):
255
+def parse_time(timestr, err=(ValueError, re.error)):
256
     """Parse a time string in hh:mm:ss, mm:ss, or ss format."""
257
     if timestr[0:1] == "-":
258
         m = -1
259
@@ -246,7 +252,7 @@
260
 
261
     try:
262
         return m * reduce(lambda s, a: s * 60 + int(a),
263
-                          sre.split(r":|\.", timestr), 0)
264
+                          re.split(r":|\.", timestr), 0)
265
     except err: return 0
266
 
267
 RATING_PRECISION = 0.25
268
@@ -362,7 +368,7 @@
269
     if not splitters: return [s.strip()]
270
     values = s.split("\n")
271
     for spl in splitters:
272
-        spl = sre.compile(r"\b\s*%s\s*\b" % sre.escape(spl), sre.UNICODE)
273
+        spl = re.compile(r"\b\s*%s\s*\b" % re.escape(spl), re.UNICODE)
274
         new_values = []
275
         for v in values:
276
             new_values.extend([st.strip() for st in spl.split(v)])
277
Index: util/massagers.py
278
===================================================================
279
--- util/massagers.py	(revision 3816)
280
+++ util/massagers.py	(revision 3817)
281
@@ -8,7 +8,7 @@
282
 # $Id: quodlibet-0.23.1-python25.patch,v 1.1 2006/09/25 02:05:35 tcort Exp $
283
 
284
 import locale
285
-import sre
286
+import re
287
 
288
 class Massager(object):
289
     """Massage a tag value from various 'okay' formats to the
290
@@ -23,7 +23,7 @@
291
     tags = ["date"]
292
     error = _("The date must be entered in 'YYYY', 'YYYY-MM-DD' or "
293
               "'YYYY-MM-DD HH:MM:SS' format.")
294
-    __match = sre.compile(r"^\d{4}([-.]\d{2}([-.]\d{2}([T ]\d{2}"
295
+    __match = re.compile(r"^\d{4}([-.]\d{2}([-.]\d{2}([T ]\d{2}"
296
                           "([:.]\d{2}([:.]\d{2})?)?)?)?)?$").match
297
     def validate(self, value):
298
         value = value.strip().replace(".", "-").replace("/", "-")
299
@@ -32,7 +32,7 @@
300
 class GainMassager(Massager):
301
     tags = ["replaygain_album_gain", "replaygain_track_gain"]
302
     error = _("Replay Gain gains must be entered in 'x.yy dB' format.")
303
-    __match = sre.compile(r"^[+-]\d+\.?\d+?\s+dB$").match
304
+    __match = re.compile(r"^[+-]\d+\.?\d+?\s+dB$").match
305
 
306
     def validate(self, value):
307
         if self.__match(value): return value

Return to bug 104451