[I18n-sig] codec questions

M.-A. Lemburg mal@lemburg.com
Mon, 01 May 2000 12:05:57 +0200


This is a multi-part message in MIME format.
--------------CDA78F736CA89810F3040FD5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Tom Emerson wrote:
> 
> I'm using 1.6a2 and the following doesn't run. I must be doing
> something brain-dead here (I'm jet lagged right now):
> 
> --
> import codecs;
> 
> foo = codecs.open('Sc-orig.utf', 'rb', 'utf-8')
> 
> line = foo.readline()
> while (line != ""):
>     print line
>     line = foo.readline()
> foo.close()
> --
> 
> When I attempt to run that, in the directory containing 'Sc-orig.utf',
> I get:
> 
> (0) tree% python process.py
> Traceback (most recent call last):
>   File "process.py", line 5, in ?
>     line = foo.readline()
>   File "/opt/tree/lib/python1.6/codecs.py", line 318, in readline
>     return self.reader.readline(size)
> NameError: self

You've hit a bug... the self argument was missing from the
readline() methods. I've appended a patch and will also send
it to the patches list.

> Any ideas? I'm trying to grok the architecture so I can add
> transcoding support for TIS-620 (Thai, an 8-bit encoding which should
> work fine with the mapping codecs), GB2312 (multibyte, simplified
> Chinese), and Big-5 (multibyte, traditional Chinese). But I can't even
> get the simplest code to work, so I need someone to hit me with a
> stick.
> 
> Also, are transcoding tables loaded as needed? Or all at once? What
> are the plans for managing transcoding tables?

Depends on how you implement them. The codecs included in
the standard Python distribution are loaded on demand
together with their translation tables.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/
--------------CDA78F736CA89810F3040FD5
Content-Type: text/plain; charset=us-ascii;
 name="Unicode-Implementation-2000-05-01.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="Unicode-Implementation-2000-05-01.patch"

diff -u -rP -x *.o -x *.pyc -x Makefile -x *~ -x *.so -x add2lib -x pgen -x buildno -x config.* -x libpython* -x python -x Setup -x Setup.local -x Setup.thread -x hassignal -x Makefile.pre -x configure -x *.bak -x *.s -x DEADJOE -x *.rej -x *.orig -x Demo -x CVS -x Doc -x *.orig -x .#* -x distutils -x PC -x PCbuild -x *.c -x *.h -x *.in -x output CVS-Python/Lib/codecs.py Python+Unicode/Lib/codecs.py
--- CVS-Python/Lib/codecs.py	Thu Apr 13 18:10:57 2000
+++ Python+Unicode/Lib/codecs.py	Mon May  1 11:54:03 2000
@@ -324,11 +324,11 @@
 
         return self.reader.read(size)
 
-    def readline(size=None):
+    def readline(self, size=None):
 
         return self.reader.readline(size)
 
-    def readlines(sizehint=None):
+    def readlines(self, sizehint=None):
 
         return self.reader.readlines(sizehint)
 
Only in CVS-Python/Lib/test: test_winsound.py

--------------CDA78F736CA89810F3040FD5--