Commit 7fb697b5 authored by Martin v. Löwis's avatar Martin v. Löwis

Revert Patch #670715: iconv support.

parent 1e469c56
......@@ -121,8 +121,3 @@ def search_function(encoding):
# Register the search_function in the Python codec registry
codecs.register(search_function)
# Register iconv_codec lookup function if available
try:
import iconv_codec
except (ImportError, RuntimeError):
pass
""" Python 'iconv' Codec
Written by Hye-Shik Chang (perky@FreeBSD.org).
Copyright(c) Python Software Foundation, All Rights Reserved. NO WARRANTY.
"""
import _iconv_codec
import codecs
def lookup(enc):
class IconvCodec(_iconv_codec.iconvcodec, codecs.Codec):
encoding = enc
try:
c = IconvCodec()
class IconvStreamReader(IconvCodec, codecs.StreamReader):
__init__ = codecs.StreamReader.__init__
class IconvStreamWriter(IconvCodec, codecs.StreamWriter):
__init__ = codecs.StreamWriter.__init__
return (
c.encode, c.decode,
IconvStreamReader, IconvStreamWriter
)
except ValueError:
return None
codecs.register(lookup)
# ex: ts=8 sts=4 et
......@@ -569,7 +569,6 @@ _expectations = {
test_gdbm
test_gl
test_grp
test_iconv_codecs
test_imgfile
test_ioctl
test_largefile
......@@ -626,7 +625,6 @@ _expectations = {
test_fork1
test_gl
test_grp
test_iconv_codecs
test_ioctl
test_imgfile
test_largefile
......@@ -774,7 +772,6 @@ _expectations = {
test_email_codecs
test_gdbm
test_gl
test_iconv_codecs
test_imgfile
test_largefile
test_linuxaudiodev
......@@ -890,7 +887,6 @@ _expectations = {
test_dl
test_email_codecs
test_gl
test_iconv_codecs
test_imgfile
test_largefile
test_linuxaudiodev
......
from test import test_support
import unittest, sys
import codecs, _iconv_codec
from encodings import iconv_codec
from StringIO import StringIO
class IconvCodecTest(unittest.TestCase):
if sys.byteorder == 'big':
spam = '\x00s\x00p\x00a\x00m' * 2
else:
spam = 's\x00p\x00a\x00m\x00' * 2
def test_sane(self):
# FIXME: Commented out, because it's not clear whether
# the internal encoding choosen requires byte swapping
# for this iconv() implementation.
if False:
self.encoder, self.decoder, self.reader, self.writer = \
codecs.lookup(_iconv_codec.internal_encoding)
self.assertEqual(self.decoder(self.spam), (u'spamspam', 16))
self.assertEqual(self.encoder(u'spamspam'), (self.spam, 8))
self.assertEqual(self.reader(StringIO(self.spam)).read(), u'spamspam')
f = StringIO()
self.writer(f).write(u'spamspam')
self.assertEqual(f.getvalue(), self.spam)
def test_basic_errors(self):
self.encoder, self.decoder, self.reader, self.writer = \
iconv_codec.lookup("ascii")
def testencerror(errors):
return self.encoder(u'sp\ufffdam', errors)
def testdecerror(errors):
return self.decoder('sp\xffam', errors)
self.assertRaises(UnicodeEncodeError, testencerror, 'strict')
self.assertRaises(UnicodeDecodeError, testdecerror, 'strict')
self.assertEqual(testencerror('replace'), ('sp?am', 5))
self.assertEqual(testdecerror('replace'), (u'sp\ufffdam', 5))
self.assertEqual(testencerror('ignore'), ('spam', 5))
self.assertEqual(testdecerror('ignore'), (u'spam', 5))
def test_pep293_errors(self):
self.encoder, self.decoder, self.reader, self.writer = \
iconv_codec.lookup("ascii")
def testencerror(errors):
return self.encoder(u'sp\ufffdam', errors)
def testdecerror(errors):
return self.decoder('sp\xffam', errors)
self.assertEqual(testencerror('xmlcharrefreplace'),
('sp�am', 5))
self.assertEqual(testencerror('backslashreplace'),
('sp\\ufffdam', 5))
def error_bomb(exc):
return (u'*'*40, len(exc.object))
def error_mock(exc):
error_mock.lastexc = exc
return (unicode(exc.object[exc.start - 1]), exc.end)
codecs.register_error('test_iconv_codec.bomb', error_bomb)
codecs.register_error('test_iconv_codec.mock', error_mock)
self.assertEqual(testencerror('test_iconv_codec.bomb'),
('sp' + ('*'*40), 5))
self.assertEqual(testdecerror('test_iconv_codec.bomb'),
(u'sp' + (u'*'*40), 5))
self.assertEqual(testencerror('test_iconv_codec.mock'), ('sppam', 5))
exc = error_mock.lastexc
self.assertEqual(exc.object, u'sp\ufffdam')
self.assertEqual(exc.start, 2)
self.assertEqual(exc.end, 3)
self.assert_(isinstance(exc, UnicodeEncodeError))
self.assertEqual(testdecerror('test_iconv_codec.mock'), (u'sppam', 5))
exc = error_mock.lastexc
self.assertEqual(exc.object, 'sp\xffam')
self.assertEqual(exc.start, 2)
self.assertEqual(exc.end, 3)
self.assert_(isinstance(exc, UnicodeDecodeError))
def test_empty_escape_decode(self):
self.encoder, self.decoder, self.reader, self.writer = \
iconv_codec.lookup("ascii")
self.assertEquals(self.decoder(u""), ("", 0))
self.assertEquals(self.encoder(""), (u"", 0))
def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(IconvCodecTest))
test_support.run_suite(suite)
if __name__ == "__main__":
test_main()
# ex: ts=8 sts=4 et
......@@ -41,6 +41,8 @@ Core and builtins
Extension modules
-----------------
- The iconv module has been removed from this release.
- The platform-independent routines for packing floats in IEEE formats
(struct.pack's <f, >f, <d, and >d codes; pickle and cPickle's protocol 1
pickling of floats) ignored that rounding can cause a carry to
......@@ -105,8 +107,6 @@ TBD
Build
-----
- Fix build problems when _iconv_codec failed. (SF bug #690012.)
- Fix problem building on OSF1 because the compiler only accepted
preprocessor directives that start in column 1. (SF bug #691793.)
......@@ -276,9 +276,6 @@ Extension modules
- The SSL module now handles sockets with a timeout set correctly (SF
patch #675750, fixing SF bug #675552).
- A new module _iconv_codec has been added, to expose the iconv(3)
library.
- os/posixmodule has grown the sysexits.h constants (EX_OK and friends).
- Fixed broken threadstate swap in readline that could cause fatal
......
......@@ -478,10 +478,6 @@ GLHACK=-Dclear=__GLclear
#EXPAT_DIR=/usr/local/src/expat-1.95.2
#pyexpat pyexpat.c -DHAVE_EXPAT_H -I$(EXPAT_DIR)/lib -L$(EXPAT_DIR) -lexpat
# Wrapper for iconv(3). This requires either GNU iconv, or a native
# iconv implementation (only Linux, Solaris, and BSD are known to work)
#_iconv_codec _iconv_codec -I$(prefix)/include -L$(exec_prefix)/lib -liconv
# Example -- included for reference only:
# xx xxmodule.c
......
This diff is collapsed.
......@@ -622,24 +622,6 @@ class PyBuildExt(build_ext):
exts.append( Extension('nis', ['nismodule.c'],
libraries = libs) )
# Hye-Shik Chang's iconv_codec C interface
iconv_incs = find_file('iconv.h', inc_dirs,
['/usr/local/include', '/usr/pkg/include'])
iconv_libs = find_library_file(self.compiler, 'iconv', lib_dirs,
['/usr/local/lib', '/usr/pkg/lib'])
if platform not in ['darwin'] and iconv_incs is not None:
if iconv_libs is not None:
iconv_libraries = ['iconv']
else:
iconv_libraries = [] # in libc
exts.append( Extension('_iconv_codec',
['_iconv_codec.c'],
include_dirs = iconv_incs,
library_dirs = iconv_libs,
libraries = iconv_libraries), )
# Curses support, requring the System V version of curses, often
# provided by the ncurses library.
if platform == 'sunos4':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment