[KoCo-CVS] [Commit] iconvcodec _iconv_codec.c _iconv_codec_compat.h iconv_codec.py
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-04-20 20:45:40
|
perky 03/04/20 13:45:34 Modified: . _iconv_codec.c _iconv_codec_compat.h iconv_codec.py Log: Get python2.1 compatibility Revision Changes Path 1.3 +106 -6 iconvcodec/_iconv_codec.c Index: _iconv_codec.c =================================================================== RCS file: /cvsroot/koco/iconvcodec/_iconv_codec.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- _iconv_codec.c 20 Apr 2003 19:45:18 -0000 1.2 +++ _iconv_codec.c 20 Apr 2003 20:45:34 -0000 1.3 @@ -24,7 +24,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: _iconv_codec.c,v 1.2 2003/04/20 19:45:18 perky Exp $ + * $Id: _iconv_codec.c,v 1.3 2003/04/20 20:45:34 perky Exp $ */ #include "Python.h" @@ -71,9 +71,11 @@ UNIINTERNAL_UTF_8, } uniinternal_type_t; +#ifndef LACKS_PYSTRING_FROMFORMAT static const char *uniinternal_type_names[] = { "unusable", "UCS", "UCS(SWAPPED)", "UTF-8", }; +#endif static struct { const char *encoding; @@ -203,7 +205,7 @@ else if (strcmp(errors, "replace") == 0) return ERROR_REPLACE; else -#ifdef HAVE_ERROR_CALLBACKS +#ifndef LACKS_ERROR_CALLBACKS return PyCodec_LookupError(errors); #else return NULL; @@ -268,7 +270,7 @@ iconv_t ic, IconvEncoderBuffer *buf, PyObject *errors, int esize) { -#ifdef HAVE_ERROR_CALLBACKS +#ifndef LACKS_ERROR_CALLBACKS PyObject *retobj = NULL, *retstr = NULL; PyObject *argsobj, *tobj; int retstrsize, newpos; @@ -353,7 +355,7 @@ start = (int)(buf->inbuf - buf->inbuf_top); end = start + esize; -#ifndef HAVE_ERROR_CALLBACKS +#ifdef LACKS_ERROR_CALLBACKS if (esize == 1) PyErr_Format(PyExc_UnicodeError, "'%s' codec can't encode byte '\\u%04x' in position %d: %s", @@ -731,6 +733,14 @@ {NULL, NULL}, }; +#ifdef OLD_STYLE_TYPE +static PyObject * +iconvencoder_getattr(PyObject *self, char *name) +{ + return Py_FindMethod(iconvencoder_methods, self, name); +} +#endif + static void iconvencoder_dealloc(IconvEncoderObject *self) { @@ -739,6 +749,7 @@ PyObject_Del(self); } +#ifndef LACKS_PYSTRING_FROMFORMAT static PyObject * iconvencoder_repr(IconvEncoderObject *self) { @@ -746,7 +757,9 @@ "<IconvEncoder from='%s' to='%s' mode='%s'>", self->unicode_encoding, self->encoding, uniinternal_type_names[self->unitype]); + return PyString_FromString("<IconvEncoder>"); } +#endif static PyTypeObject IconvEncoder_Type = { PyObject_HEAD_INIT(NULL) @@ -757,21 +770,34 @@ /* methods */ (destructor)iconvencoder_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ +#ifdef OLD_STYLE_TYPE + iconvencoder_getattr, /*tp_getattr*/ +#else 0, /*tp_getattr*/ +#endif 0, /*tp_setattr*/ 0, /*tp_compare*/ +#ifndef LACKS_PYSTRING_FROMFORMAT (reprfunc)iconvencoder_repr, /*tp_repr*/ +#else + 0, /*tp_repr*/ +#endif 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ (ternaryfunc)iconvencoder_call, /*tp_call*/ 0, /*tp_str*/ +#ifdef OLD_STYLE_TYPE + 0, /*tp_getattro*/ +#else PyObject_GenericGetAttr, /*tp_getattro*/ +#endif 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ iconvencoder_doc, /*tp_doc*/ +#ifndef OLD_STYLE_TYPE 0, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ @@ -779,6 +805,7 @@ 0, /*tp_iter*/ 0, /*tp_iterext*/ iconvencoder_methods, /*tp_methods*/ +#endif }; static int @@ -809,7 +836,7 @@ iconv_t ic, IconvDecoderBuffer *buf, PyObject *errors, int eno, int esize) { -#ifdef HAVE_ERROR_CALLBACKS +#ifndef LACKS_ERROR_CALLBACKS PyObject *argsobj, *retuni = NULL, *retobj = NULL; int retunisize, newpos; #endif @@ -851,7 +878,7 @@ start = (int)(buf->inbuf - buf->inbuf_top); end = start + esize; -#ifndef HAVE_ERROR_CALLBACKS +#ifdef LACKS_ERROR_CALLBACKS if (esize == 1) PyErr_Format(PyExc_UnicodeError, "'%s' codec can't decode byte 0x%02x in position %d: %s", @@ -1208,6 +1235,14 @@ {NULL, NULL}, }; +#ifdef OLD_STYLE_TYPE +static PyObject * +iconvdecoder_getattr(PyObject *self, char *name) +{ + return Py_FindMethod(iconvdecoder_methods, self, name); +} +#endif + static void iconvdecoder_dealloc(IconvDecoderObject *self) { @@ -1216,6 +1251,7 @@ PyObject_Del(self); } +#ifndef LACKS_PYSTRING_FROMFORMAT static PyObject * iconvdecoder_repr(IconvDecoderObject *self) { @@ -1223,7 +1259,9 @@ "<IconvDecoder from='%s' to='%s' mode='%s'>", self->encoding, self->unicode_encoding, uniinternal_type_names[self->unitype]); + return PyString_FromString("<IconvDecoder>"); } +#endif static PyTypeObject IconvDecoder_Type = { PyObject_HEAD_INIT(NULL) @@ -1234,21 +1272,34 @@ /* methods */ (destructor)iconvdecoder_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ +#ifdef OLD_STYLE_TYPE + iconvdecoder_getattr, /*tp_getattr*/ +#else 0, /*tp_getattr*/ +#endif 0, /*tp_setattr*/ 0, /*tp_compare*/ +#ifndef LACKS_PYSTRING_FROMFORMAT (reprfunc)iconvdecoder_repr, /*tp_repr*/ +#else + 0, /*tp_repr*/ +#endif 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ (ternaryfunc)iconvdecoder_call, /*tp_call*/ 0, /*tp_str*/ +#ifdef OLD_STYLE_TYPE + 0, /*tp_getattro*/ +#else PyObject_GenericGetAttr, /*tp_getattro*/ +#endif 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ iconvdecoder_doc, /*tp_doc*/ +#ifndef OLD_STYLE_TYPE 0, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ @@ -1256,6 +1307,7 @@ 0, /*tp_iter*/ 0, /*tp_iterext*/ iconvdecoder_methods, /*tp_methods*/ +#endif }; static PyObject * @@ -1463,6 +1515,14 @@ {NULL, NULL}, }; +#ifdef OLD_STYLE_TYPE +static PyObject * +iconvstreamreader_getattr(PyObject *self, char *name) +{ + return Py_FindMethod(iconvstreamreader_methods, self, name); +} +#endif + static void iconvstreamreader_dealloc(IconvStreamReaderObject *self) { @@ -1477,6 +1537,7 @@ PyObject_Del(self); } +#ifndef LACKS_PYSTRING_FROMFORMAT static PyObject * iconvstreamreader_repr(IconvStreamReaderObject *self) { @@ -1485,6 +1546,7 @@ self->codec->encoding, self->codec->unicode_encoding, uniinternal_type_names[self->codec->unitype]); } +#endif static PyTypeObject IconvStreamReader_Type = { PyObject_HEAD_INIT(NULL) @@ -1495,20 +1557,33 @@ /* methods */ (destructor)iconvstreamreader_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ +#ifdef OLD_STYLE_TYPE + iconvstreamreader_getattr, /*tp_getattr*/ +#else 0, /*tp_getattr*/ +#endif 0, /*tp_setattr*/ 0, /*tp_compare*/ +#ifndef LACKS_PYSTRING_FROMFORMAT (reprfunc)iconvstreamreader_repr, /*tp_repr*/ +#else + 0, /*tp_repr*/ +#endif 0, /*tp_as_nuiconver*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ +#ifdef OLD_STYLE_TYPE + 0, /*tp_getattro*/ +#else PyObject_GenericGetAttr, /*tp_getattro*/ +#endif 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ +#ifndef OLD_STYLE_TYPE 0, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ @@ -1517,6 +1592,7 @@ 0, /*tp_iter*/ 0, /*tp_iterext*/ iconvstreamreader_methods, /*tp_methods*/ +#endif }; static int @@ -1638,6 +1714,14 @@ {NULL, NULL}, }; +#ifdef OLD_STYLE_TYPE +static PyObject * +iconvstreamwriter_getattr(PyObject *self, char *name) +{ + return Py_FindMethod(iconvstreamwriter_methods, self, name); +} +#endif + static void iconvstreamwriter_dealloc(IconvStreamWriterObject *self) { @@ -1652,6 +1736,7 @@ PyObject_Del(self); } +#ifndef LACKS_PYSTRING_FROMFORMAT static PyObject * iconvstreamwriter_repr(IconvStreamWriterObject *self) { @@ -1660,6 +1745,7 @@ self->codec->unicode_encoding, self->codec->encoding, uniinternal_type_names[self->codec->unitype]); } +#endif static PyTypeObject IconvStreamWriter_Type = { PyObject_HEAD_INIT(NULL) @@ -1670,20 +1756,33 @@ /* methods */ (destructor)iconvstreamwriter_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ +#ifdef OLD_STYLE_TYPE + iconvstreamwriter_getattr, /*tp_getattr*/ +#else 0, /*tp_getattr*/ +#endif 0, /*tp_setattr*/ 0, /*tp_compare*/ +#ifndef LACKS_PYSTRING_FROMFORMAT (reprfunc)iconvstreamwriter_repr, /*tp_repr*/ +#else + 0, /*tp_repr*/ +#endif 0, /*tp_as_nuiconver*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ +#ifdef OLD_STYLE_TYPE + 0, /*tp_getattro*/ +#else PyObject_GenericGetAttr, /*tp_getattro*/ +#endif 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ +#ifndef OLD_STYLE_TYPE 0, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ @@ -1692,6 +1791,7 @@ 0, /*tp_iter*/ 0, /*tp_iterext*/ iconvstreamwriter_methods, /*tp_methods*/ +#endif }; static PyObject * 1.2 +16 -7 iconvcodec/_iconv_codec_compat.h Index: _iconv_codec_compat.h =================================================================== RCS file: /cvsroot/koco/iconvcodec/_iconv_codec_compat.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- _iconv_codec_compat.h 20 Apr 2003 19:45:19 -0000 1.1 +++ _iconv_codec_compat.h 20 Apr 2003 20:45:34 -0000 1.2 @@ -24,12 +24,12 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: _iconv_codec_compat.h,v 1.1 2003/04/20 19:45:19 perky Exp $ + * $Id: _iconv_codec_compat.h,v 1.2 2003/04/20 20:45:34 perky Exp $ */ -/* Versions that doesn't support Unicode */ -#if PY_VERSION_HEX < 0x02000000 -# error "Your Python version doesn't have a unicode support" +/* We don't support 2.0 and older */ +#if PY_VERSION_HEX < 0x02010000 +# error "iconv_codec requires python 2.1 or compatible" #endif /* PyDoc_VAR: For ~ Python 2.2 */ @@ -39,9 +39,18 @@ # define PyDoc_STR(str) str #endif -/* PEP293 Codec Error Callbacks: For Python 2.3 and over */ -#if PY_VERSION_HEX >= 0x02030000 -# define HAVE_ERROR_CALLBACKS 1 +/* PEP293 Codec Error Callbacks are only for Python 2.3 and over */ +#if PY_VERSION_HEX < 0x02030000 +# define LACKS_ERROR_CALLBACKS 1 +#endif + +/* Python 2.1 doesn't have sth */ +#if PY_VERSION_HEX < 0x02020000 +# define Py_USING_UNICODE 1 +# define Py_UNICODE_SIZE 2 +# define LACKS_PYSTRING_FROMFORMAT 1 +# define OLD_STYLE_TYPE 1 +# define METH_NOARGS METH_VARARGS #endif /* 1.2 +2 -1 iconvcodec/iconv_codec.py Index: iconv_codec.py =================================================================== RCS file: /cvsroot/koco/iconvcodec/iconv_codec.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- iconv_codec.py 20 Apr 2003 18:17:57 -0000 1.1 +++ iconv_codec.py 20 Apr 2003 20:45:34 -0000 1.2 @@ -24,8 +24,9 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# $Id: iconv_codec.py,v 1.1 2003/04/20 18:17:57 perky Exp $ +# $Id: iconv_codec.py,v 1.2 2003/04/20 20:45:34 perky Exp $ +from __future__ import nested_scopes from _iconv_codec import makeencoder, makedecoder import codecs, sys |