[issue7615] unicode_escape codec does not escape quotes

2010-01-24 Thread Richard Hansen
Richard Hansen added the comment: Any comments on the patches? I'd love to see at least patches 1-3 make it into Python 2.7. :) -- ___ Python tracker <http://bugs.python.org/i

[issue7615] unicode_escape codec does not escape quotes

2009-12-31 Thread Richard Hansen
New submission from Richard Hansen : The description of the unicode_escape codec says that it produces "a string that is suitable as Unicode literal in Python source code." [1] Unfortunately, this is not true as it does not escape quotes. For example: print u'a\'b&

[issue7615] unicode_escape codec does not escape quotes

2010-01-03 Thread Richard Hansen
Richard Hansen added the comment: > If we change this, the encoder should quote both single and double > quotes - simply because it is not known whether the literal > will use single or double quotes. Or document that single quotes are always escaped so that the user knows he/she c

[issue7615] unicode_escape codec does not escape quotes

2010-01-04 Thread Richard Hansen
Richard Hansen added the comment: I thought about raw_unicode_escape more, and there's a way to escape quotes: use unicode escape sequences (e.g., ur'\u0027'). I've attached a new patch that does the following: * backslash-escapes single quotes when encoding with the

[issue7615] unicode_escape codec does not escape quotes

2010-01-05 Thread Richard Hansen
Richard Hansen added the comment: Attached is a patch to the unicode unit tests. It adds tests for the following: * unicode_escape escapes single quotes * raw_unicode_escape escapes single quotes * raw_unicode_escape escapes backslashes -- Added file: http://bugs.python.org

[issue7615] unicode_escape codec does not escape quotes

2010-01-05 Thread Richard Hansen
Changes by Richard Hansen : Removed file: http://bugs.python.org/file15742/unicode_escape_reorg.patch ___ Python tracker <http://bugs.python.org/issue7615> ___ ___ Pytho

[issue7615] unicode_escape codec does not escape quotes

2010-01-05 Thread Richard Hansen
Richard Hansen added the comment: Attaching updated unicode_escape_reorg.patch. This fixes two additional issues: * don't call _PyString_Resize() on an empty string because there is only one empty string instance, and that instance is returned when creating an empty string * make

[issue7615] unicode_escape codec does not escape quotes

2010-01-07 Thread Richard Hansen
Changes by Richard Hansen : Removed file: http://bugs.python.org/file15748/unicode_escape_reorg.patch ___ Python tracker <http://bugs.python.org/issue7615> ___ ___ Pytho

[issue7615] unicode_escape codec does not escape quotes

2010-01-07 Thread Richard Hansen
Richard Hansen added the comment: Attaching updated unicode_escape_reorg.patch. This addresses two additional issues: * removes pickle's workaround of raw-unicode-escape's broken escaping * eliminates duplicated code (the raw escape encode function was copied with onl

[issue7615] unicode_escape codec does not escape quotes

2010-01-07 Thread Richard Hansen
Richard Hansen added the comment: I believe this issue is ready to be bumped to the "patch review" stage. Thoughts? -- ___ Python tracker <http://bugs.python.

[issue7615] unicode_escape codec does not escape quotes

2010-01-07 Thread Richard Hansen
Richard Hansen added the comment: > Does the last patch obsolete the first two? If so please delete the > obsolete ones. Yes and no -- it depends on what the core Python developers want and are comfortable with: * unicode_escape_single_quotes.patch: Only escapes single quotes,

[issue7615] unicode_escape codec does not escape quotes

2010-01-07 Thread Richard Hansen
Changes by Richard Hansen : Removed file: http://bugs.python.org/file15746/unicode_escape_tests.patch ___ Python tracker <http://bugs.python.org/issue7615> ___ ___ Pytho

[issue7615] unicode_escape codec does not escape quotes

2010-01-07 Thread Richard Hansen
Richard Hansen added the comment: Attaching updated unit tests for the unicode_escape codec. I removed the raw_unicode_escape tests and will attach a separate patch for those. -- Added file: http://bugs.python.org/file15774/unicode_escape_tests.patch

[issue7615] unicode_escape codec does not escape quotes

2010-01-07 Thread Richard Hansen
Richard Hansen added the comment: Attaching updated unit tests for the raw_unicode_escape codec. -- Added file: http://bugs.python.org/file15775/raw_unicode_escape_tests.patch ___ Python tracker <http://bugs.python.org/issue7

[issue7615] unicode_escape codec does not escape quotes

2010-01-07 Thread Richard Hansen
Richard Hansen added the comment: > We'll need a patch that implements single and double quote escaping > for unicode_escape and a \u style escaping of quotes for the > raw_unicode_escape encoder. OK, I'll remove unicode_escape_single_quotes.patch and update unicode

[issue7615] unicode_escape codec does not escape quotes

2010-01-07 Thread Richard Hansen
Changes by Richard Hansen : Removed file: http://bugs.python.org/file15716/unicode_escape_single_quotes.patch ___ Python tracker <http://bugs.python.org/issue7

[issue7615] unicode_escape codec does not escape quotes

2010-01-09 Thread Richard Hansen
Changes by Richard Hansen : Removed file: http://bugs.python.org/file15729/unicode_escape_single_and_double_quotes.patch ___ Python tracker <http://bugs.python.org/issue7

[issue7615] unicode_escape codec does not escape quotes

2010-01-09 Thread Richard Hansen
Changes by Richard Hansen : Removed file: http://bugs.python.org/file15771/unicode_escape_reorg.patch ___ Python tracker <http://bugs.python.org/issue7615> ___ ___ Pytho

[issue7615] unicode_escape codec does not escape quotes

2010-01-09 Thread Richard Hansen
Changes by Richard Hansen : Removed file: http://bugs.python.org/file15774/unicode_escape_tests.patch ___ Python tracker <http://bugs.python.org/issue7615> ___ ___ Pytho

[issue7615] unicode_escape codec does not escape quotes

2010-01-09 Thread Richard Hansen
Changes by Richard Hansen : Removed file: http://bugs.python.org/file15775/raw_unicode_escape_tests.patch ___ Python tracker <http://bugs.python.org/issue7615> ___ ___

[issue7615] unicode_escape codec does not escape quotes

2010-01-09 Thread Richard Hansen
Richard Hansen added the comment: Attaching updated unit tests. The tests now check to make sure that single and double quotes are escaped. -- Added file: http://bugs.python.org/file15809/unicode_escape_tests.patch ___ Python tracker <h

[issue7615] unicode_escape codec does not escape quotes

2010-01-09 Thread Richard Hansen
Richard Hansen added the comment: Attaching a minimal patch: * unicode_escape now backslash-escapes single and double quotes * raw_unicode_escape now unicode-escapes single and double quotes * raw_unicode_escape now unicode-escapes backslashes * removes pickle's escaping workaroun

[issue7615] unicode_escape codec does not escape quotes

2010-01-09 Thread Richard Hansen
Richard Hansen added the comment: Attaching a patch for an issue discovered while looking at the code: * The UTF-16 decode logic in the Unicode escape encoders no longer reads past the end of the provided Py_UNICODE buffer if the last character's value is between 0xD800 and 0xDC00.

[issue7615] unicode_escape codec does not escape quotes

2010-01-09 Thread Richard Hansen
Richard Hansen added the comment: Attaching a patch for another issue discovered while looking at the code: * The Unicode escape encoders now check to make sure that the provided size is nonnegative. * C API documentation updated to make it clear that size must be nonnegative. This patch

[issue7615] unicode_escape codec does not escape quotes

2010-01-09 Thread Richard Hansen
Richard Hansen added the comment: Attaching a patch that eliminates duplicate code: * Merge unicodeescape_string(), PyUnicode_EncodeRawUnicodeEscape(), and modified_EncodeRawUnicodeEscape() into one function called _PyUnicode_EncodeCustomUnicodeEscape(). This patch is meant to be applied

[issue23349] memoryview.to_bytes() and PyBuffer_ToContiguous() off-by-one error for non-contiguous buffers

2015-01-29 Thread Richard Hansen
New submission from Richard Hansen: PyBuffer_ToContiguous() has an off-by-one error when copying a buffer it thinks is non-contiguous. To reproduce, put the following in foo.pyx and compile with Cython v0.21.2: cpdef foo(): cdef unsigned char[:] v = bytearray("te

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-01-29 Thread Richard Hansen
New submission from Richard Hansen: According to https://docs.python.org/2/c-api/buffer.html#the-new-style-py-buffer-struct if the suboffsets member of Py_buffer is non-NULL and all members of the array are negative, the buffer may be contiguous. PyBuffer_IsContiguous() does not behave this

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-01-29 Thread Richard Hansen
Changes by Richard Hansen : -- type: -> behavior ___ Python tracker <http://bugs.python.org/issue23352> ___ ___ Python-bugs-list mailing list Unsubscrib

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-01-29 Thread Richard Hansen
Richard Hansen added the comment: > The patch has an obvious syntax error :-) Doh! > Other than that, adding a comment would be nice. Agreed, will do. > Bonus points if you can write a test (3.x has infrastructure for that, see > Lib/test/test_buffer.py). I'll tak

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-01-29 Thread Richard Hansen
Richard Hansen added the comment: I've attached a new version of the patch. Suggestions for simplifying the test code would be appreciated. -- Added file: http://bugs.python.org/file37916/PyBuffer_IsContiguous_v2.patch ___ Python tracker

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-01-29 Thread Richard Hansen
Changes by Richard Hansen : -- versions: +Python 3.2, Python 3.3 ___ Python tracker <http://bugs.python.org/issue23352> ___ ___ Python-bugs-list mailing list Unsub

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-01-29 Thread Richard Hansen
Changes by Richard Hansen : -- versions: -Python 3.2, Python 3.3 ___ Python tracker <http://bugs.python.org/issue23352> ___ ___ Python-bugs-list mailin

[issue23349] PyBuffer_ToContiguous() off-by-one error for non-contiguous buffers

2015-01-29 Thread Richard Hansen
Changes by Richard Hansen : -- title: memoryview.to_bytes() and PyBuffer_ToContiguous() off-by-one error for non-contiguous buffers -> PyBuffer_ToContiguous() off-by-one error for non-contiguous buffers ___ Python tracker <http://bugs.pyth

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-01-30 Thread Richard Hansen
Richard Hansen added the comment: > People might rely on the fact that contiguous implies suboffsets==NULL. Cython (currently) relies on all-negatives being acceptable and equivalent to suboffsets==NULL. See: https://github.com/cython/cython/pull/367 http://thread.gmane.

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-01-31 Thread Richard Hansen
Richard Hansen added the comment: (The following message is mostly off-topic but I think it is relevant to those interested in this issue. This message is about the clarity of the documentation regarding flag semantics, and what I think the flags should mean.) > Cython doesn't fo

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-01-31 Thread Richard Hansen
Richard Hansen added the comment: Attached is a documentation patch that adds what I said in msg235141. I doubt everyone will agree with the changes, but maybe it will be a useful starting point. (Despite not having an asterisk next to my username, I have signed the contributor agreement

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-02-01 Thread Richard Hansen
Changes by Richard Hansen : Added file: http://bugs.python.org/file37953/doc_c-api_buffer.patch ___ Python tracker <http://bugs.python.org/issue23352> ___ ___ Python-bug

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-02-01 Thread Richard Hansen
Changes by Richard Hansen : Removed file: http://bugs.python.org/file37952/doc_c-api_buffer.patch ___ Python tracker <http://bugs.python.org/issue23352> ___ ___ Python-bug

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-02-01 Thread Richard Hansen
Changes by Richard Hansen : Removed file: http://bugs.python.org/file37953/doc_c-api_buffer.patch ___ Python tracker <http://bugs.python.org/issue23352> ___ ___ Python-bug

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-02-01 Thread Richard Hansen
Changes by Richard Hansen : Added file: http://bugs.python.org/file37954/doc_c-api_buffer.patch ___ Python tracker <http://bugs.python.org/issue23352> ___ ___ Python-bug

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-02-01 Thread Richard Hansen
Richard Hansen added the comment: > This leaves me +-0 for the change, with the caveat that applications > might break. How might an application break with this change? Compared to the current PyBuffer_IsContiguous(), the patched version is the same except it returns true for a wider

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-02-01 Thread Richard Hansen
Richard Hansen added the comment: >> When I compile and run the above (latest Cython from Git master), I >> get: >> >> () >> () > > With Cython version 0.20.1post0 I get: > > >>> foo.foo() > (-1,) > (-1,) > > If you get

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-02-01 Thread Richard Hansen
Richard Hansen added the comment: >> How might an application break with this change? > >assert(view->suboffsets == NULL); Fair point. -- ___ Python tracker <http://bugs.pyt

[issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

2015-02-01 Thread Richard Hansen
Richard Hansen added the comment: My preference is to apply the patch, of course. There is a legitimate concern that it will break existing code, but I think there are more points in favor of applying the patch: * there exists code that the current behavior is known to break * it's e