1. python_mirrors
  2. jython-fullhistory

Commits

Alan Kennedy  committed 88d508d

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.

  • Participants
  • Parent commits b97b2ba
  • Branches default

Comments (0)

Files changed (6)

File Lib/modjy/modjy_wsgi.py

View file
 
     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)

File src/org/python/core/PyFile.java

View file
         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);
     }

File src/org/python/core/util/FileUtil.java

View file
 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) {

File tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java

View file
         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);
         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);

File tests/modjy/java/com/xhaus/modjy/ModjyTestPostData.java

View file
+/*###
+#
+# 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());
+    }
+
+}

File tests/modjy/test_apps_dir/post_data_tests.py

View file
+# -*- 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]