From: <am...@us...> - 2010-04-12 22:03:23
|
Revision: 7022 http://jython.svn.sourceforge.net/jython/?rev=7022&view=rev Author: amak Date: 2010-04-12 22:03:17 +0000 (Mon, 12 Apr 2010) Log Message: ----------- Fixing a bug with translation of line endings when that should not be happening. Fixes http://bugs.jython.org/issue1549 Thanks to Jacob Fenwick for the (jfenwick) for the patch. Modified Paths: -------------- trunk/jython/Lib/modjy/modjy_wsgi.py trunk/jython/src/org/python/core/PyFile.java trunk/jython/src/org/python/core/util/FileUtil.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java Added Paths: ----------- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestPostData.java trunk/jython/tests/modjy/test_apps_dir/post_data_tests.py Modified: trunk/jython/Lib/modjy/modjy_wsgi.py =================================================================== --- trunk/jython/Lib/modjy/modjy_wsgi.py 2010-04-12 16:47:34 UTC (rev 7021) +++ trunk/jython/Lib/modjy/modjy_wsgi.py 2010-04-12 22:03:17 UTC (rev 7022) @@ -125,7 +125,7 @@ def set_wsgi_streams(self, req, resp, dict): try: - dict["wsgi.input"] = create_py_file(req.getInputStream()) + dict["wsgi.input"] = create_py_file(req.getInputStream(), "rb") dict["wsgi.errors"] = create_py_file(System.err) except IOException, iox: raise ModjyIOException(iox) Modified: trunk/jython/src/org/python/core/PyFile.java =================================================================== --- trunk/jython/src/org/python/core/PyFile.java 2010-04-12 16:47:34 UTC (rev 7021) +++ trunk/jython/src/org/python/core/PyFile.java 2010-04-12 22:03:17 UTC (rev 7022) @@ -96,7 +96,7 @@ file___init__(raw, name, mode, bufsize); } - PyFile(InputStream istream, String name, String mode, int bufsize, boolean closefd) { + public PyFile(InputStream istream, String name, String mode, int bufsize, boolean closefd) { parseMode(mode); file___init__(new StreamIO(istream, closefd), name, mode, bufsize); } Modified: trunk/jython/src/org/python/core/util/FileUtil.java =================================================================== --- trunk/jython/src/org/python/core/util/FileUtil.java 2010-04-12 16:47:34 UTC (rev 7021) +++ trunk/jython/src/org/python/core/util/FileUtil.java 2010-04-12 22:03:17 UTC (rev 7022) @@ -14,6 +14,13 @@ public class FileUtil { /** + * Creates a PyFile that reads from the given <code>InputStream</code> with mode. + */ + public static PyFile wrap(InputStream is, String mode) { + return new PyFile(is, "<Java InputStream '" + is + "' as file>", mode, -1, true); + } + + /** * Creates a PyFile that reads from the given <code>InputStream</code> with bufsize. */ public static PyFile wrap(InputStream is, int bufsize) { Modified: trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java =================================================================== --- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java 2010-04-12 16:47:34 UTC (rev 7021) +++ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java 2010-04-12 22:03:17 UTC (rev 7022) @@ -95,6 +95,12 @@ getFactory().addRequestWrapper(request); } + public void setMethod(String method) { + MockHttpServletRequest request = (MockHttpServletRequest)getFactory().getWrappedRequest(); + request.setMethod(method); + getFactory().addRequestWrapper(request); + } + public void setBodyContent(String content) { MockHttpServletRequest request = (MockHttpServletRequest)getFactory().getWrappedRequest(); request.setBodyContent(content); @@ -244,6 +250,7 @@ suite.addTestSuite(ModjyTestInterpreterLifecycle.class); suite.addTestSuite(ModjyTestWebInf.class); suite.addTestSuite(ModjyTestWSGIStreams.class); + suite.addTestSuite(ModjyTestPostData.class); suite.addTestSuite(PyServletTest.class); suite.addTestSuite(PyFilterTest.class); junit.textui.TestRunner.run(suite); Added: trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestPostData.java =================================================================== --- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestPostData.java (rev 0) +++ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestPostData.java 2010-04-12 22:03:17 UTC (rev 7022) @@ -0,0 +1,47 @@ +/*### +# +# Copyright Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://modjy.xhaus.com/LICENSE.txt +# +###*/ + +package com.xhaus.modjy; + +public class ModjyTestPostData extends ModjyTestBase { + + protected void postDataTestSetUp() throws Exception { + baseSetUp(); + setAppFile("post_data_tests.py"); + } + + public void doHeaderTest(String appName, String postData) throws Exception { + postDataTestSetUp(); + setMethod("POST"); + setAppName(appName); + createServlet(); + if (postData != null) + setBodyContent(postData); + doPost(); + } + + public void testPostDataLineEndsNotTranslated() throws Exception { + String testData = "this\r\ndata\r\ncontains\r\ncarriage\r\nreturns\r\n"; + String expectedData = "'"+testData.replace("\r", "\\r").replace("\n", "\\n")+"'"; + doHeaderTest("test_return_post_data", testData); + assertEquals("Wrong post data returned >>" + getOutput() + "<< != >>"+expectedData+"<<", expectedData, getOutput()); + } + +} Added: trunk/jython/tests/modjy/test_apps_dir/post_data_tests.py =================================================================== --- trunk/jython/tests/modjy/test_apps_dir/post_data_tests.py (rev 0) +++ trunk/jython/tests/modjy/test_apps_dir/post_data_tests.py 2010-04-12 22:03:17 UTC (rev 7022) @@ -0,0 +1,31 @@ +# -*- coding: windows-1252 -*- + +### +# +# Copyright Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://modjy.xhaus.com/LICENSE.txt +# +### + +""" + App callables used to test post data +""" + +def test_return_post_data(environ, start_response): + post_data = environ['wsgi.input'].read() + return_value = repr(post_data) + start_response("200 OK", [('content-length', '%s' % len(return_value))]) + return [return_value] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |