\end{tableiii}
\end{ctypedesc}
+The \var{ml_meth} is a C function pointer. The functions may be of
+different types, but they always return \ctype{PyObject*}. If the
+function is not of the \ctype{PyCFunction}, the compiler will require
+a cast in the method table. Even though \ctype{PyCFunction} defines
+the first parameter as \ctype{PyObject*}, it is common that the method
+implementation uses a the specific C type of the \var{self} object.
+
+The flags can have the following values. Only METH_VARARGS and
+METH_KEYWORDS can be combined; the others can't.
+
+\begin{datadesc}{METH_VARARGS}
+
+This is the typical calling convention, where the methods have the
+type \ctype{PyMethodDef}. The function expects two \ctype{PyObject*}.
+The first one is the \var{self} object for methods; for module
+functions, it has the value given to \cfunction{PyInitModule4} (or
+\NULL{} if \cfunction{PyInitModule} was used). The second parameter
+(often called \var{args}) is a tuple object representing all
+arguments. This parameter is typically processed using
+\cfunction{PyArg_ParseTuple}.
+
+\end{datadesc}
+
+\begin{datadesc}{METH_KEYWORDS}
+
+Methods with these flags must be of type
+\ctype{PyCFunctionWithKeywords}. The function expects three
+parameters: \var{self}, \var{args}, and a dictionary of all the keyword
+arguments. The flag is typically combined with METH_VARARGS, and the
+parameters are typically processed using
+\cfunction{PyArg_ParseTupleAndKeywords}.
+
+\end{datadesc}
+
+\begin{datadesc}{METH_NOARGS}
+
+Methods without parameters don't need to check whether arguments are
+given if they are listed with the \code{METH_NOARGS} flag. They need
+to be of type \ctype{PyNoArgsFunction}, i.e. they expect a single
+\var{self} parameter.
+
+\end{datadesc}
+
+\begin{datadesc}{METH_O}
+
+Methods with a single object argument can be listed with the
+\code{METH_O} flag, instead of invoking \cfunction{PyArg_ParseTuple}
+with a \code{``O''} argument. They have the type \ctype{PyCFunction},
+with the \var{self} parameter, and a \ctype{PyObject*} parameter
+representing the single argument.
+
+\end{datadesc}
+
+\begin{datadesc}{METH_OLDARGS}
+
+This calling convention is deprecated. The method must be of type
+\ctype{PyCFunction}. The second argument is \NULL{} if no arguments
+are given, a single object if exactly one argument is given, and a
+tuple of objects if more than one argument is given.
+
+\end{datadesc}
+
\begin{cfuncdesc}{PyObject*}{Py_FindMethod}{PyMethodDef[] table,
PyObject *ob, char *name}
Return a bound method object for an extension type implemented in C.
(These warnings currently don't conform to the warnings framework of
PEP 230; we intend to fix this in 2.2a2.)
+- Two new flags METH_NOARGS and METH_O are available in method definition
+ tables to simplify implementation of methods with no arguments and a
+ single untyped argument. Calling such methods is more efficient than
+ calling corresponding METH_VARARGS methods. METH_OLDARGS is now
+ deprecated.
+
- The UTF-16 codec was modified to be more RFC compliant. It will now
only remove BOM characters at the start of the string and then
only if running in native mode (UTF-16-LE and -BE won't remove a
}
static PyObject *
-complex_conjugate(PyObject *self, PyObject *args)
+complex_conjugate(PyObject *self)
{
Py_complex c;
- if (!PyArg_ParseTuple(args, ":conjugate"))
- return NULL;
c = ((PyComplexObject *)self)->cval;
c.imag = -c.imag;
return PyComplex_FromCComplex(c);
}
static PyMethodDef complex_methods[] = {
- {"conjugate", complex_conjugate, 1},
+ {"conjugate", (PyCFunction)complex_conjugate, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
};
static PyObject *
-proxy_has_key(proxyobject *pp, PyObject *args)
+proxy_has_key(proxyobject *pp, PyObject *key)
{
- PyObject *key;
-
- if (!PyArg_ParseTuple(args, "O:has_key", &key))
- return NULL;
return PyInt_FromLong(PySequence_Contains(pp->dict, key));
}
}
static PyObject *
-proxy_keys(proxyobject *pp, PyObject *args)
+proxy_keys(proxyobject *pp)
{
- if (!PyArg_ParseTuple(args, ":keys"))
- return NULL;
return PyMapping_Keys(pp->dict);
}
static PyObject *
-proxy_values(proxyobject *pp, PyObject *args)
+proxy_values(proxyobject *pp)
{
- if (!PyArg_ParseTuple(args, ":values"))
- return NULL;
return PyMapping_Values(pp->dict);
}
static PyObject *
-proxy_items(proxyobject *pp, PyObject *args)
+proxy_items(proxyobject *pp)
{
- if (!PyArg_ParseTuple(args, ":items"))
- return NULL;
return PyMapping_Items(pp->dict);
}
static PyObject *
-proxy_copy(proxyobject *pp, PyObject *args)
+proxy_copy(proxyobject *pp)
{
- if (!PyArg_ParseTuple(args, ":copy"))
- return NULL;
return PyObject_CallMethod(pp->dict, "copy", NULL);
}
static PyMethodDef proxy_methods[] = {
- {"has_key", (PyCFunction)proxy_has_key, METH_VARARGS, "XXX"},
+ {"has_key", (PyCFunction)proxy_has_key, METH_O, "XXX"},
{"get", (PyCFunction)proxy_get, METH_VARARGS, "XXX"},
- {"keys", (PyCFunction)proxy_keys, METH_VARARGS, "XXX"},
- {"values", (PyCFunction)proxy_values, METH_VARARGS, "XXX"},
- {"items", (PyCFunction)proxy_items, METH_VARARGS, "XXX"},
- {"copy", (PyCFunction)proxy_copy, METH_VARARGS, "XXX"},
+ {"keys", (PyCFunction)proxy_keys, METH_NOARGS, "XXX"},
+ {"values", (PyCFunction)proxy_values, METH_NOARGS, "XXX"},
+ {"items", (PyCFunction)proxy_items, METH_NOARGS, "XXX"},
+ {"copy", (PyCFunction)proxy_copy, METH_NOARGS, "XXX"},
{0}
};
};
static PyObject *
-dict_keys(register dictobject *mp, PyObject *args)
+dict_keys(register dictobject *mp)
{
register PyObject *v;
register int i, j, n;
- if (!PyArg_NoArgs(args))
- return NULL;
again:
n = mp->ma_used;
v = PyList_New(n);
}
static PyObject *
-dict_values(register dictobject *mp, PyObject *args)
+dict_values(register dictobject *mp)
{
register PyObject *v;
register int i, j, n;
- if (!PyArg_NoArgs(args))
- return NULL;
again:
n = mp->ma_used;
v = PyList_New(n);
}
static PyObject *
-dict_items(register dictobject *mp, PyObject *args)
+dict_items(register dictobject *mp)
{
register PyObject *v;
register int i, j, n;
PyObject *item, *key, *value;
- if (!PyArg_NoArgs(args))
- return NULL;
/* Preallocate the list of tuples, to avoid allocations during
* the loop over the items, which could trigger GC, which
* could resize the dict. :-(
}
static PyObject *
-dict_update(PyObject *mp, PyObject *args)
+dict_update(PyObject *mp, PyObject *other)
{
- PyObject *other;
-
- if (!PyArg_ParseTuple(args, "O:update", &other))
- return NULL;
if (PyDict_Update(mp, other) < 0)
return NULL;
Py_INCREF(Py_None);
}
static PyObject *
-dict_copy(register dictobject *mp, PyObject *args)
+dict_copy(register dictobject *mp)
{
- if (!PyArg_Parse(args, ""))
- return NULL;
return PyDict_Copy((PyObject*)mp);
}
PyErr_BadInternalCall();
return NULL;
}
- return dict_keys((dictobject *)mp, (PyObject *)NULL);
+ return dict_keys((dictobject *)mp);
}
PyObject *
PyErr_BadInternalCall();
return NULL;
}
- return dict_values((dictobject *)mp, (PyObject *)NULL);
+ return dict_values((dictobject *)mp);
}
PyObject *
PyErr_BadInternalCall();
return NULL;
}
- return dict_items((dictobject *)mp, (PyObject *)NULL);
+ return dict_items((dictobject *)mp);
}
/* Subroutine which returns the smallest key in a for which b's value
}
static PyObject *
-dict_has_key(register dictobject *mp, PyObject *args)
+dict_has_key(register dictobject *mp, PyObject *key)
{
- PyObject *key;
long hash;
register long ok;
- if (!PyArg_ParseTuple(args, "O:has_key", &key))
- return NULL;
#ifdef CACHE_HASH
if (!PyString_Check(key) ||
(hash = ((PyStringObject *) key)->ob_shash) == -1)
static PyObject *
-dict_clear(register dictobject *mp, PyObject *args)
+dict_clear(register dictobject *mp)
{
- if (!PyArg_NoArgs(args))
- return NULL;
PyDict_Clear((PyObject *)mp);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
-dict_popitem(dictobject *mp, PyObject *args)
+dict_popitem(dictobject *mp)
{
int i = 0;
dictentry *ep;
PyObject *res;
- if (!PyArg_NoArgs(args))
- return NULL;
/* Allocate the result tuple before checking the size. Believe it
* or not, this allocation could trigger a garbage collection which
* could empty the dict, so if we checked the size first and that
}
static PyObject *
-dict_iterkeys(dictobject *dict, PyObject *args)
+dict_iterkeys(dictobject *dict)
{
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
return dictiter_new(dict, select_key);
}
static PyObject *
-dict_itervalues(dictobject *dict, PyObject *args)
+dict_itervalues(dictobject *dict)
{
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
return dictiter_new(dict, select_value);
}
static PyObject *
-dict_iteritems(dictobject *dict, PyObject *args)
+dict_iteritems(dictobject *dict)
{
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
return dictiter_new(dict, select_item);
}
"D.iteritems() -> an iterator over the (key, value) items of D";
static PyMethodDef mapp_methods[] = {
- {"has_key", (PyCFunction)dict_has_key, METH_VARARGS,
+ {"has_key", (PyCFunction)dict_has_key, METH_O,
has_key__doc__},
{"get", (PyCFunction)dict_get, METH_VARARGS,
get__doc__},
{"setdefault", (PyCFunction)dict_setdefault, METH_VARARGS,
setdefault_doc__},
- {"popitem", (PyCFunction)dict_popitem, METH_OLDARGS,
+ {"popitem", (PyCFunction)dict_popitem, METH_NOARGS,
popitem__doc__},
- {"keys", (PyCFunction)dict_keys, METH_OLDARGS,
+ {"keys", (PyCFunction)dict_keys, METH_NOARGS,
keys__doc__},
- {"items", (PyCFunction)dict_items, METH_OLDARGS,
+ {"items", (PyCFunction)dict_items, METH_NOARGS,
items__doc__},
- {"values", (PyCFunction)dict_values, METH_OLDARGS,
+ {"values", (PyCFunction)dict_values, METH_NOARGS,
values__doc__},
- {"update", (PyCFunction)dict_update, METH_VARARGS,
+ {"update", (PyCFunction)dict_update, METH_O,
update__doc__},
- {"clear", (PyCFunction)dict_clear, METH_OLDARGS,
+ {"clear", (PyCFunction)dict_clear, METH_NOARGS,
clear__doc__},
- {"copy", (PyCFunction)dict_copy, METH_OLDARGS,
+ {"copy", (PyCFunction)dict_copy, METH_NOARGS,
copy__doc__},
- {"iterkeys", (PyCFunction)dict_iterkeys, METH_VARARGS,
+ {"iterkeys", (PyCFunction)dict_iterkeys, METH_NOARGS,
iterkeys__doc__},
- {"itervalues", (PyCFunction)dict_itervalues, METH_VARARGS,
+ {"itervalues", (PyCFunction)dict_itervalues, METH_NOARGS,
itervalues__doc__},
- {"iteritems", (PyCFunction)dict_iteritems, METH_VARARGS,
+ {"iteritems", (PyCFunction)dict_iteritems, METH_NOARGS,
iteritems__doc__},
{NULL, NULL} /* sentinel */
};
}
static PyObject *
-file_close(PyFileObject *f, PyObject *args)
+file_close(PyFileObject *f)
{
int sts = 0;
- if (!PyArg_NoArgs(args))
- return NULL;
if (f->f_fp != NULL) {
if (f->f_close != NULL) {
Py_BEGIN_ALLOW_THREADS
#endif /* HAVE_FTRUNCATE */
static PyObject *
-file_tell(PyFileObject *f, PyObject *args)
+file_tell(PyFileObject *f)
{
Py_off_t pos;
if (f->f_fp == NULL)
return err_closed();
- if (!PyArg_NoArgs(args))
- return NULL;
Py_BEGIN_ALLOW_THREADS
errno = 0;
pos = _portable_ftell(f->f_fp);
}
static PyObject *
-file_fileno(PyFileObject *f, PyObject *args)
+file_fileno(PyFileObject *f)
{
if (f->f_fp == NULL)
return err_closed();
- if (!PyArg_NoArgs(args))
- return NULL;
return PyInt_FromLong((long) fileno(f->f_fp));
}
static PyObject *
-file_flush(PyFileObject *f, PyObject *args)
+file_flush(PyFileObject *f)
{
int res;
if (f->f_fp == NULL)
return err_closed();
- if (!PyArg_NoArgs(args))
- return NULL;
Py_BEGIN_ALLOW_THREADS
errno = 0;
res = fflush(f->f_fp);
}
static PyObject *
-file_isatty(PyFileObject *f, PyObject *args)
+file_isatty(PyFileObject *f)
{
long res;
if (f->f_fp == NULL)
return err_closed();
- if (!PyArg_NoArgs(args))
- return NULL;
Py_BEGIN_ALLOW_THREADS
res = isatty((int)fileno(f->f_fp));
Py_END_ALLOW_THREADS
}
static PyObject *
-file_xreadlines(PyFileObject *f, PyObject *args)
+file_xreadlines(PyFileObject *f)
{
static PyObject* xreadlines_function = NULL;
- if (!PyArg_ParseTuple(args, ":xreadlines"))
- return NULL;
-
if (!xreadlines_function) {
PyObject *xreadlines_module =
PyImport_ImportModule("xreadlines");
}
static PyMethodDef file_methods[] = {
- {"readline", (PyCFunction)file_readline, 1},
- {"read", (PyCFunction)file_read, 1},
- {"write", (PyCFunction)file_write, 0},
- {"fileno", (PyCFunction)file_fileno, 0},
- {"seek", (PyCFunction)file_seek, 1},
+ {"readline", (PyCFunction)file_readline, METH_VARARGS},
+ {"read", (PyCFunction)file_read, METH_VARARGS},
+ {"write", (PyCFunction)file_write, METH_OLDARGS},
+ {"fileno", (PyCFunction)file_fileno, METH_NOARGS},
+ {"seek", (PyCFunction)file_seek, METH_VARARGS},
#ifdef HAVE_FTRUNCATE
- {"truncate", (PyCFunction)file_truncate, 1},
+ {"truncate", (PyCFunction)file_truncate, METH_VARARGS},
#endif
- {"tell", (PyCFunction)file_tell, 0},
- {"readinto", (PyCFunction)file_readinto, 0},
- {"readlines", (PyCFunction)file_readlines, 1},
- {"xreadlines", (PyCFunction)file_xreadlines, 1},
- {"writelines", (PyCFunction)file_writelines, 0},
- {"flush", (PyCFunction)file_flush, 0},
- {"close", (PyCFunction)file_close, 0},
- {"isatty", (PyCFunction)file_isatty, 0},
+ {"tell", (PyCFunction)file_tell, METH_NOARGS},
+ {"readinto", (PyCFunction)file_readinto, METH_OLDARGS},
+ {"readlines", (PyCFunction)file_readlines, METH_VARARGS},
+ {"xreadlines", (PyCFunction)file_xreadlines, METH_NOARGS},
+ {"writelines", (PyCFunction)file_writelines, METH_O},
+ {"flush", (PyCFunction)file_flush, METH_NOARGS},
+ {"close", (PyCFunction)file_close, METH_NOARGS},
+ {"isatty", (PyCFunction)file_isatty, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
}
static PyObject *
-iter_next(seqiterobject *it, PyObject *args)
+iter_next(seqiterobject *it)
{
PyObject *seq = it->it_seq;
PyObject *result = PySequence_GetItem(seq, it->it_index++);
}
static PyMethodDef iter_methods[] = {
- {"next", (PyCFunction)iter_next, METH_VARARGS,
+ {"next", (PyCFunction)iter_next, METH_NOARGS,
"it.next() -- get the next value, or raise StopIteration"},
{NULL, NULL} /* sentinel */
};
}
static PyObject *
-listappend(PyListObject *self, PyObject *args)
+listappend(PyListObject *self, PyObject *v)
{
- PyObject *v;
- if (!PyArg_ParseTuple(args, "O:append", &v))
- return NULL;
return ins(self, (int) self->ob_size, v);
}
}
static PyObject *
-listextend(PyListObject *self, PyObject *args)
+listextend(PyListObject *self, PyObject *b)
{
- PyObject *b;
-
- if (!PyArg_ParseTuple(args, "O:extend", &b))
- return NULL;
-
b = PySequence_Fast(b, "list.extend() argument must be iterable");
if (!b)
return NULL;
}
static PyObject *
-listreverse(PyListObject *self, PyObject *args)
+listreverse(PyListObject *self)
{
- if (!PyArg_ParseTuple(args, ":reverse"))
- return NULL;
_listreverse(self);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
-listindex(PyListObject *self, PyObject *args)
+listindex(PyListObject *self, PyObject *v)
{
int i;
- PyObject *v;
- if (!PyArg_ParseTuple(args, "O:index", &v))
- return NULL;
for (i = 0; i < self->ob_size; i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0)
}
static PyObject *
-listcount(PyListObject *self, PyObject *args)
+listcount(PyListObject *self, PyObject *v)
{
int count = 0;
int i;
- PyObject *v;
- if (!PyArg_ParseTuple(args, "O:count", &v))
- return NULL;
for (i = 0; i < self->ob_size; i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0)
}
static PyObject *
-listremove(PyListObject *self, PyObject *args)
+listremove(PyListObject *self, PyObject *v)
{
int i;
- PyObject *v;
- if (!PyArg_ParseTuple(args, "O:remove", &v))
- return NULL;
for (i = 0; i < self->ob_size; i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0) {
"L.sort([cmpfunc]) -- sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1";
static PyMethodDef list_methods[] = {
- {"append", (PyCFunction)listappend, METH_VARARGS, append_doc},
+ {"append", (PyCFunction)listappend, METH_O, append_doc},
{"insert", (PyCFunction)listinsert, METH_VARARGS, insert_doc},
- {"extend", (PyCFunction)listextend, METH_VARARGS, extend_doc},
+ {"extend", (PyCFunction)listextend, METH_O, extend_doc},
{"pop", (PyCFunction)listpop, METH_VARARGS, pop_doc},
- {"remove", (PyCFunction)listremove, METH_VARARGS, remove_doc},
- {"index", (PyCFunction)listindex, METH_VARARGS, index_doc},
- {"count", (PyCFunction)listcount, METH_VARARGS, count_doc},
- {"reverse", (PyCFunction)listreverse, METH_VARARGS, reverse_doc},
+ {"remove", (PyCFunction)listremove, METH_O, remove_doc},
+ {"index", (PyCFunction)listindex, METH_O, index_doc},
+ {"count", (PyCFunction)listcount, METH_O, count_doc},
+ {"reverse", (PyCFunction)listreverse, METH_NOARGS, reverse_doc},
{"sort", (PyCFunction)listsort, METH_VARARGS, sort_doc},
{NULL, NULL} /* sentinel */
};
}
static PyMethodDef immutable_list_methods[] = {
- {"append", (PyCFunction)immutable_list_op},
- {"insert", (PyCFunction)immutable_list_op},
- {"remove", (PyCFunction)immutable_list_op},
- {"index", (PyCFunction)listindex},
- {"count", (PyCFunction)listcount},
- {"reverse", (PyCFunction)immutable_list_op},
- {"sort", (PyCFunction)immutable_list_op},
+ {"append", (PyCFunction)immutable_list_op, METH_VARARGS},
+ {"insert", (PyCFunction)immutable_list_op, METH_VARARGS},
+ {"remove", (PyCFunction)immutable_list_op, METH_VARARGS},
+ {"index", (PyCFunction)listindex, METH_O},
+ {"count", (PyCFunction)listcount, METH_O},
+ {"reverse", (PyCFunction)immutable_list_op, METH_VARARGS},
+ {"sort", (PyCFunction)immutable_list_op, METH_VARARGS},
{NULL, NULL} /* sentinel */
};
PyCFunction meth = PyCFunction_GET_FUNCTION(func);
PyObject *self = PyCFunction_GET_SELF(func);
int flags = PyCFunction_GET_FLAGS(func);
+ int size = PyTuple_GET_SIZE(arg);
if (flags & METH_KEYWORDS) {
return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
f->m_ml->ml_name);
return NULL;
}
- if (flags & METH_VARARGS) {
+
+ switch (flags) {
+ case METH_VARARGS:
return (*meth)(self, arg);
- }
- if (!(flags & METH_VARARGS)) {
+ break;
+ case METH_NOARGS:
+ if (size == 0)
+ return (*meth)(self, NULL);
+ PyErr_Format(PyExc_TypeError,
+ "%.200s() takes no arguments (%d given)",
+ f->m_ml->ml_name, size);
+ return NULL;
+ break;
+ case METH_O:
+ if (size == 1)
+ return (*meth)(self, PyTuple_GET_ITEM(arg, 0));
+ PyErr_Format(PyExc_TypeError,
+ "%.200s() takes exactly one argument (%d given)",
+ f->m_ml->ml_name, size);
+ return NULL;
+ break;
+ case METH_OLDARGS:
/* the really old style */
- int size = PyTuple_GET_SIZE(arg);
if (size == 1)
arg = PyTuple_GET_ITEM(arg, 0);
else if (size == 0)
arg = NULL;
return (*meth)(self, arg);
+ default:
+ /* should never get here ??? */
+ PyErr_BadInternalCall();
+ return NULL;
}
- /* should never get here ??? */
- PyErr_BadInternalCall();
- return NULL;
}
/* Methods (the standard built-in methods, that is) */
WARN("xrange.tolist() is deprecated; use list(xrange) instead");
- if (! PyArg_ParseTuple(args, ":tolist"))
- return NULL;
-
if (self->totlen == -1)
return PyErr_NoMemory();
PyObject *result;
static PyMethodDef range_methods[] = {
- {"tolist", (PyCFunction)range_tolist, METH_VARARGS,
+ {"tolist", (PyCFunction)range_tolist, METH_NOARGS,
"tolist() -> list\n"
"Return a list object with the same values.\n"
"(This method is deprecated; use list() instead.)"},
sequence. The separator between elements is S.";
static PyObject *
-string_join(PyStringObject *self, PyObject *args)
+string_join(PyStringObject *self, PyObject *orig)
{
char *sep = PyString_AS_STRING(self);
const int seplen = PyString_GET_SIZE(self);
int seqlen = 0;
size_t sz = 0;
int i;
- PyObject *orig, *seq, *item;
-
- if (!PyArg_ParseTuple(args, "O:join", &orig))
- return NULL;
+ PyObject *seq, *item;
seq = PySequence_Fast(orig, "");
if (seq == NULL) {
PyObject *
_PyString_Join(PyObject *sep, PyObject *x)
{
- PyObject* args;
- PyObject* result = NULL;
-
assert(sep != NULL && PyString_Check(sep));
assert(x != NULL);
- args = PyTuple_New(1);
- if (args != NULL) {
- Py_INCREF(x);
- PyTuple_SET_ITEM(args, 0, x);
- result = string_join((PyStringObject *)sep, args);
- Py_DECREF(args);
- }
- return result;
+ return string_join((PyStringObject *)sep, x);
}
static long
static PyObject *
-do_strip(PyStringObject *self, PyObject *args, int striptype)
+do_strip(PyStringObject *self, int striptype)
{
char *s = PyString_AS_STRING(self);
int len = PyString_GET_SIZE(self), i, j;
- if (!PyArg_ParseTuple(args, ":strip"))
- return NULL;
-
i = 0;
if (striptype != RIGHTSTRIP) {
while (i < len && isspace(Py_CHARMASK(s[i]))) {
whitespace removed.";
static PyObject *
-string_strip(PyStringObject *self, PyObject *args)
+string_strip(PyStringObject *self)
{
- return do_strip(self, args, BOTHSTRIP);
+ return do_strip(self, BOTHSTRIP);
}
Return a copy of the string S with leading whitespace removed.";
static PyObject *
-string_lstrip(PyStringObject *self, PyObject *args)
+string_lstrip(PyStringObject *self)
{
- return do_strip(self, args, LEFTSTRIP);
+ return do_strip(self, LEFTSTRIP);
}
Return a copy of the string S with trailing whitespace removed.";
static PyObject *
-string_rstrip(PyStringObject *self, PyObject *args)
+string_rstrip(PyStringObject *self)
{
- return do_strip(self, args, RIGHTSTRIP);
+ return do_strip(self, RIGHTSTRIP);
}
Return a copy of the string S converted to lowercase.";
static PyObject *
-string_lower(PyStringObject *self, PyObject *args)
+string_lower(PyStringObject *self)
{
char *s = PyString_AS_STRING(self), *s_new;
int i, n = PyString_GET_SIZE(self);
PyObject *new;
- if (!PyArg_ParseTuple(args, ":lower"))
- return NULL;
new = PyString_FromStringAndSize(NULL, n);
if (new == NULL)
return NULL;
Return a copy of the string S converted to uppercase.";
static PyObject *
-string_upper(PyStringObject *self, PyObject *args)
+string_upper(PyStringObject *self)
{
char *s = PyString_AS_STRING(self), *s_new;
int i, n = PyString_GET_SIZE(self);
PyObject *new;
- if (!PyArg_ParseTuple(args, ":upper"))
- return NULL;
new = PyString_FromStringAndSize(NULL, n);
if (new == NULL)
return NULL;
characters, all remaining cased characters have lowercase.";
static PyObject*
-string_title(PyStringObject *self, PyObject *args)
+string_title(PyStringObject *self)
{
char *s = PyString_AS_STRING(self), *s_new;
int i, n = PyString_GET_SIZE(self);
int previous_is_cased = 0;
PyObject *new;
- if (!PyArg_ParseTuple(args, ":title"))
- return NULL;
new = PyString_FromStringAndSize(NULL, n);
if (new == NULL)
return NULL;
capitalized.";
static PyObject *
-string_capitalize(PyStringObject *self, PyObject *args)
+string_capitalize(PyStringObject *self)
{
char *s = PyString_AS_STRING(self), *s_new;
int i, n = PyString_GET_SIZE(self);
PyObject *new;
- if (!PyArg_ParseTuple(args, ":capitalize"))
- return NULL;
new = PyString_FromStringAndSize(NULL, n);
if (new == NULL)
return NULL;
converted to lowercase and vice versa.";
static PyObject *
-string_swapcase(PyStringObject *self, PyObject *args)
+string_swapcase(PyStringObject *self)
{
char *s = PyString_AS_STRING(self), *s_new;
int i, n = PyString_GET_SIZE(self);
PyObject *new;
- if (!PyArg_ParseTuple(args, ":swapcase"))
- return NULL;
new = PyString_FromStringAndSize(NULL, n);
if (new == NULL)
return NULL;
0 otherwise.";
static PyObject*
-string_isspace(PyStringObject *self, PyObject *args)
+string_isspace(PyStringObject *self)
{
register const unsigned char *p
= (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyString_GET_SIZE(self) == 1 &&
isspace(*p))
and there is at least one character in S, 0 otherwise.";
static PyObject*
-string_isalpha(PyStringObject *self, PyObject *args)
+string_isalpha(PyStringObject *self)
{
register const unsigned char *p
= (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyString_GET_SIZE(self) == 1 &&
isalpha(*p))
and there is at least one character in S, 0 otherwise.";
static PyObject*
-string_isalnum(PyStringObject *self, PyObject *args)
+string_isalnum(PyStringObject *self)
{
register const unsigned char *p
= (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyString_GET_SIZE(self) == 1 &&
isalnum(*p))
0 otherwise.";
static PyObject*
-string_isdigit(PyStringObject *self, PyObject *args)
+string_isdigit(PyStringObject *self)
{
register const unsigned char *p
= (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyString_GET_SIZE(self) == 1 &&
isdigit(*p))
at least one cased character in S, 0 otherwise.";
static PyObject*
-string_islower(PyStringObject *self, PyObject *args)
+string_islower(PyStringObject *self)
{
register const unsigned char *p
= (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
int cased;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyString_GET_SIZE(self) == 1)
return PyInt_FromLong(islower(*p) != 0);
at least one cased character in S, 0 otherwise.";
static PyObject*
-string_isupper(PyStringObject *self, PyObject *args)
+string_isupper(PyStringObject *self)
{
register const unsigned char *p
= (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
int cased;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyString_GET_SIZE(self) == 1)
return PyInt_FromLong(isupper(*p) != 0);
ones. Return 0 otherwise.";
static PyObject*
-string_istitle(PyStringObject *self, PyObject *args)
+string_istitle(PyStringObject *self, PyObject *uncased)
{
register const unsigned char *p
= (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
int cased, previous_is_cased;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyString_GET_SIZE(self) == 1)
return PyInt_FromLong(isupper(*p) != 0);
string_methods[] = {
/* Counterparts of the obsolete stropmodule functions; except
string.maketrans(). */
- {"join", (PyCFunction)string_join, 1, join__doc__},
- {"split", (PyCFunction)string_split, 1, split__doc__},
- {"lower", (PyCFunction)string_lower, 1, lower__doc__},
- {"upper", (PyCFunction)string_upper, 1, upper__doc__},
- {"islower", (PyCFunction)string_islower, 0, islower__doc__},
- {"isupper", (PyCFunction)string_isupper, 0, isupper__doc__},
- {"isspace", (PyCFunction)string_isspace, 0, isspace__doc__},
- {"isdigit", (PyCFunction)string_isdigit, 0, isdigit__doc__},
- {"istitle", (PyCFunction)string_istitle, 0, istitle__doc__},
- {"isalpha", (PyCFunction)string_isalpha, 0, isalpha__doc__},
- {"isalnum", (PyCFunction)string_isalnum, 0, isalnum__doc__},
- {"capitalize", (PyCFunction)string_capitalize, 1, capitalize__doc__},
- {"count", (PyCFunction)string_count, 1, count__doc__},
- {"endswith", (PyCFunction)string_endswith, 1, endswith__doc__},
- {"find", (PyCFunction)string_find, 1, find__doc__},
- {"index", (PyCFunction)string_index, 1, index__doc__},
- {"lstrip", (PyCFunction)string_lstrip, 1, lstrip__doc__},
- {"replace", (PyCFunction)string_replace, 1, replace__doc__},
- {"rfind", (PyCFunction)string_rfind, 1, rfind__doc__},
- {"rindex", (PyCFunction)string_rindex, 1, rindex__doc__},
- {"rstrip", (PyCFunction)string_rstrip, 1, rstrip__doc__},
- {"startswith", (PyCFunction)string_startswith, 1, startswith__doc__},
- {"strip", (PyCFunction)string_strip, 1, strip__doc__},
- {"swapcase", (PyCFunction)string_swapcase, 1, swapcase__doc__},
- {"translate", (PyCFunction)string_translate, 1, translate__doc__},
- {"title", (PyCFunction)string_title, 1, title__doc__},
- {"ljust", (PyCFunction)string_ljust, 1, ljust__doc__},
- {"rjust", (PyCFunction)string_rjust, 1, rjust__doc__},
- {"center", (PyCFunction)string_center, 1, center__doc__},
- {"encode", (PyCFunction)string_encode, 1, encode__doc__},
- {"decode", (PyCFunction)string_decode, 1, decode__doc__},
- {"expandtabs", (PyCFunction)string_expandtabs, 1, expandtabs__doc__},
- {"splitlines", (PyCFunction)string_splitlines, 1, splitlines__doc__},
+ {"join", (PyCFunction)string_join, METH_O, join__doc__},
+ {"split", (PyCFunction)string_split, METH_VARARGS, split__doc__},
+ {"lower", (PyCFunction)string_lower, METH_NOARGS, lower__doc__},
+ {"upper", (PyCFunction)string_upper, METH_NOARGS, upper__doc__},
+ {"islower", (PyCFunction)string_islower, METH_NOARGS, islower__doc__},
+ {"isupper", (PyCFunction)string_isupper, METH_NOARGS, isupper__doc__},
+ {"isspace", (PyCFunction)string_isspace, METH_NOARGS, isspace__doc__},
+ {"isdigit", (PyCFunction)string_isdigit, METH_NOARGS, isdigit__doc__},
+ {"istitle", (PyCFunction)string_istitle, METH_NOARGS, istitle__doc__},
+ {"isalpha", (PyCFunction)string_isalpha, METH_NOARGS, isalpha__doc__},
+ {"isalnum", (PyCFunction)string_isalnum, METH_NOARGS, isalnum__doc__},
+ {"capitalize", (PyCFunction)string_capitalize, METH_NOARGS, capitalize__doc__},
+ {"count", (PyCFunction)string_count, METH_VARARGS, count__doc__},
+ {"endswith", (PyCFunction)string_endswith, METH_VARARGS, endswith__doc__},
+ {"find", (PyCFunction)string_find, METH_VARARGS, find__doc__},
+ {"index", (PyCFunction)string_index, METH_VARARGS, index__doc__},
+ {"lstrip", (PyCFunction)string_lstrip, METH_NOARGS, lstrip__doc__},
+ {"replace", (PyCFunction)string_replace, METH_VARARGS, replace__doc__},
+ {"rfind", (PyCFunction)string_rfind, METH_VARARGS, rfind__doc__},
+ {"rindex", (PyCFunction)string_rindex, METH_VARARGS, rindex__doc__},
+ {"rstrip", (PyCFunction)string_rstrip, METH_NOARGS, rstrip__doc__},
+ {"startswith", (PyCFunction)string_startswith, METH_VARARGS, startswith__doc__},
+ {"strip", (PyCFunction)string_strip, METH_NOARGS, strip__doc__},
+ {"swapcase", (PyCFunction)string_swapcase, METH_NOARGS, swapcase__doc__},
+ {"translate", (PyCFunction)string_translate, METH_VARARGS, translate__doc__},
+ {"title", (PyCFunction)string_title, METH_NOARGS, title__doc__},
+ {"ljust", (PyCFunction)string_ljust, METH_VARARGS, ljust__doc__},
+ {"rjust", (PyCFunction)string_rjust, METH_VARARGS, rjust__doc__},
+ {"center", (PyCFunction)string_center, METH_VARARGS, center__doc__},
+ {"encode", (PyCFunction)string_encode, METH_VARARGS, encode__doc__},
+ {"decode", (PyCFunction)string_decode, METH_VARARGS, decode__doc__},
+ {"expandtabs", (PyCFunction)string_expandtabs, METH_VARARGS, expandtabs__doc__},
+ {"splitlines", (PyCFunction)string_splitlines, METH_VARARGS, splitlines__doc__},
#if 0
- {"zfill", (PyCFunction)string_zfill, 1, zfill__doc__},
+ {"zfill", (PyCFunction)string_zfill, METH_VARARGS, zfill__doc__},
#endif
{NULL, NULL} /* sentinel */
};
}
static PyObject *
-mro_external(PyObject *self, PyObject *args)
+mro_external(PyObject *self)
{
PyTypeObject *type = (PyTypeObject *)self;
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
return mro_implementation(type);
}
}
static PyMethodDef type_methods[] = {
- {"mro", mro_external, METH_VARARGS,
+ {"mro", (PyCFunction)mro_external, METH_NOARGS,
"mro() -> list\nreturn a type's method resolution order"},
{0}
};
characters, all remaining cased characters have lower case.";
static PyObject*
-unicode_title(PyUnicodeObject *self, PyObject *args)
+unicode_title(PyUnicodeObject *self)
{
- if (!PyArg_NoArgs(args))
- return NULL;
return fixup(self, fixtitle);
}
have upper case.";
static PyObject*
-unicode_capitalize(PyUnicodeObject *self, PyObject *args)
+unicode_capitalize(PyUnicodeObject *self)
{
- if (!PyArg_NoArgs(args))
- return NULL;
return fixup(self, fixcapitalize);
}
normalized whitespace (all whitespace strings are replaced by ' ').";
static PyObject*
-unicode_capwords(PyUnicodeObject *self, PyObject *args)
+unicode_capwords(PyUnicodeObject *self)
{
PyObject *list;
PyObject *item;
int i;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Split into words */
list = split(self, NULL, -1);
if (!list)
at least one cased character in S, 0 otherwise.";
static PyObject*
-unicode_islower(PyUnicodeObject *self, PyObject *args)
+unicode_islower(PyUnicodeObject *self)
{
register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
register const Py_UNICODE *e;
int cased;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyUnicode_GET_SIZE(self) == 1)
return PyInt_FromLong(Py_UNICODE_ISLOWER(*p) != 0);
at least one cased character in S, 0 otherwise.";
static PyObject*
-unicode_isupper(PyUnicodeObject *self, PyObject *args)
+unicode_isupper(PyUnicodeObject *self)
{
register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
register const Py_UNICODE *e;
int cased;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyUnicode_GET_SIZE(self) == 1)
return PyInt_FromLong(Py_UNICODE_ISUPPER(*p) != 0);
ones. Return 0 otherwise.";
static PyObject*
-unicode_istitle(PyUnicodeObject *self, PyObject *args)
+unicode_istitle(PyUnicodeObject *self)
{
register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
register const Py_UNICODE *e;
int cased, previous_is_cased;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyUnicode_GET_SIZE(self) == 1)
return PyInt_FromLong((Py_UNICODE_ISTITLE(*p) != 0) ||
0 otherwise.";
static PyObject*
-unicode_isspace(PyUnicodeObject *self, PyObject *args)
+unicode_isspace(PyUnicodeObject *self)
{
register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
register const Py_UNICODE *e;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyUnicode_GET_SIZE(self) == 1 &&
Py_UNICODE_ISSPACE(*p))
and there is at least one character in S, 0 otherwise.";
static PyObject*
-unicode_isalpha(PyUnicodeObject *self, PyObject *args)
+unicode_isalpha(PyUnicodeObject *self)
{
register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
register const Py_UNICODE *e;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyUnicode_GET_SIZE(self) == 1 &&
Py_UNICODE_ISALPHA(*p))
and there is at least one character in S, 0 otherwise.";
static PyObject*
-unicode_isalnum(PyUnicodeObject *self, PyObject *args)
+unicode_isalnum(PyUnicodeObject *self)
{
register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
register const Py_UNICODE *e;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyUnicode_GET_SIZE(self) == 1 &&
Py_UNICODE_ISALNUM(*p))
0 otherwise.";
static PyObject*
-unicode_isdecimal(PyUnicodeObject *self, PyObject *args)
+unicode_isdecimal(PyUnicodeObject *self)
{
register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
register const Py_UNICODE *e;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyUnicode_GET_SIZE(self) == 1 &&
Py_UNICODE_ISDECIMAL(*p))
0 otherwise.";
static PyObject*
-unicode_isdigit(PyUnicodeObject *self, PyObject *args)
+unicode_isdigit(PyUnicodeObject *self)
{
register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
register const Py_UNICODE *e;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyUnicode_GET_SIZE(self) == 1 &&
Py_UNICODE_ISDIGIT(*p))
0 otherwise.";
static PyObject*
-unicode_isnumeric(PyUnicodeObject *self, PyObject *args)
+unicode_isnumeric(PyUnicodeObject *self)
{
register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
register const Py_UNICODE *e;
- if (!PyArg_NoArgs(args))
- return NULL;
-
/* Shortcut for single character strings */
if (PyUnicode_GET_SIZE(self) == 1 &&
Py_UNICODE_ISNUMERIC(*p))
sequence. The separator between elements is S.";
static PyObject*
-unicode_join(PyUnicodeObject *self, PyObject *args)
+unicode_join(PyObject *self, PyObject *data)
{
- PyObject *data;
- if (!PyArg_ParseTuple(args, "O:join", &data))
- return NULL;
-
- return PyUnicode_Join((PyObject *)self, data);
+ return PyUnicode_Join(self, data);
}
static int
Return a copy of the string S converted to lowercase.";
static PyObject*
-unicode_lower(PyUnicodeObject *self, PyObject *args)
+unicode_lower(PyUnicodeObject *self)
{
- if (!PyArg_NoArgs(args))
- return NULL;
return fixup(self, fixlower);
}
Return a copy of the string S with leading whitespace removed.";
static PyObject *
-unicode_lstrip(PyUnicodeObject *self, PyObject *args)
+unicode_lstrip(PyUnicodeObject *self)
{
- if (!PyArg_NoArgs(args))
- return NULL;
return strip(self, 1, 0);
}
Return a copy of the string S with trailing whitespace removed.";
static PyObject *
-unicode_rstrip(PyUnicodeObject *self, PyObject *args)
+unicode_rstrip(PyUnicodeObject *self)
{
- if (!PyArg_NoArgs(args))
- return NULL;
return strip(self, 0, 1);
}
Return a copy of S with leading and trailing whitespace removed.";
static PyObject *
-unicode_strip(PyUnicodeObject *self, PyObject *args)
+unicode_strip(PyUnicodeObject *self)
{
- if (!PyArg_NoArgs(args))
- return NULL;
return strip(self, 1, 1);
}
and vice versa.";
static PyObject*
-unicode_swapcase(PyUnicodeObject *self, PyObject *args)
+unicode_swapcase(PyUnicodeObject *self)
{
- if (!PyArg_NoArgs(args))
- return NULL;
return fixup(self, fixswapcase);
}
are left untouched. Characters mapped to None are deleted.";
static PyObject*
-unicode_translate(PyUnicodeObject *self, PyObject *args)
+unicode_translate(PyUnicodeObject *self, PyObject *table)
{
- PyObject *table;
-
- if (!PyArg_ParseTuple(args, "O:translate", &table))
- return NULL;
return PyUnicode_TranslateCharmap(self->str,
self->length,
table,
Return a copy of S converted to uppercase.";
static PyObject*
-unicode_upper(PyUnicodeObject *self, PyObject *args)
+unicode_upper(PyUnicodeObject *self)
{
- if (!PyArg_NoArgs(args))
- return NULL;
return fixup(self, fixupper);
}
#if 0
static PyObject*
-unicode_freelistsize(PyUnicodeObject *self, PyObject *args)
+unicode_freelistsize(PyUnicodeObject *self)
{
- if (!PyArg_NoArgs(args))
- return NULL;
return PyInt_FromLong(unicode_freelist_size);
}
#endif
/* Order is according to common usage: often used methods should
appear first, since lookup is done sequentially. */
- {"encode", (PyCFunction) unicode_encode, 1, encode__doc__},
- {"replace", (PyCFunction) unicode_replace, 1, replace__doc__},
- {"split", (PyCFunction) unicode_split, 1, split__doc__},
- {"join", (PyCFunction) unicode_join, 1, join__doc__},
- {"capitalize", (PyCFunction) unicode_capitalize, 0, capitalize__doc__},
- {"title", (PyCFunction) unicode_title, 0, title__doc__},
- {"center", (PyCFunction) unicode_center, 1, center__doc__},
- {"count", (PyCFunction) unicode_count, 1, count__doc__},
- {"expandtabs", (PyCFunction) unicode_expandtabs, 1, expandtabs__doc__},
- {"find", (PyCFunction) unicode_find, 1, find__doc__},
- {"index", (PyCFunction) unicode_index, 1, index__doc__},
- {"ljust", (PyCFunction) unicode_ljust, 1, ljust__doc__},
- {"lower", (PyCFunction) unicode_lower, 0, lower__doc__},
- {"lstrip", (PyCFunction) unicode_lstrip, 0, lstrip__doc__},
-/* {"maketrans", (PyCFunction) unicode_maketrans, 1, maketrans__doc__}, */
- {"rfind", (PyCFunction) unicode_rfind, 1, rfind__doc__},
- {"rindex", (PyCFunction) unicode_rindex, 1, rindex__doc__},
- {"rjust", (PyCFunction) unicode_rjust, 1, rjust__doc__},
- {"rstrip", (PyCFunction) unicode_rstrip, 0, rstrip__doc__},
- {"splitlines", (PyCFunction) unicode_splitlines, 1, splitlines__doc__},
- {"strip", (PyCFunction) unicode_strip, 0, strip__doc__},
- {"swapcase", (PyCFunction) unicode_swapcase, 0, swapcase__doc__},
- {"translate", (PyCFunction) unicode_translate, 1, translate__doc__},
- {"upper", (PyCFunction) unicode_upper, 0, upper__doc__},
- {"startswith", (PyCFunction) unicode_startswith, 1, startswith__doc__},
- {"endswith", (PyCFunction) unicode_endswith, 1, endswith__doc__},
- {"islower", (PyCFunction) unicode_islower, 0, islower__doc__},
- {"isupper", (PyCFunction) unicode_isupper, 0, isupper__doc__},
- {"istitle", (PyCFunction) unicode_istitle, 0, istitle__doc__},
- {"isspace", (PyCFunction) unicode_isspace, 0, isspace__doc__},
- {"isdecimal", (PyCFunction) unicode_isdecimal, 0, isdecimal__doc__},
- {"isdigit", (PyCFunction) unicode_isdigit, 0, isdigit__doc__},
- {"isnumeric", (PyCFunction) unicode_isnumeric, 0, isnumeric__doc__},
- {"isalpha", (PyCFunction) unicode_isalpha, 0, isalpha__doc__},
- {"isalnum", (PyCFunction) unicode_isalnum, 0, isalnum__doc__},
+ {"encode", (PyCFunction) unicode_encode, METH_VARARGS, encode__doc__},
+ {"replace", (PyCFunction) unicode_replace, METH_VARARGS, replace__doc__},
+ {"split", (PyCFunction) unicode_split, METH_VARARGS, split__doc__},
+ {"join", (PyCFunction) unicode_join, METH_O, join__doc__},
+ {"capitalize", (PyCFunction) unicode_capitalize, METH_NOARGS, capitalize__doc__},
+ {"title", (PyCFunction) unicode_title, METH_NOARGS, title__doc__},
+ {"center", (PyCFunction) unicode_center, METH_VARARGS, center__doc__},
+ {"count", (PyCFunction) unicode_count, METH_VARARGS, count__doc__},
+ {"expandtabs", (PyCFunction) unicode_expandtabs, METH_VARARGS, expandtabs__doc__},
+ {"find", (PyCFunction) unicode_find, METH_VARARGS, find__doc__},
+ {"index", (PyCFunction) unicode_index, METH_VARARGS, index__doc__},
+ {"ljust", (PyCFunction) unicode_ljust, METH_VARARGS, ljust__doc__},
+ {"lower", (PyCFunction) unicode_lower, METH_NOARGS, lower__doc__},
+ {"lstrip", (PyCFunction) unicode_lstrip, METH_NOARGS, lstrip__doc__},
+/* {"maketrans", (PyCFunction) unicode_maketrans, METH_VARARGS, maketrans__doc__}, */
+ {"rfind", (PyCFunction) unicode_rfind, METH_VARARGS, rfind__doc__},
+ {"rindex", (PyCFunction) unicode_rindex, METH_VARARGS, rindex__doc__},
+ {"rjust", (PyCFunction) unicode_rjust, METH_VARARGS, rjust__doc__},
+ {"rstrip", (PyCFunction) unicode_rstrip, METH_NOARGS, rstrip__doc__},
+ {"splitlines", (PyCFunction) unicode_splitlines, METH_VARARGS, splitlines__doc__},
+ {"strip", (PyCFunction) unicode_strip, METH_NOARGS, strip__doc__},
+ {"swapcase", (PyCFunction) unicode_swapcase, METH_NOARGS, swapcase__doc__},
+ {"translate", (PyCFunction) unicode_translate, METH_O, translate__doc__},
+ {"upper", (PyCFunction) unicode_upper, METH_NOARGS, upper__doc__},
+ {"startswith", (PyCFunction) unicode_startswith, METH_VARARGS, startswith__doc__},
+ {"endswith", (PyCFunction) unicode_endswith, METH_VARARGS, endswith__doc__},
+ {"islower", (PyCFunction) unicode_islower, METH_NOARGS, islower__doc__},
+ {"isupper", (PyCFunction) unicode_isupper, METH_NOARGS, isupper__doc__},
+ {"istitle", (PyCFunction) unicode_istitle, METH_NOARGS, istitle__doc__},
+ {"isspace", (PyCFunction) unicode_isspace, METH_NOARGS, isspace__doc__},
+ {"isdecimal", (PyCFunction) unicode_isdecimal, METH_NOARGS, isdecimal__doc__},
+ {"isdigit", (PyCFunction) unicode_isdigit, METH_NOARGS, isdigit__doc__},
+ {"isnumeric", (PyCFunction) unicode_isnumeric, METH_NOARGS, isnumeric__doc__},
+ {"isalpha", (PyCFunction) unicode_isalpha, METH_NOARGS, isalpha__doc__},
+ {"isalnum", (PyCFunction) unicode_isalnum, METH_NOARGS, isalnum__doc__},
#if 0
- {"zfill", (PyCFunction) unicode_zfill, 1, zfill__doc__},
- {"capwords", (PyCFunction) unicode_capwords, 0, capwords__doc__},
+ {"zfill", (PyCFunction) unicode_zfill, METH_VARARGS, zfill__doc__},
+ {"capwords", (PyCFunction) unicode_capwords, METH_NOARGS, capwords__doc__},
#endif
#if 0
/* This one is just used for debugging the implementation. */
- {"freelistsize", (PyCFunction) unicode_freelistsize, 0},
+ {"freelistsize", (PyCFunction) unicode_freelistsize, METH_NOARGS},
#endif
{NULL, NULL}
static PyObject *
-builtin_abs(PyObject *self, PyObject *args)
+builtin_abs(PyObject *self, PyObject *v)
{
- PyObject *v;
-
- if (!PyArg_ParseTuple(args, "O:abs", &v))
- return NULL;
return PyNumber_Absolute(v);
}
static PyObject *
-builtin_callable(PyObject *self, PyObject *args)
+builtin_callable(PyObject *self, PyObject *v)
{
- PyObject *v;
-
- if (!PyArg_ParseTuple(args, "O:callable", &v))
- return NULL;
return PyInt_FromLong((long)PyCallable_Check(v));
}
static PyObject *
-builtin_globals(PyObject *self, PyObject *args)
+builtin_globals(PyObject *self)
{
PyObject *d;
- if (!PyArg_ParseTuple(args, ":globals"))
- return NULL;
d = PyEval_GetGlobals();
Py_INCREF(d);
return d;
static PyObject *
-builtin_id(PyObject *self, PyObject *args)
+builtin_id(PyObject *self, PyObject *v)
{
- PyObject *v;
-
- if (!PyArg_ParseTuple(args, "O:id", &v))
- return NULL;
return PyLong_FromVoidPtr(v);
}
static PyObject *
-builtin_hash(PyObject *self, PyObject *args)
+builtin_hash(PyObject *self, PyObject *v)
{
- PyObject *v;
long x;
- if (!PyArg_ParseTuple(args, "O:hash", &v))
- return NULL;
x = PyObject_Hash(v);
if (x == -1)
return NULL;
static PyObject *
-builtin_hex(PyObject *self, PyObject *args)
+builtin_hex(PyObject *self, PyObject *v)
{
- PyObject *v;
PyNumberMethods *nb;
- if (!PyArg_ParseTuple(args, "O:hex", &v))
- return NULL;
-
if ((nb = v->ob_type->tp_as_number) == NULL ||
nb->nb_hex == NULL) {
PyErr_SetString(PyExc_TypeError,
static PyObject *
-builtin_len(PyObject *self, PyObject *args)
+builtin_len(PyObject *self, PyObject *v)
{
- PyObject *v;
long res;
- if (!PyArg_ParseTuple(args, "O:len", &v))
- return NULL;
res = PyObject_Size(v);
if (res < 0 && PyErr_Occurred())
return NULL;
static PyObject *
-builtin_locals(PyObject *self, PyObject *args)
+builtin_locals(PyObject *self)
{
PyObject *d;
- if (!PyArg_ParseTuple(args, ":locals"))
- return NULL;
d = PyEval_GetLocals();
Py_INCREF(d);
return d;
static PyObject *
-builtin_oct(PyObject *self, PyObject *args)
+builtin_oct(PyObject *self, PyObject *v)
{
- PyObject *v;
PyNumberMethods *nb;
- if (!PyArg_ParseTuple(args, "O:oct", &v))
- return NULL;
if (v == NULL || (nb = v->ob_type->tp_as_number) == NULL ||
nb->nb_oct == NULL) {
PyErr_SetString(PyExc_TypeError,
static PyObject *
-builtin_ord(PyObject *self, PyObject *args)
+builtin_ord(PyObject *self, PyObject* obj)
{
- PyObject *obj;
long ord;
int size;
- if (!PyArg_ParseTuple(args, "O:ord", &obj))
- return NULL;
-
if (PyString_Check(obj)) {
size = PyString_GET_SIZE(obj);
if (size == 1) {
static PyObject *
-builtin_reload(PyObject *self, PyObject *args)
+builtin_reload(PyObject *self, PyObject *v)
{
- PyObject *v;
-
- if (!PyArg_ParseTuple(args, "O:reload", &v))
- return NULL;
return PyImport_ReloadModule(v);
}
static PyObject *
-builtin_repr(PyObject *self, PyObject *args)
+builtin_repr(PyObject *self, PyObject *v)
{
- PyObject *v;
-
- if (!PyArg_ParseTuple(args, "O:repr", &v))
- return NULL;
return PyObject_Repr(v);
}
static PyMethodDef builtin_methods[] = {
- {"__import__", builtin___import__, 1, import_doc},
- {"abs", builtin_abs, 1, abs_doc},
- {"apply", builtin_apply, 1, apply_doc},
- {"buffer", builtin_buffer, 1, buffer_doc},
- {"callable", builtin_callable, 1, callable_doc},
- {"chr", builtin_chr, 1, chr_doc},
- {"cmp", builtin_cmp, 1, cmp_doc},
- {"coerce", builtin_coerce, 1, coerce_doc},
- {"compile", builtin_compile, 1, compile_doc},
- {"delattr", builtin_delattr, 1, delattr_doc},
- {"dir", builtin_dir, 1, dir_doc},
- {"divmod", builtin_divmod, 1, divmod_doc},
- {"eval", builtin_eval, 1, eval_doc},
- {"execfile", builtin_execfile, 1, execfile_doc},
- {"filter", builtin_filter, 1, filter_doc},
- {"getattr", builtin_getattr, 1, getattr_doc},
- {"globals", builtin_globals, 1, globals_doc},
- {"hasattr", builtin_hasattr, 1, hasattr_doc},
- {"hash", builtin_hash, 1, hash_doc},
- {"hex", builtin_hex, 1, hex_doc},
- {"id", builtin_id, 1, id_doc},
- {"input", builtin_input, 1, input_doc},
- {"intern", builtin_intern, 1, intern_doc},
- {"isinstance", builtin_isinstance, 1, isinstance_doc},
- {"issubclass", builtin_issubclass, 1, issubclass_doc},
- {"iter", builtin_iter, 1, iter_doc},
- {"len", builtin_len, 1, len_doc},
- {"locals", builtin_locals, 1, locals_doc},
- {"map", builtin_map, 1, map_doc},
- {"max", builtin_max, 1, max_doc},
- {"min", builtin_min, 1, min_doc},
- {"oct", builtin_oct, 1, oct_doc},
- {"open", builtin_open, 1, open_doc},
- {"ord", builtin_ord, 1, ord_doc},
- {"pow", builtin_pow, 1, pow_doc},
- {"range", builtin_range, 1, range_doc},
- {"raw_input", builtin_raw_input, 1, raw_input_doc},
- {"reduce", builtin_reduce, 1, reduce_doc},
- {"reload", builtin_reload, 1, reload_doc},
- {"repr", builtin_repr, 1, repr_doc},
- {"round", builtin_round, 1, round_doc},
- {"setattr", builtin_setattr, 1, setattr_doc},
- {"slice", builtin_slice, 1, slice_doc},
- {"unichr", builtin_unichr, 1, unichr_doc},
- {"vars", builtin_vars, 1, vars_doc},
- {"xrange", builtin_xrange, 1, xrange_doc},
- {"zip", builtin_zip, 1, zip_doc},
+ {"__import__", builtin___import__, METH_VARARGS, import_doc},
+ {"abs", builtin_abs, METH_O, abs_doc},
+ {"apply", builtin_apply, METH_VARARGS, apply_doc},
+ {"buffer", builtin_buffer, METH_VARARGS, buffer_doc},
+ {"callable", builtin_callable, METH_O, callable_doc},
+ {"chr", builtin_chr, METH_VARARGS, chr_doc},
+ {"cmp", builtin_cmp, METH_VARARGS, cmp_doc},
+ {"coerce", builtin_coerce, METH_VARARGS, coerce_doc},
+ {"compile", builtin_compile, METH_VARARGS, compile_doc},
+ {"delattr", builtin_delattr, METH_VARARGS, delattr_doc},
+ {"dir", builtin_dir, METH_VARARGS, dir_doc},
+ {"divmod", builtin_divmod, METH_VARARGS, divmod_doc},
+ {"eval", builtin_eval, METH_VARARGS, eval_doc},
+ {"execfile", builtin_execfile, METH_VARARGS, execfile_doc},
+ {"filter", builtin_filter, METH_VARARGS, filter_doc},
+ {"getattr", builtin_getattr, METH_VARARGS, getattr_doc},
+ {"globals", (PyCFunction)builtin_globals, METH_NOARGS, globals_doc},
+ {"hasattr", builtin_hasattr, METH_VARARGS, hasattr_doc},
+ {"hash", builtin_hash, METH_O, hash_doc},
+ {"hex", builtin_hex, METH_O, hex_doc},
+ {"id", builtin_id, METH_O, id_doc},
+ {"input", builtin_input, METH_VARARGS, input_doc},
+ {"intern", builtin_intern, METH_VARARGS, intern_doc},
+ {"isinstance", builtin_isinstance, METH_VARARGS, isinstance_doc},
+ {"issubclass", builtin_issubclass, METH_VARARGS, issubclass_doc},
+ {"iter", builtin_iter, METH_VARARGS, iter_doc},
+ {"len", builtin_len, METH_O, len_doc},
+ {"locals", (PyCFunction)builtin_locals, METH_NOARGS, locals_doc},
+ {"map", builtin_map, METH_VARARGS, map_doc},
+ {"max", builtin_max, METH_VARARGS, max_doc},
+ {"min", builtin_min, METH_VARARGS, min_doc},
+ {"oct", builtin_oct, METH_O, oct_doc},
+ {"open", builtin_open, METH_VARARGS, open_doc},
+ {"ord", builtin_ord, METH_O, ord_doc},
+ {"pow", builtin_pow, METH_VARARGS, pow_doc},
+ {"range", builtin_range, METH_VARARGS, range_doc},
+ {"raw_input", builtin_raw_input, METH_VARARGS, raw_input_doc},
+ {"reduce", builtin_reduce, METH_VARARGS, reduce_doc},
+ {"reload", builtin_reload, METH_O, reload_doc},
+ {"repr", builtin_repr, METH_O, repr_doc},
+ {"round", builtin_round, METH_VARARGS, round_doc},
+ {"setattr", builtin_setattr, METH_VARARGS, setattr_doc},
+ {"slice", builtin_slice, METH_VARARGS, slice_doc},
+ {"unichr", builtin_unichr, METH_VARARGS, unichr_doc},
+ {"vars", builtin_vars, METH_VARARGS, vars_doc},
+ {"xrange", builtin_xrange, METH_VARARGS, xrange_doc},
+ {"zip", builtin_zip, METH_VARARGS, zip_doc},
{NULL, NULL},
};
}
static PyObject *
-gen_next(genobject *gen, PyObject *args)
+gen_next(genobject *gen)
{
PyObject *result;
- if (!PyArg_ParseTuple(args, ":next"))
- return NULL;
-
result = gen_iternext(gen);
if (result == NULL && !PyErr_Occurred()) {
}
static struct PyMethodDef gen_methods[] = {
- {"next", (PyCFunction)gen_next, METH_VARARGS,
+ {"next", (PyCFunction)gen_next, METH_NOARGS,
"next() -- get the next value, or raise StopIteration"},
{NULL, NULL} /* Sentinel */
};
*/
if (PyCFunction_Check(func)) {
int flags = PyCFunction_GET_FLAGS(func);
- if (flags > 1 || nk != 0)
+ if (nk != 0 || (flags & METH_KEYWORDS))
x = do_call(func, &stack_pointer,
na, nk);
else if (flags == METH_VARARGS) {
callargs = load_args(&stack_pointer, na);
x = PyCFunction_Call(func, callargs, NULL);
Py_XDECREF(callargs);
- } else if (!(flags & METH_KEYWORDS))
- x = fast_cfunction(func,
- &stack_pointer, na);
+ } else
+ x = fast_cfunction(func,
+ &stack_pointer, na);
} else {
if (PyMethod_Check(func)
&& PyMethod_GET_SELF(func) != NULL) {
{
PyCFunction meth = PyCFunction_GET_FUNCTION(func);
PyObject *self = PyCFunction_GET_SELF(func);
-
- if (na == 0)
- return (*meth)(self, NULL);
- else if (na == 1) {
- PyObject *arg = EXT_POP(*pp_stack);
- PyObject *result = (*meth)(self, arg);
- Py_DECREF(arg);
- return result;
- } else {
- PyObject *args = load_args(pp_stack, na);
- PyObject *result = (*meth)(self, args);
- Py_DECREF(args);
- return result;
- }
+ int flags = PyCFunction_GET_FLAGS(func);
+
+ switch (flags) {
+ case METH_OLDARGS:
+ if (na == 0)
+ return (*meth)(self, NULL);
+ else if (na == 1) {
+ PyObject *arg = EXT_POP(*pp_stack);
+ PyObject *result = (*meth)(self, arg);
+ Py_DECREF(arg);
+ return result;
+ } else {
+ PyObject *args = load_args(pp_stack, na);
+ PyObject *result = (*meth)(self, args);
+ Py_DECREF(args);
+ return result;
+ }
+ break;
+ case METH_NOARGS:
+ if (na == 0)
+ return (*meth)(self, NULL);
+ PyErr_Format(PyExc_TypeError,
+ "%.200s() takes no arguments (%d given)",
+ ((PyCFunctionObject*)func)->m_ml->ml_name, na);
+ return NULL;
+ break;
+ case METH_O:
+ if (na == 1) {
+ PyObject *arg = EXT_POP(*pp_stack);
+ PyObject *result = (*meth)(self, arg);
+ Py_DECREF(arg);
+ return result;
+ }
+ PyErr_Format(PyExc_TypeError,
+ "%.200s() takes exactly one argument (%d given)",
+ ((PyCFunctionObject*)func)->m_ml->ml_name, na);
+ return NULL;
+ break;
+ default:
+ fprintf(stderr, "%.200s() flags = %d\n",
+ ((PyCFunctionObject*)func)->m_ml->ml_name, flags);
+ PyErr_BadInternalCall();
+ return NULL;
+ }
}
static PyObject *
}
static PyObject *
-sys_displayhook(PyObject *self, PyObject *args)
+sys_displayhook(PyObject *self, PyObject *o)
{
- PyObject *o, *outf;
+ PyObject *outf;
PyInterpreterState *interp = PyThreadState_Get()->interp;
PyObject *modules = interp->modules;
PyObject *builtins = PyDict_GetItemString(modules, "__builtin__");
return NULL;
}
- /* parse arguments */
- if (!PyArg_ParseTuple(args, "O:displayhook", &o))
- return NULL;
-
/* Print value except if None */
/* After printing, also assign to '_' */
/* Before, set '_' to None to avoid recursion */
"Handle an exception by displaying it with a traceback on sys.stderr.\n";
static PyObject *
-sys_exc_info(PyObject *self, PyObject *args)
+sys_exc_info(PyObject *self)
{
PyThreadState *tstate;
- if (!PyArg_ParseTuple(args, ":exc_info"))
- return NULL;
tstate = PyThreadState_Get();
return Py_BuildValue(
"(OOO)",
exit status will be one (i.e., failure).";
static PyObject *
-sys_getdefaultencoding(PyObject *self, PyObject *args)
+sys_getdefaultencoding(PyObject *self)
{
- if (!PyArg_ParseTuple(args, ":getdefaultencoding"))
- return NULL;
return PyString_FromString(PyUnicode_GetDefaultEncoding());
}
dependent.";
static PyObject *
-sys_getrecursionlimit(PyObject *self, PyObject *args)
+sys_getrecursionlimit(PyObject *self)
{
- if (!PyArg_ParseTuple(args, ":getrecursionlimit"))
- return NULL;
return PyInt_FromLong(Py_GetRecursionLimit());
}
sys_getdlopenflags(PyObject *self, PyObject *args)
{
PyThreadState *tstate = PyThreadState_Get();
- if (!PyArg_ParseTuple(args, ":getdlopenflags"))
- return NULL;
if (!tstate)
return NULL;
return PyInt_FromLong(tstate->interp->dlopenflags);
#ifdef Py_TRACE_REFS
static PyObject *
-sys_gettotalrefcount(PyObject *self, PyObject *args)
+sys_gettotalrefcount(PyObject *self)
{
extern long _Py_RefTotal;
- if (!PyArg_ParseTuple(args, ":gettotalrefcount"))
- return NULL;
return PyInt_FromLong(_Py_RefTotal);
}
#ifdef COUNT_ALLOCS
static PyObject *
-sys_getcounts(PyObject *self, PyObject *args)
+sys_getcounts(PyObject *self)
{
extern PyObject *get_counts(void);
- if (!PyArg_ParseTuple(args, ":getcounts"))
- return NULL;
return get_counts();
}
#endif
static PyMethodDef sys_methods[] = {
/* Might as well keep this in alphabetic order */
- {"displayhook", sys_displayhook, 1, displayhook_doc},
- {"exc_info", sys_exc_info, 1, exc_info_doc},
- {"excepthook", sys_excepthook, 1, excepthook_doc},
- {"exit", sys_exit, 0, exit_doc},
- {"getdefaultencoding", sys_getdefaultencoding, 1,
+ {"displayhook", sys_displayhook, METH_O, displayhook_doc},
+ {"exc_info", (PyCFunction)sys_exc_info, METH_NOARGS, exc_info_doc},
+ {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
+ {"exit", sys_exit, METH_OLDARGS, exit_doc},
+ {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, METH_NOARGS,
getdefaultencoding_doc},
#ifdef HAVE_DLOPEN
- {"getdlopenflags", sys_getdlopenflags, 1,
- getdlopenflags_doc},
+ {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,
+ getdlopenflags_doc},
#endif
#ifdef COUNT_ALLOCS
- {"getcounts", sys_getcounts, 1},
+ {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS},
#endif
#ifdef DYNAMIC_EXECUTION_PROFILE
- {"getdxp", _Py_GetDXProfile, 1},
+ {"getdxp", _Py_GetDXProfile, METH_VARARGS},
#endif
#ifdef Py_TRACE_REFS
- {"getobjects", _Py_GetObjects, 1},
- {"gettotalrefcount", sys_gettotalrefcount, 1},
+ {"getobjects", _Py_GetObjects, METH_VARARGS},
+ {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS},
#endif
- {"getrefcount", sys_getrefcount, 1, getrefcount_doc},
- {"getrecursionlimit", sys_getrecursionlimit, 1,
+ {"getrefcount", sys_getrefcount, METH_VARARGS, getrefcount_doc},
+ {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS,
getrecursionlimit_doc},
- {"_getframe", sys_getframe, 1, getframe_doc},
+ {"_getframe", sys_getframe, METH_VARARGS, getframe_doc},
#ifdef USE_MALLOPT
- {"mdebug", sys_mdebug, 1},
+ {"mdebug", sys_mdebug, METH_VARARGS},
#endif
- {"setdefaultencoding", sys_setdefaultencoding, 1,
+ {"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS,
setdefaultencoding_doc},
- {"setcheckinterval", sys_setcheckinterval, 1,
+ {"setcheckinterval", sys_setcheckinterval, METH_VARARGS,
setcheckinterval_doc},
#ifdef HAVE_DLOPEN
- {"setdlopenflags", sys_setdlopenflags, 1,
- setdlopenflags_doc},
+ {"setdlopenflags", sys_setdlopenflags, METH_VARARGS,
+ setdlopenflags_doc},
#endif
- {"setprofile", sys_setprofile, 0, setprofile_doc},
- {"setrecursionlimit", sys_setrecursionlimit, 1,
+ {"setprofile", sys_setprofile, METH_OLDARGS, setprofile_doc},
+ {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,
setrecursionlimit_doc},
- {"settrace", sys_settrace, 0, settrace_doc},
+ {"settrace", sys_settrace, METH_OLDARGS, settrace_doc},
{NULL, NULL} /* sentinel */
};
#! /bin/sh
-# From configure.in Revision: 1.246
+# From configure.in Revision: 1.247
# Guess values for system-dependent variables and create Makefiles.
# Generated automatically using autoconf version 2.13