| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f7667e3 commit a57dfd0
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1596,6 +1596,12 @@ def test_decode(self): | |||
| 1596 | 1596 | self.assertEqual(codecs.decode(b'abc'), 'abc') | |
| 1597 | 1597 | self.assertRaises(UnicodeDecodeError, codecs.decode, b'\xff', 'ascii') | |
| 1598 | 1598 | ||
| 1599 | + # test keywords | ||
| 1600 | + self.assertEqual(codecs.decode(obj=b'\xe4\xf6\xfc', encoding='latin-1'), | ||
| 1601 | + '\xe4\xf6\xfc') | ||
| 1602 | + self.assertEqual(codecs.decode(b'[\xff]', 'ascii', errors='ignore'), | ||
| 1603 | + '[]') | ||
| 1604 | + | ||
| 1599 | 1605 | def test_encode(self): | |
| 1600 | 1606 | self.assertEqual(codecs.encode('\xe4\xf6\xfc', 'latin-1'), | |
| 1601 | 1607 | b'\xe4\xf6\xfc') | |
@@ -1604,6 +1610,12 @@ def test_encode(self): | |||
| 1604 | 1610 | self.assertEqual(codecs.encode('abc'), b'abc') | |
| 1605 | 1611 | self.assertRaises(UnicodeEncodeError, codecs.encode, '\xffff', 'ascii') | |
| 1606 | 1612 | ||
| 1613 | + # test keywords | ||
| 1614 | + self.assertEqual(codecs.encode(obj='\xe4\xf6\xfc', encoding='latin-1'), | ||
| 1615 | + b'\xe4\xf6\xfc') | ||
| 1616 | + self.assertEqual(codecs.encode('[\xff]', 'ascii', errors='ignore'), | ||
| 1617 | + b'[]') | ||
| 1618 | + | ||
| 1607 | 1619 | def test_register(self): | |
| 1608 | 1620 | self.assertRaises(TypeError, codecs.register) | |
| 1609 | 1621 | self.assertRaises(TypeError, codecs.register, 42) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,13 +89,15 @@ a ValueError. Other possible values are 'ignore', 'replace' and\n\ | |||
| 89 | 89 | codecs.register_error that can handle ValueErrors."); | |
| 90 | 90 | ||
| 91 | 91 | static PyObject * | |
| 92 | - codec_encode(PyObject *self, PyObject *args) | ||
| 92 | + codec_encode(PyObject *self, PyObject *args, PyObject *kwargs) | ||
| 93 | 93 | { | |
| 94 | + static char *kwlist[] = {"obj", "encoding", "errors", NULL}; | ||
| 94 | 95 | const char *encoding = NULL; | |
| 95 | 96 | const char *errors = NULL; | |
| 96 | 97 | PyObject *v; | |
| 97 | 98 | ||
| 98 | - if (!PyArg_ParseTuple(args, "O|ss:encode", &v, &encoding, &errors)) | ||
| 99 | + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|ss:encode", kwlist, | ||
| 100 | + &v, &encoding, &errors)) | ||
| 99 | 101 | return NULL; | |
| 100 | 102 | ||
| 101 | 103 | if (encoding == NULL) | |
@@ -116,13 +118,15 @@ as well as any other name registered with codecs.register_error that is\n\ | |||
| 116 | 118 | able to handle ValueErrors."); | |
| 117 | 119 | ||
| 118 | 120 | static PyObject * | |
| 119 | - codec_decode(PyObject *self, PyObject *args) | ||
| 121 | + codec_decode(PyObject *self, PyObject *args, PyObject *kwargs) | ||
| 120 | 122 | { | |
| 123 | + static char *kwlist[] = {"obj", "encoding", "errors", NULL}; | ||
| 121 | 124 | const char *encoding = NULL; | |
| 122 | 125 | const char *errors = NULL; | |
| 123 | 126 | PyObject *v; | |
| 124 | 127 | ||
| 125 | - if (!PyArg_ParseTuple(args, "O|ss:decode", &v, &encoding, &errors)) | ||
| 128 | + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|ss:decode", kwlist, | ||
| 129 | + &v, &encoding, &errors)) | ||
| 126 | 130 | return NULL; | |
| 127 | 131 | ||
| 128 | 132 | if (encoding == NULL) | |
@@ -1120,9 +1124,9 @@ static PyMethodDef _codecs_functions[] = { | |||
| 1120 | 1124 | register__doc__}, | |
| 1121 | 1125 | {"lookup", codec_lookup, METH_VARARGS, | |
| 1122 | 1126 | lookup__doc__}, | |
| 1123 | - {"encode", codec_encode, METH_VARARGS, | ||
| 1127 | + {"encode", (PyCFunction)codec_encode, METH_VARARGS|METH_KEYWORDS, | ||
| 1124 | 1128 | encode__doc__}, | |
| 1125 | - {"decode", codec_decode, METH_VARARGS, | ||
| 1129 | + {"decode", (PyCFunction)codec_decode, METH_VARARGS|METH_KEYWORDS, | ||
| 1126 | 1130 | decode__doc__}, | |
| 1127 | 1131 | {"escape_encode", escape_encode, METH_VARARGS}, | |
| 1128 | 1132 | {"escape_decode", escape_decode, METH_VARARGS}, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments