This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author samwyse
Recipients r.david.murray, samwyse
Date 2014-12-12.17:27:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1418405261.6.0.0580801462027.issue23041@psf.upfronthosting.co.za>
In-reply-to
Content
David:  That's not a problem for me.

Sorry I can't provide real patches, but I'm not in a position to compile (much less test) the C implementation of _csv.  I've looked at the code online and below are the changes that I think need to be made.  My use cases don't require special handing when reading empty fields, so the only changes I've made are to the code for writers.  I did verify that the reader code mostly only checks for QUOTE_NOTNULL when parsing.  This means that completely empty fields will continue to load as zero-length strings, not None.  I won't stand in the way of anyone wanting to "fix" that for these new rules.



typedef enum {
    QUOTE_MINIMAL, QUOTE_ALL, QUOTE_NONNUMERIC, QUOTE_NONE,
    QUOTE_STRINGS, QUOTE_NOTNULL
} QuoteStyle;



static StyleDesc quote_styles[] = {
    { QUOTE_MINIMAL,    "QUOTE_MINIMAL" },
    { QUOTE_ALL,        "QUOTE_ALL" },
    { QUOTE_NONNUMERIC, "QUOTE_NONNUMERIC" },
    { QUOTE_NONE,       "QUOTE_NONE" },
    { QUOTE_STRINGS,    "QUOTE_STRINGS" },
    { QUOTE_NOTNULL,    "QUOTE_NOTNULL" },
    { 0 }
};



        switch (dialect->quoting) {
        case QUOTE_NONNUMERIC:
            quoted = !PyNumber_Check(field);
            break;
        case QUOTE_ALL:
            quoted = 1;
            break;
        case QUOTE_STRINGS:
            quoted = PyString_Check(field);
            break;
        case QUOTE_NOTNULL:
            quoted = field != Py_None;
            break;
        default:
            quoted = 0;
            break;
        }



"        csv.QUOTE_MINIMAL means only when required, for example, when a\n"
"            field contains either the quotechar or the delimiter\n"
"        csv.QUOTE_ALL means that quotes are always placed around fields.\n"
"        csv.QUOTE_NONNUMERIC means that quotes are always placed around\n"
"            fields which do not parse as integers or floating point\n"
"            numbers.\n"
"        csv.QUOTE_STRINGS means that quotes are always placed around\n"
"            fields which are strings.  Note that the Python value None\n"
"            is not a string.\n"
"        csv.QUOTE_NOTNULL means that quotes are only placed around fields\n"
"            that are not the Python value None.\n"
History
Date User Action Args
2014-12-12 17:27:41samwysesetrecipients: + samwyse, r.david.murray
2014-12-12 17:27:41samwysesetmessageid: <1418405261.6.0.0580801462027.issue23041@psf.upfronthosting.co.za>
2014-12-12 17:27:41samwyselinkissue23041 messages
2014-12-12 17:27:41samwysecreate