[Python-Dev] Re: [Python-checkins] python/dist/src/Lib warnings.py,
1.19, 1.20
Walter Dörwald
walter@livinglogic.de
Thu, 15 May 2003 12:05:22 +0200
This is a multi-part message in MIME format.
--------------020507060202080607040303
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Skip Montanaro wrote:
> [...]
> I've got to get back to some paying work, so I can't pursue this more at the
> moment. Attached are my current diffs for warnings.py and encodings/
> __init__.py if someone has a few moments to look at it.
Your normalize_encoding() doesn't preserve the "." and it doesn't
collapse consecutive non-alphanumeric characters. Furthermore it imports
the string module. How about the attached patch? Constructing the
translation string might be bad for startup time.
Bye,
Walter Dörwald
--------------020507060202080607040303
Content-Type: text/plain;
name="diff.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="diff.txt"
Index: Lib/encodings/__init__.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/encodings/__init__.py,v
retrieving revision 1.18
diff -u -r1.18 __init__.py
--- Lib/encodings/__init__.py 24 Apr 2003 16:02:49 -0000 1.18
+++ Lib/encodings/__init__.py 15 May 2003 10:00:52 -0000
@@ -32,7 +32,13 @@
_cache = {}
_unknown = '--unknown--'
_import_tail = ['*']
-_norm_encoding_RE = re.compile('[^a-zA-Z0-9.]')
+_norm_encoding_trans = []
+for i in xrange(128):
+ c = chr(i)
+ if not c.isalnum() and not c==".":
+ c = "_"
+ _norm_encoding_trans.append(c)
+_norm_encoding_trans = "".join(_norm_encoding_trans) + "_"*128
class CodecRegistryError(exceptions.LookupError,
exceptions.SystemError):
@@ -48,7 +54,7 @@
becomes '_'.
"""
- return '_'.join(_norm_encoding_RE.split(encoding))
+ return '_'.join(filter(None, encoding.translate(_norm_encoding_trans).split("_")))
def search_function(encoding):
--------------020507060202080607040303--