Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Delta Between Two Patch Sets: Objects/bytesobject.c

Issue 8706: accept keyword arguments on all base type methods and builtins
Left Patch Set: Created 8 years, 3 months ago
Right Patch Set: Created 8 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Objects/bytearrayobject.c ('k') | Objects/stringlib/find.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* bytes object implementation */ 1 /* bytes object implementation */
2 2
3 #define PY_SSIZE_T_CLEAN 3 #define PY_SSIZE_T_CLEAN
4 4
5 #include "Python.h" 5 #include "Python.h"
6 6
7 #include "bytes_methods.h" 7 #include "bytes_methods.h"
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 static Py_ssize_t 10 static Py_ssize_t
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 #define LEFTSTRIP 0 965 #define LEFTSTRIP 0
966 #define RIGHTSTRIP 1 966 #define RIGHTSTRIP 1
967 #define BOTHSTRIP 2 967 #define BOTHSTRIP 2
968 968
969 /* Arrays indexed by above */ 969 /* Arrays indexed by above */
970 static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"}; 970 static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"};
971 971
972 #define STRIPNAME(i) (stripformat[i]+3) 972 #define STRIPNAME(i) (stripformat[i]+3)
973 973
974 PyDoc_STRVAR(split__doc__, 974 PyDoc_STRVAR(split__doc__,
975 "B.split([sep[, maxsplit]]) -> list of bytes\n\ 975 "B.split(sep=None, maxsplit=-1) -> list of bytes\n\
976 \n\ 976 \n\
977 Return a list of the sections in B, using sep as the delimiter.\n\ 977 Return a list of the sections in B, using sep as the delimiter.\n\
978 If sep is not specified or is None, B is split on ASCII whitespace\n\ 978 If sep is not specified or is None, B is split on ASCII whitespace\n\
979 characters (space, tab, return, newline, formfeed, vertical tab).\n\ 979 characters (space, tab, return, newline, formfeed, vertical tab).\n\
980 If maxsplit is given, at most maxsplit splits are done."); 980 If maxsplit is given, at most maxsplit splits are done.");
981 981
982 static PyObject * 982 static PyObject *
983 bytes_split(PyBytesObject *self, PyObject *args) 983 bytes_split(PyBytesObject *self, PyObject *args, PyObject *kwds)
984 { 984 {
985 static char *kwlist[] = {"sep", "maxsplit", 0};
985 Py_ssize_t len = PyBytes_GET_SIZE(self), n; 986 Py_ssize_t len = PyBytes_GET_SIZE(self), n;
986 Py_ssize_t maxsplit = -1; 987 Py_ssize_t maxsplit = -1;
987 const char *s = PyBytes_AS_STRING(self), *sub; 988 const char *s = PyBytes_AS_STRING(self), *sub;
988 Py_buffer vsub; 989 Py_buffer vsub;
989 PyObject *list, *subobj = Py_None; 990 PyObject *list, *subobj = Py_None;
990 991
991 if (!PyArg_ParseTuple(args, "|On:split", &subobj, &maxsplit)) 992 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|On:split",
993 kwlist, &subobj, &maxsplit))
992 return NULL; 994 return NULL;
993 if (maxsplit < 0) 995 if (maxsplit < 0)
994 maxsplit = PY_SSIZE_T_MAX; 996 maxsplit = PY_SSIZE_T_MAX;
995 if (subobj == Py_None) 997 if (subobj == Py_None)
996 return stringlib_split_whitespace((PyObject*) self, s, len, maxsplit); 998 return stringlib_split_whitespace((PyObject*) self, s, len, maxsplit);
997 if (_getbuffer(subobj, &vsub) < 0) 999 if (_getbuffer(subobj, &vsub) < 0)
998 return NULL; 1000 return NULL;
999 sub = vsub.buf; 1001 sub = vsub.buf;
1000 n = vsub.len; 1002 n = vsub.len;
1001 1003
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 return NULL; 1055 return NULL;
1054 1056
1055 return stringlib_rpartition( 1057 return stringlib_rpartition(
1056 (PyObject*) self, 1058 (PyObject*) self,
1057 PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), 1059 PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
1058 sep_obj, sep, sep_len 1060 sep_obj, sep, sep_len
1059 ); 1061 );
1060 } 1062 }
1061 1063
1062 PyDoc_STRVAR(rsplit__doc__, 1064 PyDoc_STRVAR(rsplit__doc__,
1063 "B.rsplit([sep[, maxsplit]]) -> list of bytes\n\ 1065 "B.rsplit(sep=None, maxsplit=-1) -> list of bytes\n\
1064 \n\ 1066 \n\
1065 Return a list of the sections in B, using sep as the delimiter,\n\ 1067 Return a list of the sections in B, using sep as the delimiter,\n\
1066 starting at the end of B and working to the front.\n\ 1068 starting at the end of B and working to the front.\n\
1067 If sep is not given, B is split on ASCII whitespace characters\n\ 1069 If sep is not given, B is split on ASCII whitespace characters\n\
1068 (space, tab, return, newline, formfeed, vertical tab).\n\ 1070 (space, tab, return, newline, formfeed, vertical tab).\n\
1069 If maxsplit is given, at most maxsplit splits are done."); 1071 If maxsplit is given, at most maxsplit splits are done.");
1070 1072
1071 1073
1072 static PyObject * 1074 static PyObject *
1073 bytes_rsplit(PyBytesObject *self, PyObject *args) 1075 bytes_rsplit(PyBytesObject *self, PyObject *args, PyObject *kwds)
1074 { 1076 {
1077 static char *kwlist[] = {"sep", "maxsplit", 0};
1075 Py_ssize_t len = PyBytes_GET_SIZE(self), n; 1078 Py_ssize_t len = PyBytes_GET_SIZE(self), n;
1076 Py_ssize_t maxsplit = -1; 1079 Py_ssize_t maxsplit = -1;
1077 const char *s = PyBytes_AS_STRING(self), *sub; 1080 const char *s = PyBytes_AS_STRING(self), *sub;
1078 Py_buffer vsub; 1081 Py_buffer vsub;
1079 PyObject *list, *subobj = Py_None; 1082 PyObject *list, *subobj = Py_None;
1080 1083
1081 if (!PyArg_ParseTuple(args, "|On:rsplit", &subobj, &maxsplit)) 1084 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|On:rsplit",
1085 kwlist, &subobj, &maxsplit))
1082 return NULL; 1086 return NULL;
1083 if (maxsplit < 0) 1087 if (maxsplit < 0)
1084 maxsplit = PY_SSIZE_T_MAX; 1088 maxsplit = PY_SSIZE_T_MAX;
1085 if (subobj == Py_None) 1089 if (subobj == Py_None)
1086 return stringlib_rsplit_whitespace((PyObject*) self, s, len, maxsplit); 1090 return stringlib_rsplit_whitespace((PyObject*) self, s, len, maxsplit);
1087 if (_getbuffer(subobj, &vsub) < 0) 1091 if (_getbuffer(subobj, &vsub) < 0)
1088 return NULL; 1092 return NULL;
1089 sub = vsub.buf; 1093 sub = vsub.buf;
1090 n = vsub.len; 1094 n = vsub.len;
1091 1095
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after
2467 {"lstrip", (PyCFunction)bytes_lstrip, METH_VARARGS, lstrip__doc__}, 2471 {"lstrip", (PyCFunction)bytes_lstrip, METH_VARARGS, lstrip__doc__},
2468 {"maketrans", (PyCFunction)bytes_maketrans, METH_VARARGS|METH_STATIC, 2472 {"maketrans", (PyCFunction)bytes_maketrans, METH_VARARGS|METH_STATIC,
2469 _Py_maketrans__doc__}, 2473 _Py_maketrans__doc__},
2470 {"partition", (PyCFunction)bytes_partition, METH_O, partition__doc__}, 2474 {"partition", (PyCFunction)bytes_partition, METH_O, partition__doc__},
2471 {"replace", (PyCFunction)bytes_replace, METH_VARARGS, replace__doc__}, 2475 {"replace", (PyCFunction)bytes_replace, METH_VARARGS, replace__doc__},
2472 {"rfind", (PyCFunction)bytes_rfind, METH_VARARGS | METH_KEYWORDS, rfind__doc __}, 2476 {"rfind", (PyCFunction)bytes_rfind, METH_VARARGS | METH_KEYWORDS, rfind__doc __},
2473 {"rindex", (PyCFunction)bytes_rindex, METH_VARARGS | METH_KEYWORDS, rindex__ doc__}, 2477 {"rindex", (PyCFunction)bytes_rindex, METH_VARARGS | METH_KEYWORDS, rindex__ doc__},
2474 {"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, rjust__doc__}, 2478 {"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, rjust__doc__},
2475 {"rpartition", (PyCFunction)bytes_rpartition, METH_O, 2479 {"rpartition", (PyCFunction)bytes_rpartition, METH_O,
2476 rpartition__doc__}, 2480 rpartition__doc__},
2477 {"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS, rsplit__doc__}, 2481 {"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS | METH_KEYWORDS, rsplit__ doc__},
2478 {"rstrip", (PyCFunction)bytes_rstrip, METH_VARARGS, rstrip__doc__}, 2482 {"rstrip", (PyCFunction)bytes_rstrip, METH_VARARGS, rstrip__doc__},
2479 {"split", (PyCFunction)bytes_split, METH_VARARGS, split__doc__}, 2483 {"split", (PyCFunction)bytes_split, METH_VARARGS | METH_KEYWORDS, split__doc __},
2480 {"splitlines", (PyCFunction)bytes_splitlines, METH_VARARGS | METH_KEYWORDS, 2484 {"splitlines", (PyCFunction)bytes_splitlines, METH_VARARGS | METH_KEYWORDS,
2481 splitlines__doc__}, 2485 splitlines__doc__},
2482 {"startswith", (PyCFunction)bytes_startswith, METH_VARARGS | METH_KEYWORDS, 2486 {"startswith", (PyCFunction)bytes_startswith, METH_VARARGS | METH_KEYWORDS,
2483 startswith__doc__}, 2487 startswith__doc__},
2484 {"strip", (PyCFunction)bytes_strip, METH_VARARGS, strip__doc__}, 2488 {"strip", (PyCFunction)bytes_strip, METH_VARARGS, strip__doc__},
2485 {"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS, 2489 {"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS,
2486 _Py_swapcase__doc__}, 2490 _Py_swapcase__doc__},
2487 {"title", (PyCFunction)stringlib_title, METH_NOARGS, _Py_title__doc__}, 2491 {"title", (PyCFunction)stringlib_title, METH_NOARGS, _Py_title__doc__},
2488 {"translate", (PyCFunction)bytes_translate, METH_VARARGS, 2492 {"translate", (PyCFunction)bytes_translate, METH_VARARGS,
2489 translate__doc__}, 2493 translate__doc__},
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
3124 } 3128 }
3125 it = PyObject_GC_New(striterobject, &PyBytesIter_Type); 3129 it = PyObject_GC_New(striterobject, &PyBytesIter_Type);
3126 if (it == NULL) 3130 if (it == NULL)
3127 return NULL; 3131 return NULL;
3128 it->it_index = 0; 3132 it->it_index = 0;
3129 Py_INCREF(seq); 3133 Py_INCREF(seq);
3130 it->it_seq = (PyBytesObject *)seq; 3134 it->it_seq = (PyBytesObject *)seq;
3131 _PyObject_GC_TRACK(it); 3135 _PyObject_GC_TRACK(it);
3132 return (PyObject *)it; 3136 return (PyObject *)it;
3133 } 3137 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+