On Wed, 2006-02-15 at 22:07 +0100, M.-A. Lemburg wrote: > Those are not pseudo-encodings, they are regular codecs. > > It's a common misunderstanding that codecs are only seen as serving > the purpose of converting between Unicode and strings. > > The codec system is deliberately designed to be general enough > to also work with many other types, e.g. it is easily possible to > write a codec that convert between the hex literal sequence you > have above to a list of ordinals:
Slightly off-topic, but one thing that's always bothered me about the current codecs implementation is that str.encode() (and friends) implicitly treats its argument as module, and imports it, even if the module doesn't live in the encodings package. That seems like a mistake to me (and a potential security problem if the import has side-effects). I don't know whether at the very least restricting the imports to the encodings package would make sense or would break things. >>> import sys >>> sys.modules['smtplib'] Traceback (most recent call last): File "<stdin>", line 1, in ? KeyError: 'smtplib' >>> ''.encode('smtplib') Traceback (most recent call last): File "<stdin>", line 1, in ? LookupError: unknown encoding: smtplib >>> sys.modules['smtplib'] <module 'smtplib' from '/usr/lib/python2.4/smtplib.pyc'> I can't see any reason for allowing any randomly importable module to act like an encoding. -Barry
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com