#endif
#ifdef HAVE_WCHAR_H
+/* Work around a cosmetic bug in BSDI 4.x wchar.h; thanks to Thomas Wouters */
+# ifdef _HAVE_BSDI
+# include <time.h>
+# endif
# include "wchar.h"
#endif
);
#ifdef MS_WIN32
+
/* --- MBCS codecs for Windows -------------------------------------------- */
+
extern DL_IMPORT(PyObject*) PyUnicode_DecodeMBCS(
const char *string, /* MBCS encoded string */
int length, /* size of string */
const char *errors /* error handling */
);
-
#endif /* MS_WIN32 */
+
/* --- Methods & Slots ----------------------------------------------------
These are capable of handling Unicode objects and strings on input
def getregentry():
return (Codec.encode,Codec.decode,StreamReader,StreamWriter)
-
test_unicode
Testing Unicode comparisons... done.
+Testing Unicode contains method... done.
Testing Unicode formatting strings... done.
-Testing unicodedata module... done.
+Testing builtin codecs... done.
--- /dev/null
+test_unicodedata
+Testing unicodedata module... done.
""" Test script for the Unicode implementation.
-
Written by Marc-Andre Lemburg (mal@lemburg.com).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
assert u"%(x)s, %(ä)s" % {'x':u"abc", u'ä'.encode('utf-8'):"def"} == u'abc, def'
print 'done.'
-# Test Unicode database APIs
-try:
- import unicodedata
-except ImportError:
- pass
-else:
- print 'Testing unicodedata module...',
-
- assert unicodedata.digit(u'A',None) is None
- assert unicodedata.digit(u'9') == 9
- assert unicodedata.digit(u'\u215b',None) is None
- assert unicodedata.digit(u'\u2468') == 9
-
- assert unicodedata.numeric(u'A',None) is None
- assert unicodedata.numeric(u'9') == 9
- assert unicodedata.numeric(u'\u215b') == 0.125
- assert unicodedata.numeric(u'\u2468') == 9.0
-
- assert unicodedata.decimal(u'A',None) is None
- assert unicodedata.decimal(u'9') == 9
- assert unicodedata.decimal(u'\u215b',None) is None
- assert unicodedata.decimal(u'\u2468',None) is None
-
- assert unicodedata.category(u'\uFFFE') == 'Cn'
- assert unicodedata.category(u'a') == 'Ll'
- assert unicodedata.category(u'A') == 'Lu'
-
- assert unicodedata.bidirectional(u'\uFFFE') == ''
- assert unicodedata.bidirectional(u' ') == 'WS'
- assert unicodedata.bidirectional(u'A') == 'L'
-
- assert unicodedata.decomposition(u'\uFFFE') == ''
- assert unicodedata.decomposition(u'\u00bc') == '<fraction> 0031 2044 0034'
-
- assert unicodedata.mirrored(u'\uFFFE') == 0
- assert unicodedata.mirrored(u'a') == 0
- assert unicodedata.mirrored(u'\u2201') == 1
-
- assert unicodedata.combining(u'\uFFFE') == 0
- assert unicodedata.combining(u'a') == 0
- assert unicodedata.combining(u'\u20e1') == 230
-
- print 'done.'
-
# Test builtin codecs
print 'Testing builtin codecs...',
--- /dev/null
+""" Test script for the unicodedata module.
+
+Written by Marc-Andre Lemburg (mal@lemburg.com).
+
+(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
+
+"""#"
+from test_support import verbose
+import sys
+
+# Test Unicode database APIs
+import unicodedata
+
+print 'Testing unicodedata module...',
+
+assert unicodedata.digit(u'A',None) is None
+assert unicodedata.digit(u'9') == 9
+assert unicodedata.digit(u'\u215b',None) is None
+assert unicodedata.digit(u'\u2468') == 9
+
+assert unicodedata.numeric(u'A',None) is None
+assert unicodedata.numeric(u'9') == 9
+assert unicodedata.numeric(u'\u215b') == 0.125
+assert unicodedata.numeric(u'\u2468') == 9.0
+
+assert unicodedata.decimal(u'A',None) is None
+assert unicodedata.decimal(u'9') == 9
+assert unicodedata.decimal(u'\u215b',None) is None
+assert unicodedata.decimal(u'\u2468',None) is None
+
+assert unicodedata.category(u'\uFFFE') == 'Cn'
+assert unicodedata.category(u'a') == 'Ll'
+assert unicodedata.category(u'A') == 'Lu'
+
+assert unicodedata.bidirectional(u'\uFFFE') == ''
+assert unicodedata.bidirectional(u' ') == 'WS'
+assert unicodedata.bidirectional(u'A') == 'L'
+
+assert unicodedata.decomposition(u'\uFFFE') == ''
+assert unicodedata.decomposition(u'\u00bc') == '<fraction> 0031 2044 0034'
+
+assert unicodedata.mirrored(u'\uFFFE') == 0
+assert unicodedata.mirrored(u'a') == 0
+assert unicodedata.mirrored(u'\u2201') == 1
+
+assert unicodedata.combining(u'\uFFFE') == 0
+assert unicodedata.combining(u'a') == 0
+assert unicodedata.combining(u'\u20e1') == 230
+
+print 'done.'
On output, a buffer of the needed size is allocated and
returned through *buffer as NULL-terminated string.
The encoded may not contain embedded NULL characters.
- The caller is responsible for free()ing the allocated *buffer
- after usage.
+ The caller is responsible for calling PyMem_Free()
+ to free the allocated *buffer after usage.
"es#":
Takes three parameters: encoding (const char *),
If *buffer is NULL, a buffer of the needed size is
allocated and output copied into it. *buffer is then
- updated to point to the allocated memory area. The caller
- is responsible for free()ing *buffer after usage.
+ updated to point to the allocated memory area.
+ The caller is responsible for calling PyMem_Free()
+ to free the allocated *buffer after usage.
In both cases *buffer_len is updated to the number of
characters written (excluding the trailing NULL-byte).
return NULL;
}
str = PyString_FromStringAndSize(buffer, buffer_len);
- free(buffer);
+ PyMem_Free(buffer);
return str;
}
return NULL;
}
str = PyString_FromString(buffer);
- free(buffer);
+ PyMem_Free(buffer);
return str;
}
size);
}
+#ifdef MS_WIN32
+
+static PyObject *
+mbcs_decode(PyObject *self,
+ PyObject *args)
+{
+ const char *data;
+ int size;
+ const char *errors = NULL;
+
+ if (!PyArg_ParseTuple(args, "t#|z:mbcs_decode",
+ &data, &size, &errors))
+ return NULL;
+
+ return codec_tuple(PyUnicode_DecodeMBCS(data, size, errors),
+ size);
+}
+
+#endif /* MS_WIN32 */
+
/* --- Encoder ------------------------------------------------------------ */
static PyObject *
PyUnicode_GET_SIZE(str));
}
+#ifdef MS_WIN32
+
+static PyObject *
+mbcs_encode(PyObject *self,
+ PyObject *args)
+{
+ PyObject *str;
+ const char *errors = NULL;
+
+ if (!PyArg_ParseTuple(args, "U|z:mbcs_encode",
+ &str, &errors))
+ return NULL;
+
+ return codec_tuple(PyUnicode_EncodeMBCS(
+ PyUnicode_AS_UNICODE(str),
+ PyUnicode_GET_SIZE(str),
+ errors),
+ PyUnicode_GET_SIZE(str));
+}
+
+#endif /* MS_WIN32 */
+
/* --- Module API --------------------------------------------------------- */
static PyMethodDef _codecs_functions[] = {
{"charmap_decode", charmap_decode, 1},
{"readbuffer_encode", readbuffer_encode, 1},
{"charbuffer_encode", charbuffer_encode, 1},
+#ifdef MS_WIN32
+ {"mbcs_encode", mbcs_encode, 1},
+ {"mbcs_decode", mbcs_decode, 1},
+#endif
{NULL, NULL} /* sentinel */
};
the data copied into it; *buffer is
updated to point to the new buffer;
the caller is responsible for
- free()ing it after usage
+ PyMem_Free()ing it after usage
- if *buffer is not NULL, the data
is copied to *buffer; *buffer_len
is allocated and the data copied
into it; *buffer is updated to
point to the new buffer; the caller
- is responsible for free()ing it
+ is responsible for PyMem_Free()ing it
after usage
*/