Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4185)

Issue 5655: Fix for #1128: java.lang.String should be mapped to PyUnicode, not PyString

Can't Edit
Can't Publish+Mail
Start Review
Created:
15 years, 7 months ago by Leo Soto M.
Modified:
9 years, 4 months ago
Reviewers:
Nicholas Riley
Base URL:
https://jython.svn.sourceforge.net/svnroot/jython/trunk/
Visibility:
Public.

Description

This has the potential to break a lot of things, but it is the right thing to do. I hope we are on time to introduce it on 2.5. I've fixed all the regressions found by running the test suite, fixing the APIs that really need to return str objects. That was done explicitly declaring the return value as PyString on the Java site. On the Python side, I had to introduce StringUtil.asPyString as a helper to force the String -> PyString conversion (Another option is to do java_string.decode('iso8859-1'), but seems rather expensive)

Patch Set 1 #

Patch Set 2 : same patch, ignoring whitespace changes #

Unified diffs Side-by-side diffs Delta from patch set Stats (+125 lines, -110 lines) Patch
jython/Lib/javapath.py View 1 9 chunks +13 lines, -11 lines 4 comments Download
jython/Lib/os.py View 1 4 chunks +6 lines, -3 lines 2 comments Download
jython/Lib/test/test_exceptions.py View 1 chunk +1 line, -1 line 1 comment Download
jython/Lib/zlib.py View 1 3 chunks +11 lines, -7 lines 0 comments Download
jython/src/com/ziclix/python/sql/DataHandler.java View 2 chunks +2 lines, -2 lines 0 comments Download
jython/src/com/ziclix/python/sql/JDBC20DataHandler.java View 1 chunk +1 line, -1 line 0 comments Download
jython/src/com/ziclix/python/sql/Jython22DataHandler.java View 2 chunks +2 lines, -2 lines 0 comments Download
jython/src/com/ziclix/python/sql/handler/MySQLDataHandler.java View 1 1 chunk +7 lines, -5 lines 2 comments Download
jython/src/com/ziclix/python/sql/handler/PostgresqlDataHandler.java View 1 1 chunk +1 line, -1 line 0 comments Download
jython/src/org/python/core/PyFile.java View 1 2 chunks +8 lines, -8 lines 0 comments Download
jython/src/org/python/core/PyFunction.java View 1 chunk +4 lines, -4 lines 0 comments Download
jython/src/org/python/core/PyStringMap.java View 1 1 chunk +1 line, -1 line 2 comments Download
jython/src/org/python/core/PySystemState.java View 1 4 chunks +5 lines, -5 lines 1 comment Download
jython/src/org/python/core/PyTraceback.java View 1 chunk +2 lines, -1 line 0 comments Download
jython/src/org/python/core/__builtin__.java View 1 1 chunk +1 line, -1 line 0 comments Download
jython/src/org/python/core/adapter/ClassicPyObjectAdapter.java View 1 2 chunks +2 lines, -2 lines 1 comment Download
jython/src/org/python/core/util/StringUtil.java View 1 2 chunks +5 lines, -0 lines 2 comments Download
jython/src/org/python/modules/binascii.java View 1 18 chunks +21 lines, -22 lines 0 comments Download
jython/src/org/python/modules/cPickle.java View 1 3 chunks +4 lines, -4 lines 0 comments Download
jython/src/org/python/modules/cStringIO.java View 1 11 chunks +18 lines, -19 lines 0 comments Download
jython/src/org/python/modules/struct.java View 2 chunks +2 lines, -2 lines 0 comments Download
jython/src/org/python/modules/time/Time.java View 5 chunks +8 lines, -8 lines 2 comments Download

Messages

Total messages: 4
Leo Soto M.
15 years, 7 months ago (2008-09-13 23:35:39 UTC) #1
Leo Soto M.
same patch, ignoring whitespace changes
15 years, 7 months ago (2008-09-13 23:58:02 UTC) #2
Nicholas Riley
comments http://codereview.appspot.com/5655/diff/206/225 File jython/Lib/javapath.py (right): http://codereview.appspot.com/5655/diff/206/225#newcode103 Line 103: return asPyString(File(sys.getPath(path)).exists()) This is a bool, doesn't ...
15 years, 7 months ago (2008-09-14 00:22:45 UTC) #3
Leo Soto M.
15 years, 7 months ago (2008-09-21 16:57:17 UTC) #4
http://codereview.appspot.com/5655/diff/206/224
File jython/src/com/ziclix/python/sql/handler/MySQLDataHandler.java (right):

http://codereview.appspot.com/5655/diff/206/224#newcode57
Line 57: // XXX: Only works with ASCII data!
On 2008/09/14 00:22:45, Nicholas Riley wrote:
> tabs? looks like indentation is messed up here

Sure. I think I've fixed it, but when using diff -w whitespace changes are lost.

http://codereview.appspot.com/5655/diff/206/208
File jython/src/org/python/core/PyStringMap.java (right):

http://codereview.appspot.com/5655/diff/206/208#newcode144
Line 144: buf.append(new PyString((String)key).__repr__().toString());
On 2008/09/14 00:22:45, Nicholas Riley wrote:
> This seems a really complicated way to say:
> 
> "'" + key + "'"

Unless key.contains("'"). We could replicate PyString#__repr__ logic here, but I
think this is better.

http://codereview.appspot.com/5655/diff/206/210
File jython/src/org/python/core/util/StringUtil.java (right):

http://codereview.appspot.com/5655/diff/206/210#newcode89
Line 89: return new PyString(string);
On 2008/09/14 00:22:45, Nicholas Riley wrote:
> perhaps toPyString (parallel with toBytes above)?

To me, toPyString sounds more like a transformation, which is not the case here,
where we are just wrapping the String. Also note that asPyString parallels
PyString#asString.

http://codereview.appspot.com/5655/diff/206/217
File jython/src/org/python/modules/time/Time.java (right):

http://codereview.appspot.com/5655/diff/206/217#newcode654
Line 654: return new PyString(s);
On 2008/09/14 00:22:45, Nicholas Riley wrote:
> This can produce Unicode.  Consider:
> 
> LANG=es_ES.UTF-8 jythont -c "import time; print time.strftime('%A')"
> s?bado

So, strftime should start to return unicode in all cases?

That would break many doctests. Also this would break code that mixes the return
of strftime with other strings and then uses that value on places where a str is
expected (not an unicode). os.environ is one of such places. 

So, how about returning new PyUnicode(s).encode('utf-8')?

[BTW, What does CPython in your example? On Linux it doesn't seem to localize
the info, so I can't reproduce it :( ]
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b