Kaydet (Commit) 31d8896e authored tarafından Andrew McNamara's avatar Andrew McNamara

Rename csv.set_field_limit to csv.field_size_limit (since it both sets and

gets).
üst a08eecb6
...@@ -6,7 +6,7 @@ csv.py - read/write/investigate CSV files ...@@ -6,7 +6,7 @@ csv.py - read/write/investigate CSV files
import re import re
from _csv import Error, __version__, writer, reader, register_dialect, \ from _csv import Error, __version__, writer, reader, register_dialect, \
unregister_dialect, get_dialect, list_dialects, \ unregister_dialect, get_dialect, list_dialects, \
set_field_limit, \ field_size_limit, \
QUOTE_MINIMAL, QUOTE_ALL, QUOTE_NONNUMERIC, QUOTE_NONE, \ QUOTE_MINIMAL, QUOTE_ALL, QUOTE_NONNUMERIC, QUOTE_NONE, \
__doc__ __doc__
from _csv import Dialect as _Dialect from _csv import Dialect as _Dialect
......
...@@ -233,21 +233,21 @@ class Test_Csv(unittest.TestCase): ...@@ -233,21 +233,21 @@ class Test_Csv(unittest.TestCase):
def test_read_bigfield(self): def test_read_bigfield(self):
# This exercises the buffer realloc functionality and field size # This exercises the buffer realloc functionality and field size
# limits. # limits.
limit = csv.set_field_limit() limit = csv.field_size_limit()
try: try:
size = 50000 size = 50000
bigstring = 'X' * size bigstring = 'X' * size
bigline = '%s,%s' % (bigstring, bigstring) bigline = '%s,%s' % (bigstring, bigstring)
self._read_test([bigline], [[bigstring, bigstring]]) self._read_test([bigline], [[bigstring, bigstring]])
csv.set_field_limit(size) csv.field_size_limit(size)
self._read_test([bigline], [[bigstring, bigstring]]) self._read_test([bigline], [[bigstring, bigstring]])
self.assertEqual(csv.set_field_limit(), size) self.assertEqual(csv.field_size_limit(), size)
csv.set_field_limit(size-1) csv.field_size_limit(size-1)
self.assertRaises(csv.Error, self._read_test, [bigline], []) self.assertRaises(csv.Error, self._read_test, [bigline], [])
self.assertRaises(TypeError, csv.set_field_limit, None) self.assertRaises(TypeError, csv.field_size_limit, None)
self.assertRaises(TypeError, csv.set_field_limit, 1, None) self.assertRaises(TypeError, csv.field_size_limit, 1, None)
finally: finally:
csv.set_field_limit(limit) csv.field_size_limit(limit)
class TestDialectRegistry(unittest.TestCase): class TestDialectRegistry(unittest.TestCase):
def test_registry_badargs(self): def test_registry_badargs(self):
......
...@@ -57,7 +57,7 @@ Library ...@@ -57,7 +57,7 @@ Library
+ a configurable limit to the size of parsed fields has been added - + a configurable limit to the size of parsed fields has been added -
previously, an unmatched quote character could result in the entire previously, an unmatched quote character could result in the entire
file being read into the field buffer before an error was reported. file being read into the field buffer before an error was reported.
+ A new module method csv.set_field_limit() has been added that sets + A new module method csv.field_size_limit() has been added that sets
the parser field size limit (returning the former limit). The initial the parser field size limit (returning the former limit). The initial
limit is 128kB. limit is 128kB.
+ reader and writer objects were not being registered with the cyclic-GC. + reader and writer objects were not being registered with the cyclic-GC.
......
...@@ -1408,12 +1408,12 @@ csv_get_dialect(PyObject *module, PyObject *name_obj) ...@@ -1408,12 +1408,12 @@ csv_get_dialect(PyObject *module, PyObject *name_obj)
} }
static PyObject * static PyObject *
csv_set_field_limit(PyObject *module, PyObject *args) csv_field_size_limit(PyObject *module, PyObject *args)
{ {
PyObject *new_limit = NULL; PyObject *new_limit = NULL;
long old_limit = field_limit; long old_limit = field_limit;
if (!PyArg_UnpackTuple(args, "set_field_limit", 0, 1, &new_limit)) if (!PyArg_UnpackTuple(args, "field_size_limit", 0, 1, &new_limit))
return NULL; return NULL;
if (new_limit != NULL) { if (new_limit != NULL) {
if (!PyInt_Check(new_limit)) { if (!PyInt_Check(new_limit)) {
...@@ -1533,9 +1533,9 @@ PyDoc_STRVAR(csv_unregister_dialect_doc, ...@@ -1533,9 +1533,9 @@ PyDoc_STRVAR(csv_unregister_dialect_doc,
"Delete the name/dialect mapping associated with a string name.\n" "Delete the name/dialect mapping associated with a string name.\n"
" csv.unregister_dialect(name)"); " csv.unregister_dialect(name)");
PyDoc_STRVAR(csv_set_field_limit_doc, PyDoc_STRVAR(csv_field_size_limit_doc,
"Sets an upper limit on parsed fields.\n" "Sets an upper limit on parsed fields.\n"
" csv.set_field_limit([limit])\n" " csv.field_size_limit([limit])\n"
"\n" "\n"
"Returns old limit. If limit is not given, no new limit is set and\n" "Returns old limit. If limit is not given, no new limit is set and\n"
"the old limit is returned"); "the old limit is returned");
...@@ -1553,8 +1553,8 @@ static struct PyMethodDef csv_methods[] = { ...@@ -1553,8 +1553,8 @@ static struct PyMethodDef csv_methods[] = {
METH_O, csv_unregister_dialect_doc}, METH_O, csv_unregister_dialect_doc},
{ "get_dialect", (PyCFunction)csv_get_dialect, { "get_dialect", (PyCFunction)csv_get_dialect,
METH_O, csv_get_dialect_doc}, METH_O, csv_get_dialect_doc},
{ "set_field_limit", (PyCFunction)csv_set_field_limit, { "field_size_limit", (PyCFunction)csv_field_size_limit,
METH_VARARGS, csv_set_field_limit_doc}, METH_VARARGS, csv_field_size_limit_doc},
{ NULL, NULL } { NULL, NULL }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment