~pythonregexp2.7/python/issue2636-01

« back to all changes in this revision

Viewing changes to Objects/unicodeobject.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-06-09 14:37:21 UTC
  • mfrom: (39022.1.14 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080609143721-bj0g1mwta28038da
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#define PY_SSIZE_T_CLEAN
43
43
#include "Python.h"
44
44
 
45
 
#include "formatter_unicode.h"
46
 
 
47
45
#include "unicodeobject.h"
48
46
#include "ucnhash.h"
49
47
 
1084
1082
            s = PyString_AS_STRING(obj);
1085
1083
            len = PyString_GET_SIZE(obj);
1086
1084
    }
1087
 
    else if (PyBytes_Check(obj)) {
 
1085
    else if (PyByteArray_Check(obj)) {
1088
1086
        /* Python 2.x specific */
1089
1087
        PyErr_Format(PyExc_TypeError,
1090
1088
                     "decoding bytearray is not supported");
7318
7316
}
7319
7317
 
7320
7318
PyDoc_STRVAR(replace__doc__,
7321
 
"S.replace (old, new[, maxsplit]) -> unicode\n\
 
7319
"S.replace (old, new[, count]) -> unicode\n\
7322
7320
\n\
7323
7321
Return a copy of S with all occurrences of substring\n\
7324
 
old replaced by new.  If the optional argument maxsplit is\n\
7325
 
given, only the first maxsplit occurrences are replaced.");
 
7322
old replaced by new.  If the optional argument count is\n\
 
7323
given, only the first count occurrences are replaced.");
7326
7324
 
7327
7325
static PyObject*
7328
7326
unicode_replace(PyUnicodeObject *self, PyObject *args)
7863
7861
\n\
7864
7862
");
7865
7863
 
 
7864
static PyObject *
 
7865
unicode__format__(PyObject *self, PyObject *args)
 
7866
{
 
7867
    PyObject *format_spec;
 
7868
    PyObject *result = NULL;
 
7869
    PyObject *tmp = NULL;
 
7870
 
 
7871
    /* If 2.x, convert format_spec to the same type as value */
 
7872
    /* This is to allow things like u''.format('') */
 
7873
    if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
 
7874
        goto done;
 
7875
    if (!(PyBytes_Check(format_spec) || PyUnicode_Check(format_spec))) {
 
7876
        PyErr_Format(PyExc_TypeError, "__format__ arg must be str "
 
7877
                     "or unicode, not %s", Py_TYPE(format_spec)->tp_name);
 
7878
        goto done;
 
7879
    }
 
7880
    tmp = PyObject_Unicode(format_spec);
 
7881
    if (tmp == NULL)
 
7882
        goto done;
 
7883
    format_spec = tmp;
 
7884
 
 
7885
    result = _PyUnicode_FormatAdvanced(self,
 
7886
                                       PyUnicode_AS_UNICODE(format_spec),
 
7887
                                       PyUnicode_GET_SIZE(format_spec));
 
7888
done:
 
7889
    Py_XDECREF(tmp);
 
7890
    return result;
 
7891
}
 
7892
 
7866
7893
PyDoc_STRVAR(p_format__doc__,
7867
7894
"S.__format__(format_spec) -> unicode\n\
7868
7895
\n\