Commit Graph

115 Commits

Author SHA1 Message Date
Miss Islington (bot) 6933c4ace9
[3.13] gh-113785: csv: fields starting with escapechar are not quoted (GH-122110) (GH-122258)
(cherry picked from commit a3327dbfd4)

Co-authored-by: Mikołaj Kuranowski <mkuranowski@gmail.com>
2024-07-25 07:29:36 +00:00
Serhiy Storchaka c688c0f130
gh-67044: Always quote or escape \r and \n in csv.writer() (GH-115741) 2024-02-23 22:25:09 +02:00
Serhiy Storchaka 937d282150
gh-115712: Support CSV dialects with delimiter=' ' and skipinitialspace=True (GH-115721)
Restore support of such combination, disabled in gh-113796.

csv.writer() now quotes empty fields if delimiter is a space and
skipinitialspace is true and raises exception if quoting is not possible.
2024-02-20 18:09:50 +02:00
Serhiy Storchaka ea30a28c3e
gh-113732: Fix support of QUOTE_NOTNULL and QUOTE_STRINGS in csv.reader (GH-113738) 2024-01-30 14:21:12 +02:00
Serhiy Storchaka c8351a617b
gh-113796: Add more validation checks in the csv.Dialect constructor (GH-113797)
ValueError is now raised if the same character is used in different roles.
2024-01-22 15:34:16 +02:00
Skip Montanaro 72abb8c5d4
gh-114123: Migrate docstring from _csv to csv (#114124)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Éric <merwok@netwok.org>
2024-01-18 22:18:42 +00:00
Serhiy Storchaka 568d220993
gh-70835: Clarify error message for CSV file opened with wrong newline (GH-113786)
Based on patch by SilentGhost.
2024-01-10 14:52:29 +02:00
Alex Waygood 19601efa36
gh-109653: Remove unused imports in the `Lib/` directory (#109803) 2023-09-24 15:07:23 +01:00
Serhiy Storchaka b4131a13cb
gh-109050: Remove remaining tests for legacy Unicode C API (GH-109068) 2023-09-09 05:44:46 +00:00
Victor Stinner 995f4c48e1
gh-80527: Change support.requires_legacy_unicode_capi() (#108438)
The decorator now requires to be called with parenthesis:

    @support.requires_legacy_unicode_capi()

instead of:

    @support.requires_legacy_unicode_capi

The implementation now only imports _testcapi when the decorator is
called, so "import test.support" no longer imports the _testcapi
extension.
2023-08-24 20:09:23 +02:00
Inada Naoki 1237fb6a4b
gh-80480: array: Add 'w' typecode. (#105242) 2023-06-04 16:45:00 +00:00
chgnrdv 06c2a4858b
gh-104265 Disallow instantiation of `_csv.Reader` and `_csv.Writer` (#104266) 2023-05-07 21:15:44 +00:00
Skip Montanaro 330a942b63
gh-67230: add quoting rules to csv module (GH-29469)
Add two quoting styles for csv dialects.
They will help to work with certain databases in particular.

Automerge-Triggered-By: GH:merwok
2023-04-12 15:32:30 -07:00
andrei kulakov d0679c1239
bpo-44512: Fix handling of extrasactions arg to csv.DictWriter with mixed or upper case (#26924) 2022-12-09 16:14:33 +00:00
Stanley 676d8ef380
gh-65496: Correct wording on csv's skipinitialspace argument (#96170) 2022-10-07 11:15:34 -07:00
Nikita Sobolev 1c01bd28a0
gh-95950: Add a test for both `csv.Dialect` and `kwargs` (#95951) 2022-08-28 17:43:32 -07:00
Sam Ezeh cd492d43a2
gh-76728: Coerce DictReader and DictWriter fieldnames argument to a list (GH-32225) 2022-08-25 05:13:24 -05:00
Dong-hee Na ab62051152
bpo-20028: Empty escapechar/quotechar is not allowed for csv.Dialect (GH-28833) 2021-10-11 20:08:15 +09:00
Serhiy Storchaka b454e8e4df
bpo-27580: Add support of null characters in the csv module. (GH-28808) 2021-10-09 19:17:43 +03:00
Dong-hee Na 34bbc87b2d
bpo-20028: Improve error message of csv.Dialect when initializing (GH-28705) 2021-10-09 23:50:12 +09:00
andrei kulakov ceea579ccc
bpo-43625: Enhance csv sniffer has_headers() to be more accurate (GH-26939) 2021-07-30 19:10:37 +02:00
T. Wouters 0093876328
bpo-44630: Fix assertion errors in csv module (GH-27127)
Fix incorrect handling of exceptions when interpreting dialect objects in
the csv module. Not clearing exceptions between calls to
PyObject_GetAttrString() causes assertion failures in pydebug mode (or with
assertions enabled).

Add a minimal test that would've caught this (passing None as dialect, or
any object that isn't a csv.Dialect subclass, which the csv module allows
and caters to, even though it is not documented.) In pydebug mode, the test
triggers the assertion failure in the old code.

Contributed-By: T. Wouters [Google]
2021-07-13 15:56:45 -07:00
Dong-hee Na 5a3108044d
bpo-28395: Remove unnecessary semicolons in tests (GH-26868) 2021-06-23 18:01:06 +09:00
Ken Jin 2b458c1dba
bpo-44089: Allow subclassing of ``csv.Error`` (GH-26008)
* fix subclass error

* Update 2021-05-09-22-52-34.bpo-44089.IoANsN.rst
2021-05-12 06:47:11 -07:00
Inada Naoki 35715d1e72
bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25145)
* test_asyncio
* test_bz2
* test_math
* test_cmath
* test_cmd_line
* test_cmd_line_script
* test_compile
* test_contextlib
* test_profile
* ctypes/test/test_find
* test_multiprocessing
* test_configparser
* test_csv
* test_dbm_dumb
* test_decimal
* test_difflib
* os.fdopen() calls io.text_encoding() to emit EncodingWarning for right place.
2021-04-04 09:01:23 +09:00
Berker Peksag 5c0eed7375
bpo-12178: Fix escaping of escapechar in csv.writer() (GH-13710)
Co-authored-by: Itay Elbirt <anotahacou@gmail.com>
2020-09-20 09:38:07 +03:00
Inada Naoki 902356a7b0
bpo-41338: Fix DeprecationWarning in tests (GH-21542) 2020-07-20 12:02:50 +09:00
Serhiy Storchaka 4c8f09d7ce
bpo-36346: Make using the legacy Unicode C API optional (GH-21437)
Add compile time option USE_UNICODE_WCHAR_CACHE. Setting it to 0
makes the interpreter not using the wchar_t cache and the legacy Unicode C API.
2020-07-10 23:26:06 +03:00
Serhiy Storchaka c88239f864
bpo-26407: Do not mask errors in csv. (GH-20536)
Unexpected errors in calling the __iter__ method are no longer
masked by TypeError in csv.reader(), csv.writer.writerow() and
csv.writer.writerows().
2020-06-22 11:21:59 +03:00
Rémi Lapeyre fce5ff1e18 bpo-27497: Add return value to csv.DictWriter.writeheader (GH-12306)
csv.DictWriter.writeheader() now returns the return value of the
underlying csv.Writer.writerow() method.

Patch contributed by Ashish Nitin Patil.
2019-05-10 03:50:11 +02:00
Serhiy Storchaka 323748ad74
bpo-34197: Make _csv.Dialect attributes booleans. (GH-8440)
Attributes skipinitialspace, doublequote and strict are now
booleans instead of integers 0 or 1.
2018-07-26 13:21:09 +03:00
Serhiy Storchaka 2411292ba8
bpo-30157: Fix csv.Sniffer.sniff() regex pattern. (GH-5601)
Co-authored-by: Jake Davis <jcdavis@awedge.net>
2018-02-09 20:00:49 +02:00
Licht Takeuchi 2001900b0c bpo-32255: Always quote a single empty field when write into a CSV file. (#4769)
This allows to distinguish an empty row from a row consisting of a single empty field.
2017-12-12 11:57:06 +02:00
INADA Naoki 0a421a28f8 Issue #18219: Optimize csv.DictWriter for large number of columns.
Patch by Mariatta Wijaya.
2016-10-21 19:47:57 +09:00
Raymond Hettinger 8ca35707c0 Issue #27895: Strengthen the dict reader tests. 2016-08-30 12:57:26 -07:00
Raymond Hettinger 43ca452887 Issue #27842: The csv.DictReader now returns rows of type OrderedDict. 2016-08-30 12:35:50 -07:00
Serhiy Storchaka e437a10d15 Issue #23277: Remove unused imports in tests. 2016-04-24 21:41:02 +03:00
Berker Peksag 1e8ee9b380 Issue #23277: Remove unused sys and os imports
Patch by Jon Dufresne.
2016-04-24 07:31:42 +03:00
Serhiy Storchaka f9253c96fd Issue #22995: Instances of extension types with a state that aren't
subclasses of list or dict and haven't implemented any pickle-related
methods (__reduce__, __reduce_ex__, __getnewargs__, __getnewargs_ex__,
or __getstate__), can no longer be pickled.  Including memoryview.
2015-12-25 21:05:35 +02:00
Serhiy Storchaka f81be8aa3f Issue #22995: Instances of extension types with a state that aren't
subclasses of list or dict and haven't implemented any pickle-related
methods (__reduce__, __reduce_ex__, __getnewargs__, __getnewargs_ex__,
or __getstate__), can no longer be pickled.  Including memoryview.
2015-12-25 21:04:29 +02:00
Martin Panter 19e69c5a20 Issue #23883: Add missing APIs to __all__; patch by Jacek Kołodziej 2015-11-14 12:46:42 +00:00
Zachary Ware 38c707e7e0 Issue #21741: Update 147 test modules to use test discovery.
I have compared output between pre- and post-patch runs of these tests
to make sure there's nothing missing and nothing broken, on both
Windows and Linux.  The only differences I found were actually tests
that were previously *not* run.
2015-04-13 15:00:43 -05:00
Serhiy Storchaka 7901b48a1f Issue #23171: csv.Writer.writerow() now supports arbitrary iterables. 2015-03-30 09:09:54 +03:00
Serhiy Storchaka 7c316a181a Check that failed writerow() doesn't produce change a file. 2015-03-25 19:16:54 +02:00
Serhiy Storchaka 0b4e355b8e Check that failed writerow() doesn't produce change a file. 2015-03-25 19:16:15 +02:00
Berker Peksag 0f41acb0ea Issue #22076: Minor grammar fix.
Patch by Martin Matusiak.
2014-07-27 23:22:34 +03:00
Antoine Pitrou 05da1ef40a Issue #18727: improve test coverage of the csv module by testing for DictWriter.writerows.
Patch by Muhammad Jehanzeb.
2014-04-29 01:58:06 +02:00
Victor Stinner 009771ee6b (Merge 3.3) Issue #18829: Add tests for the csv module for invalid characters
(delimiter, escapechar, quotechar)
2014-01-02 12:53:50 +01:00
Victor Stinner 6a31b0fa19 Issue #18829: Add tests for the csv module for invalid characters (delimiter,
escapechar, quotechar)
2014-01-02 12:53:13 +01:00
Serhiy Storchaka cf58fb5e29 Issue #18829: csv.Dialect() now checks type for delimiter, escapechar and
quotechar fields.  Original patch by Vajrasky Kok.
2013-12-19 16:28:04 +02:00