diff options
author | Marc-André Lemburg <mal@egenix.com> | 2001-01-17 17:09:53 (GMT) |
---|---|---|
committer | Marc-André Lemburg <mal@egenix.com> | 2001-01-17 17:09:53 (GMT) |
commit | ad7c98e264bbc9c84e911417c8770f6e95ffb794 (patch) | |
tree | 7586edae78b019c6c2db46861da762083e0c3c8a /Python | |
parent | d5c43065d5aa7bd8b9ec67525bd01d2c09a7759f (diff) | |
download | cpython-ad7c98e264bbc9c84e911417c8770f6e95ffb794.zip cpython-ad7c98e264bbc9c84e911417c8770f6e95ffb794.tar.gz cpython-ad7c98e264bbc9c84e911417c8770f6e95ffb794.tar.bz2 |
This patch adds a new builtin unistr() which behaves like str()
except that it always returns Unicode objects.
A new C API PyObject_Unicode() is also provided.
This closes patch #101664.
Written by Marc-Andre Lemburg. Copyright assigned to Guido van Rossum.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 683eec0..3acd0e2 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1928,6 +1928,23 @@ If the argument is a string, the return value is the same object."; static PyObject * +builtin_unistr(PyObject *self, PyObject *args) +{ + PyObject *v; + + if (!PyArg_ParseTuple(args, "O:unistr", &v)) + return NULL; + return PyObject_Unicode(v); +} + +static char unistr_doc[] = +"unistr(object) -> unicode\n\ +\n\ +Return a nice unicode representation of the object.\n\ +If the argument is a unicode, the return value is the same object."; + + +static PyObject * builtin_tuple(PyObject *self, PyObject *args) { PyObject *v; @@ -2242,6 +2259,7 @@ static PyMethodDef builtin_methods[] = { {"type", builtin_type, 1, type_doc}, {"unicode", builtin_unicode, 1, unicode_doc}, {"unichr", builtin_unichr, 1, unichr_doc}, + {"unistr", builtin_unistr, 1, unistr_doc}, {"vars", builtin_vars, 1, vars_doc}, {"xrange", builtin_xrange, 1, xrange_doc}, {"zip", builtin_zip, 1, zip_doc}, |