From: <fwi...@us...> - 2009-03-06 18:27:27
|
Revision: 6075 http://jython.svn.sourceforge.net/jython/?rev=6075&view=rev Author: fwierzbicki Date: 2009-03-06 18:27:15 +0000 (Fri, 06 Mar 2009) Log Message: ----------- Merged revisions 5751,6066-6070 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/branches/modjy Merging Alan Kennedy's amazing modjy project http://modjy.xhaus.com/ into core of Jython Cut the branch comments down to the interesting ones. Thanks Alan! ........ r6068 | amak | 2009-03-05 10:43:01 -0500 (Thu, 05 Mar 2009) | 1 line Modification to the ModjyJServlet to reflect that it is now part of the jython distribution, rather than a standalone product. ........ r6069 | amak | 2009-03-05 10:54:43 -0500 (Thu, 05 Mar 2009) | 3 lines Adding the original modjy demo application to the Demo subdirectory. This application gives the users a complete running application that they can use as a template for aplication development. In the future, we might develop a more sophisticated application. ........ r6070 | amak | 2009-03-05 17:07:35 -0500 (Thu, 05 Mar 2009) | 1 line Committing the unit tests. There is a readme.txt file in the directory which explains how to run the tests, which depend on mockrunner. ........ Added Paths: ----------- trunk/jython/Demo/modjy_webapp/ trunk/jython/Demo/modjy_webapp/WEB-INF/ trunk/jython/Demo/modjy_webapp/WEB-INF/lib/ trunk/jython/Demo/modjy_webapp/WEB-INF/lib-python/ trunk/jython/Demo/modjy_webapp/WEB-INF/lib-python/readme.txt trunk/jython/Demo/modjy_webapp/WEB-INF/web.xml trunk/jython/Demo/modjy_webapp/demo_app.py trunk/jython/Demo/modjy_webapp/readme.txt trunk/jython/Lib/modjy/ trunk/jython/Lib/modjy/__init__.py trunk/jython/Lib/modjy/modjy.py trunk/jython/Lib/modjy/modjy_exceptions.py trunk/jython/Lib/modjy/modjy_impl.py trunk/jython/Lib/modjy/modjy_log.py trunk/jython/Lib/modjy/modjy_params.py trunk/jython/Lib/modjy/modjy_publish.py trunk/jython/Lib/modjy/modjy_response.py trunk/jython/Lib/modjy/modjy_write.py trunk/jython/Lib/modjy/modjy_wsgi.py trunk/jython/src/com/xhaus/ trunk/jython/src/com/xhaus/modjy/ trunk/jython/src/com/xhaus/modjy/ModjyJServlet.java trunk/jython/tests/modjy/ trunk/jython/tests/modjy/__init__.py trunk/jython/tests/modjy/build.xml trunk/jython/tests/modjy/empty.txt trunk/jython/tests/modjy/java/ trunk/jython/tests/modjy/java/com/ trunk/jython/tests/modjy/java/com/xhaus/ trunk/jython/tests/modjy/java/com/xhaus/modjy/ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestContentHeaders.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestEnviron.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestHeaders.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestReturnIterable.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestWSGIStreams.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestWebInf.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestWriteCallable.java trunk/jython/tests/modjy/lib_python_folder/ trunk/jython/tests/modjy/lib_python_folder/__init__.py trunk/jython/tests/modjy/lib_python_folder/add_zips.pth trunk/jython/tests/modjy/lib_python_folder/do_import.pth trunk/jython/tests/modjy/lib_python_folder/mock_framework/ trunk/jython/tests/modjy/lib_python_folder/mock_framework/__init__.py trunk/jython/tests/modjy/lib_python_folder/mock_framework/web/ trunk/jython/tests/modjy/lib_python_folder/mock_framework/web/__init__.py trunk/jython/tests/modjy/lib_python_folder/mock_framework/web/handlers/ trunk/jython/tests/modjy/lib_python_folder/mock_framework/web/handlers/__init__.py trunk/jython/tests/modjy/lib_python_folder/mock_framework/web/handlers/wsgi_handlers.py trunk/jython/tests/modjy/lib_python_folder/script_name_path_info.py trunk/jython/tests/modjy/lib_python_folder/test_lib/ trunk/jython/tests/modjy/lib_python_folder/test_lib/__init__.py trunk/jython/tests/modjy/lib_python_folder/test_lib/some_libs.py trunk/jython/tests/modjy/lib_python_folder/test_modules.zip trunk/jython/tests/modjy/lines.txt trunk/jython/tests/modjy/readme.txt trunk/jython/tests/modjy/test_apps_dir/ trunk/jython/tests/modjy/test_apps_dir/__init__.py trunk/jython/tests/modjy/test_apps_dir/content_header_tests.py trunk/jython/tests/modjy/test_apps_dir/environ_tests.py trunk/jython/tests/modjy/test_apps_dir/header_tests.py trunk/jython/tests/modjy/test_apps_dir/return_tests.py trunk/jython/tests/modjy/test_apps_dir/simple_app.py trunk/jython/tests/modjy/test_apps_dir/stream_tests.py trunk/jython/tests/modjy/test_apps_dir/web_inf_tests.py Removed Paths: ------------- trunk/jython/Demo/modjy_webapp/WEB-INF/ trunk/jython/Demo/modjy_webapp/WEB-INF/lib/ trunk/jython/Demo/modjy_webapp/WEB-INF/lib-python/ trunk/jython/Demo/modjy_webapp/WEB-INF/lib-python/readme.txt trunk/jython/Demo/modjy_webapp/WEB-INF/web.xml trunk/jython/Demo/modjy_webapp/demo_app.py trunk/jython/Demo/modjy_webapp/readme.txt trunk/jython/Lib/modjy/__init__.py trunk/jython/Lib/modjy/modjy.py trunk/jython/Lib/modjy/modjy_exceptions.py trunk/jython/Lib/modjy/modjy_impl.py trunk/jython/Lib/modjy/modjy_log.py trunk/jython/Lib/modjy/modjy_params.py trunk/jython/Lib/modjy/modjy_publish.py trunk/jython/Lib/modjy/modjy_response.py trunk/jython/Lib/modjy/modjy_write.py trunk/jython/Lib/modjy/modjy_wsgi.py trunk/jython/src/com/xhaus/modjy/ trunk/jython/src/com/xhaus/modjy/ModjyJServlet.java trunk/jython/tests/modjy/__init__.py trunk/jython/tests/modjy/build.xml trunk/jython/tests/modjy/empty.txt trunk/jython/tests/modjy/java/ trunk/jython/tests/modjy/java/com/ trunk/jython/tests/modjy/java/com/xhaus/ trunk/jython/tests/modjy/java/com/xhaus/modjy/ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestContentHeaders.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestEnviron.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestHeaders.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestReturnIterable.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestWSGIStreams.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestWebInf.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestWriteCallable.java trunk/jython/tests/modjy/lib_python_folder/ trunk/jython/tests/modjy/lib_python_folder/__init__.py trunk/jython/tests/modjy/lib_python_folder/add_zips.pth trunk/jython/tests/modjy/lib_python_folder/do_import.pth trunk/jython/tests/modjy/lib_python_folder/mock_framework/ trunk/jython/tests/modjy/lib_python_folder/mock_framework/__init__.py trunk/jython/tests/modjy/lib_python_folder/mock_framework/web/ trunk/jython/tests/modjy/lib_python_folder/mock_framework/web/__init__.py trunk/jython/tests/modjy/lib_python_folder/mock_framework/web/handlers/ trunk/jython/tests/modjy/lib_python_folder/mock_framework/web/handlers/__init__.py trunk/jython/tests/modjy/lib_python_folder/mock_framework/web/handlers/wsgi_handlers.py trunk/jython/tests/modjy/lib_python_folder/script_name_path_info.py trunk/jython/tests/modjy/lib_python_folder/test_lib/ trunk/jython/tests/modjy/lib_python_folder/test_lib/__init__.py trunk/jython/tests/modjy/lib_python_folder/test_lib/some_libs.py trunk/jython/tests/modjy/lib_python_folder/test_modules.zip trunk/jython/tests/modjy/lines.txt trunk/jython/tests/modjy/readme.txt trunk/jython/tests/modjy/test_apps_dir/ trunk/jython/tests/modjy/test_apps_dir/__init__.py trunk/jython/tests/modjy/test_apps_dir/content_header_tests.py trunk/jython/tests/modjy/test_apps_dir/environ_tests.py trunk/jython/tests/modjy/test_apps_dir/header_tests.py trunk/jython/tests/modjy/test_apps_dir/return_tests.py trunk/jython/tests/modjy/test_apps_dir/simple_app.py trunk/jython/tests/modjy/test_apps_dir/stream_tests.py trunk/jython/tests/modjy/test_apps_dir/web_inf_tests.py Property Changed: ---------------- trunk/jython/ Property changes on: trunk/jython ___________________________________________________________________ Modified: svnmerge-integrated - /branches/modjy:1-5750 /branches/pbcvm:1-6045 + /branches/modjy:1-6074 /branches/pbcvm:1-6045 Deleted: trunk/jython/Demo/modjy_webapp/WEB-INF/lib-python/readme.txt =================================================================== --- branches/modjy/Demo/modjy_webapp/WEB-INF/lib-python/readme.txt 2009-03-05 22:07:35 UTC (rev 6070) +++ trunk/jython/Demo/modjy_webapp/WEB-INF/lib-python/readme.txt 2009-03-06 18:27:15 UTC (rev 6075) @@ -1,11 +0,0 @@ -The WEB-INF/lib-python directory, if it exists, is automatically added -to sys.path. Adding jython modules into this directory will make them -available for import into your application. - -If you add your modules in a subdirectory, then be sure that that -subdirectory contains an __init__.py file, so that the subdirectory -is considered to be a package. - -See here for more details. -http://www.rexx.com/~dkuhlman/python_101/python_101.html#SECTION004540000000000000000 -http://www.python.org/doc/essays/packages.html Copied: trunk/jython/Demo/modjy_webapp/WEB-INF/lib-python/readme.txt (from rev 6070, branches/modjy/Demo/modjy_webapp/WEB-INF/lib-python/readme.txt) =================================================================== --- trunk/jython/Demo/modjy_webapp/WEB-INF/lib-python/readme.txt (rev 0) +++ trunk/jython/Demo/modjy_webapp/WEB-INF/lib-python/readme.txt 2009-03-06 18:27:15 UTC (rev 6075) @@ -0,0 +1,11 @@ +The WEB-INF/lib-python directory, if it exists, is automatically added +to sys.path. Adding jython modules into this directory will make them +available for import into your application. + +If you add your modules in a subdirectory, then be sure that that +subdirectory contains an __init__.py file, so that the subdirectory +is considered to be a package. + +See here for more details. +http://www.rexx.com/~dkuhlman/python_101/python_101.html#SECTION004540000000000000000 +http://www.python.org/doc/essays/packages.html Deleted: trunk/jython/Demo/modjy_webapp/WEB-INF/web.xml =================================================================== --- branches/modjy/Demo/modjy_webapp/WEB-INF/web.xml 2009-03-05 22:07:35 UTC (rev 6070) +++ trunk/jython/Demo/modjy_webapp/WEB-INF/web.xml 2009-03-06 18:27:15 UTC (rev 6075) @@ -1,85 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> -<!DOCTYPE web-app - PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" - "http://java.sun.com/dtd/web-app_2_3.dtd"> -<web-app> - - <display-name>modjy demo application</display-name> - <description> - modjy WSGI demo application - </description> - - <servlet> - <servlet-name>modjy</servlet-name> - <servlet-class>com.xhaus.modjy.ModjyJServlet</servlet-class> - <init-param> - <param-name>python.home</param-name> - <param-value>C:/jython2.5</param-value> - </init-param> -<!-- - There are two different ways you can specify an application to modjy - 1. Using the app_import_name mechanism - 2. Using a combination of app_directory/app_filename/app_callable_name - Examples of both are given below - See the documenation for more details. - http://modjy.xhaus.com/locating.html#locating_callables ---> -<!-- - This is the app_import_name mechanism. If you specify a value - for this variable, then it will take precedence over the other mechanism - <init-param> - <param-name>app_import_name</param-name> - <param-value>my_wsgi_module.my_handler_class().handler_method</param-value> - </init-param> ---> -<!-- - And this is the app_directory/app_filename/app_callable_name combo - The defaults for these three variables are ""/application.py/handler - So if you specify no values at all for any of app_* variables, then modjy - will by default look for "handler" in "application.py" in the servlet - context root. - <init-param> - <param-name>app_directory</param-name> - <param-value>some_sub_directory</param-value> - </init-param> ---> - <init-param> - <param-name>app_filename</param-name> - <param-value>demo_app.py</param-value> - </init-param> -<!-- - Supply a value for this parameter if you want your application - callable to have a different name than the default. - <init-param> - <param-name>app_callable_name</param-name> - <param-value>my_handler_func</param-value> - </init-param> ---> - <!-- Do you want application callables to be cached? --> - <init-param> - <param-name>cache_callables</param-name> - <param-value>1</param-value> - </init-param> - <!-- Should the application be reloaded if it's .py file changes? --> - <!-- Does not work with the app_import_name mechanism --> - <init-param> - <param-name>reload_on_mod</param-name> - <param-value>1</param-value> - </init-param> - <init-param> - <param-name>log_level</param-name> - <param-value>debug</param-value> -<!-- <param-value>info</param-value> --> -<!-- <param-value>warn</param-value> --> -<!-- <param-value>error</param-value> --> -<!-- <param-value>fatal</param-value> --> - </init-param> - <load-on-startup>1</load-on-startup> - </servlet> - - <servlet-mapping> - <servlet-name>modjy</servlet-name> - <url-pattern>/*</url-pattern> - </servlet-mapping> - -</web-app> Copied: trunk/jython/Demo/modjy_webapp/WEB-INF/web.xml (from rev 6070, branches/modjy/Demo/modjy_webapp/WEB-INF/web.xml) =================================================================== --- trunk/jython/Demo/modjy_webapp/WEB-INF/web.xml (rev 0) +++ trunk/jython/Demo/modjy_webapp/WEB-INF/web.xml 2009-03-06 18:27:15 UTC (rev 6075) @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!DOCTYPE web-app + PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" + "http://java.sun.com/dtd/web-app_2_3.dtd"> +<web-app> + + <display-name>modjy demo application</display-name> + <description> + modjy WSGI demo application + </description> + + <servlet> + <servlet-name>modjy</servlet-name> + <servlet-class>com.xhaus.modjy.ModjyJServlet</servlet-class> + <init-param> + <param-name>python.home</param-name> + <param-value>C:/jython2.5</param-value> + </init-param> +<!-- + There are two different ways you can specify an application to modjy + 1. Using the app_import_name mechanism + 2. Using a combination of app_directory/app_filename/app_callable_name + Examples of both are given below + See the documenation for more details. + http://modjy.xhaus.com/locating.html#locating_callables +--> +<!-- + This is the app_import_name mechanism. If you specify a value + for this variable, then it will take precedence over the other mechanism + <init-param> + <param-name>app_import_name</param-name> + <param-value>my_wsgi_module.my_handler_class().handler_method</param-value> + </init-param> +--> +<!-- + And this is the app_directory/app_filename/app_callable_name combo + The defaults for these three variables are ""/application.py/handler + So if you specify no values at all for any of app_* variables, then modjy + will by default look for "handler" in "application.py" in the servlet + context root. + <init-param> + <param-name>app_directory</param-name> + <param-value>some_sub_directory</param-value> + </init-param> +--> + <init-param> + <param-name>app_filename</param-name> + <param-value>demo_app.py</param-value> + </init-param> +<!-- + Supply a value for this parameter if you want your application + callable to have a different name than the default. + <init-param> + <param-name>app_callable_name</param-name> + <param-value>my_handler_func</param-value> + </init-param> +--> + <!-- Do you want application callables to be cached? --> + <init-param> + <param-name>cache_callables</param-name> + <param-value>1</param-value> + </init-param> + <!-- Should the application be reloaded if it's .py file changes? --> + <!-- Does not work with the app_import_name mechanism --> + <init-param> + <param-name>reload_on_mod</param-name> + <param-value>1</param-value> + </init-param> + <init-param> + <param-name>log_level</param-name> + <param-value>debug</param-value> +<!-- <param-value>info</param-value> --> +<!-- <param-value>warn</param-value> --> +<!-- <param-value>error</param-value> --> +<!-- <param-value>fatal</param-value> --> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + + <servlet-mapping> + <servlet-name>modjy</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + +</web-app> Deleted: trunk/jython/Demo/modjy_webapp/demo_app.py =================================================================== --- branches/modjy/Demo/modjy_webapp/demo_app.py 2009-03-05 22:07:35 UTC (rev 6070) +++ trunk/jython/Demo/modjy_webapp/demo_app.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -1,37 +0,0 @@ -import sys - -def escape_html(s): return s.replace('&', '&').replace('<', '<').replace('>', '>') - -def cutoff(s, n=100): - if len(s) > n: return s[:n]+ '.. cut ..' - return s - -def handler(environ, start_response): - writer = start_response("200 OK", [ ('content-type', 'text/html') ]) - response_parts = [] - response_parts.append("<html>") - response_parts.append("<head>") - response_parts.append("<title>Modjy demo application</title>") - response_parts.append("</head>") - response_parts.append("<body>") - response_parts.append("<p>Modjy servlet running correctly: jython %s on %s:</p>" % (sys.version, sys.platform)) - response_parts.append("<h3>Hello WSGI World!</h3>") - response_parts.append("<h4>Here are the contents of the WSGI environment</h4>") - environ_str = "<table border='1'>" - keys = environ.keys() - keys.sort() - for ix, name in enumerate(keys): - if ix % 2: - background='#ffffff' - else: - background='#eeeeee' - style = " style='background-color:%s;'" % background - value = escape_html(cutoff(str(environ[name]))) or ' ' - environ_str = "%s\n<tr><td%s>%s</td><td%s>%s</td></tr>" % \ - (environ_str, style, name, style, value) - environ_str = "%s\n</table>" % environ_str - response_parts.append(environ_str) - response_parts.append("</body>") - response_parts.append("</html>") - response_text = "\n".join(response_parts) - return [response_text] Copied: trunk/jython/Demo/modjy_webapp/demo_app.py (from rev 6070, branches/modjy/Demo/modjy_webapp/demo_app.py) =================================================================== --- trunk/jython/Demo/modjy_webapp/demo_app.py (rev 0) +++ trunk/jython/Demo/modjy_webapp/demo_app.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -0,0 +1,37 @@ +import sys + +def escape_html(s): return s.replace('&', '&').replace('<', '<').replace('>', '>') + +def cutoff(s, n=100): + if len(s) > n: return s[:n]+ '.. cut ..' + return s + +def handler(environ, start_response): + writer = start_response("200 OK", [ ('content-type', 'text/html') ]) + response_parts = [] + response_parts.append("<html>") + response_parts.append("<head>") + response_parts.append("<title>Modjy demo application</title>") + response_parts.append("</head>") + response_parts.append("<body>") + response_parts.append("<p>Modjy servlet running correctly: jython %s on %s:</p>" % (sys.version, sys.platform)) + response_parts.append("<h3>Hello WSGI World!</h3>") + response_parts.append("<h4>Here are the contents of the WSGI environment</h4>") + environ_str = "<table border='1'>" + keys = environ.keys() + keys.sort() + for ix, name in enumerate(keys): + if ix % 2: + background='#ffffff' + else: + background='#eeeeee' + style = " style='background-color:%s;'" % background + value = escape_html(cutoff(str(environ[name]))) or ' ' + environ_str = "%s\n<tr><td%s>%s</td><td%s>%s</td></tr>" % \ + (environ_str, style, name, style, value) + environ_str = "%s\n</table>" % environ_str + response_parts.append(environ_str) + response_parts.append("</body>") + response_parts.append("</html>") + response_text = "\n".join(response_parts) + return [response_text] Deleted: trunk/jython/Demo/modjy_webapp/readme.txt =================================================================== --- branches/modjy/Demo/modjy_webapp/readme.txt 2009-03-05 22:07:35 UTC (rev 6070) +++ trunk/jython/Demo/modjy_webapp/readme.txt 2009-03-06 18:27:15 UTC (rev 6075) @@ -1,15 +0,0 @@ -To deploy this application - -1. Copy the jython.jar file into the WEB-INF/lib subdirectory -2. Set the value of python.home property in WEB-INF/web.xml so - that it points to your jython installation. -3. Copy this directory to the applications directory of your servlet - container. On Apache Tomcat, this is the "webapps" subdirectory - of the tomcat install directory. -4. Enter the URL http://localhost:8080/modjy_webapp into your - browser. -5. You should see a table containing the WSGI environment. - -Please see the installation documentation for more details. - -http://modjy.xhaus.com/install.html Copied: trunk/jython/Demo/modjy_webapp/readme.txt (from rev 6070, branches/modjy/Demo/modjy_webapp/readme.txt) =================================================================== --- trunk/jython/Demo/modjy_webapp/readme.txt (rev 0) +++ trunk/jython/Demo/modjy_webapp/readme.txt 2009-03-06 18:27:15 UTC (rev 6075) @@ -0,0 +1,15 @@ +To deploy this application + +1. Copy the jython.jar file into the WEB-INF/lib subdirectory +2. Set the value of python.home property in WEB-INF/web.xml so + that it points to your jython installation. +3. Copy this directory to the applications directory of your servlet + container. On Apache Tomcat, this is the "webapps" subdirectory + of the tomcat install directory. +4. Enter the URL http://localhost:8080/modjy_webapp into your + browser. +5. You should see a table containing the WSGI environment. + +Please see the installation documentation for more details. + +http://modjy.xhaus.com/install.html Deleted: trunk/jython/Lib/modjy/__init__.py =================================================================== --- branches/modjy/Lib/modjy/__init__.py 2009-03-05 22:07:35 UTC (rev 6070) +++ trunk/jython/Lib/modjy/__init__.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -1,22 +0,0 @@ -### -# -# 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 -# -### - -__all__ = ['modjy', 'modjy_exceptions', 'modjy_impl', 'modjy_log', 'modjy_params', 'modjy_publish', 'modjy_response', 'modjy_write', 'modjy_wsgi',] - Copied: trunk/jython/Lib/modjy/__init__.py (from rev 6070, branches/modjy/Lib/modjy/__init__.py) =================================================================== --- trunk/jython/Lib/modjy/__init__.py (rev 0) +++ trunk/jython/Lib/modjy/__init__.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -0,0 +1,22 @@ +### +# +# 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 +# +### + +__all__ = ['modjy', 'modjy_exceptions', 'modjy_impl', 'modjy_log', 'modjy_params', 'modjy_publish', 'modjy_response', 'modjy_write', 'modjy_wsgi',] + Deleted: trunk/jython/Lib/modjy/modjy.py =================================================================== --- branches/modjy/Lib/modjy/modjy.py 2009-03-05 22:07:35 UTC (rev 6070) +++ trunk/jython/Lib/modjy/modjy.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -1,121 +0,0 @@ -### -# -# 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 -# -### - -import jarray -import synchronize -import sys -import types - -sys.add_package("javax.servlet") -sys.add_package("javax.servlet.http") -sys.add_package("org.python.core") - -from modjy_exceptions import * -from modjy_log import * -from modjy_params import modjy_param_mgr, modjy_servlet_params -from modjy_wsgi import modjy_wsgi -from modjy_response import start_response_object -from modjy_impl import modjy_impl -from modjy_publish import modjy_publisher - -from javax.servlet.http import HttpServlet - -class modjy_servlet(HttpServlet, modjy_publisher, modjy_wsgi, modjy_impl): - - def __init__(self): - HttpServlet.__init__(self) - - def do_param(self, name, value): - if name[:3] == 'log': - getattr(self.log, "set_%s" % name)(value) - else: - self.params[name] = value - - def process_param_container(self, param_container): - param_enum = param_container.getInitParameterNames() - while param_enum.hasMoreElements(): - param_name = param_enum.nextElement() - self.do_param(param_name, param_container.getInitParameter(param_name)) - - def get_params(self): - self.process_param_container(self.servlet_context) - self.process_param_container(self.servlet) - - def init(self, delegator): - self.servlet = delegator - self.servlet_context = self.servlet.getServletContext() - self.servlet_config = self.servlet.getServletConfig() - self.log = modjy_logger(self.servlet_context) - self.params = modjy_param_mgr(modjy_servlet_params) - self.get_params() - self.init_impl() - self.init_publisher() - import modjy_exceptions - self.exc_handler = getattr(modjy_exceptions, '%s_handler' % self.params['exc_handler'])() - - def service (self, req, resp): - wsgi_environ = {} - try: - self.dispatch_to_application(req, resp, wsgi_environ) - except ModjyException, mx: - self.log.error("Exception servicing request: %s" % str(mx)) - typ, value, tb = sys.exc_info()[:] - self.exc_handler.handle(req, resp, wsgi_environ, mx, (typ, value, tb) ) - - def get_j2ee_ns(self, req, resp): - return { - 'servlet': self.servlet, - 'servlet_context': self.servlet_context, - 'servlet_config': self.servlet_config, - 'request': req, - 'response': resp, - } - - def dispatch_to_application(self, req, resp, environ): - app_callable = self.get_app_object(req, environ) - self.set_wsgi_environment(req, resp, environ, self.params, self.get_j2ee_ns(req, resp)) - response_callable = start_response_object(req, resp) - try: - app_return = self.call_application(app_callable, environ, response_callable) - if app_return is None: - raise ReturnNotIterable("Application returned None: must return an iterable") - self.deal_with_app_return(environ, response_callable, app_return) - except ModjyException, mx: - self.raise_exc(mx.__class__, str(mx)) - except Exception, x: - self.raise_exc(ApplicationException, str(x)) - - def call_application(self, app_callable, environ, response_callable): - if self.params['multithread']: - return app_callable.__call__(environ, response_callable) - else: - return synchronize.apply_synchronized( \ - app_callable, \ - app_callable, \ - (environ, response_callable)) - - def expand_relative_path(self, path): - if path.startswith("$"): - return self.servlet.getServletContext().getRealPath(path[1:]) - return path - - def raise_exc(self, exc_class, message): - self.log.error(message) - raise exc_class(message) Copied: trunk/jython/Lib/modjy/modjy.py (from rev 6070, branches/modjy/Lib/modjy/modjy.py) =================================================================== --- trunk/jython/Lib/modjy/modjy.py (rev 0) +++ trunk/jython/Lib/modjy/modjy.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -0,0 +1,121 @@ +### +# +# 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 +# +### + +import jarray +import synchronize +import sys +import types + +sys.add_package("javax.servlet") +sys.add_package("javax.servlet.http") +sys.add_package("org.python.core") + +from modjy_exceptions import * +from modjy_log import * +from modjy_params import modjy_param_mgr, modjy_servlet_params +from modjy_wsgi import modjy_wsgi +from modjy_response import start_response_object +from modjy_impl import modjy_impl +from modjy_publish import modjy_publisher + +from javax.servlet.http import HttpServlet + +class modjy_servlet(HttpServlet, modjy_publisher, modjy_wsgi, modjy_impl): + + def __init__(self): + HttpServlet.__init__(self) + + def do_param(self, name, value): + if name[:3] == 'log': + getattr(self.log, "set_%s" % name)(value) + else: + self.params[name] = value + + def process_param_container(self, param_container): + param_enum = param_container.getInitParameterNames() + while param_enum.hasMoreElements(): + param_name = param_enum.nextElement() + self.do_param(param_name, param_container.getInitParameter(param_name)) + + def get_params(self): + self.process_param_container(self.servlet_context) + self.process_param_container(self.servlet) + + def init(self, delegator): + self.servlet = delegator + self.servlet_context = self.servlet.getServletContext() + self.servlet_config = self.servlet.getServletConfig() + self.log = modjy_logger(self.servlet_context) + self.params = modjy_param_mgr(modjy_servlet_params) + self.get_params() + self.init_impl() + self.init_publisher() + import modjy_exceptions + self.exc_handler = getattr(modjy_exceptions, '%s_handler' % self.params['exc_handler'])() + + def service (self, req, resp): + wsgi_environ = {} + try: + self.dispatch_to_application(req, resp, wsgi_environ) + except ModjyException, mx: + self.log.error("Exception servicing request: %s" % str(mx)) + typ, value, tb = sys.exc_info()[:] + self.exc_handler.handle(req, resp, wsgi_environ, mx, (typ, value, tb) ) + + def get_j2ee_ns(self, req, resp): + return { + 'servlet': self.servlet, + 'servlet_context': self.servlet_context, + 'servlet_config': self.servlet_config, + 'request': req, + 'response': resp, + } + + def dispatch_to_application(self, req, resp, environ): + app_callable = self.get_app_object(req, environ) + self.set_wsgi_environment(req, resp, environ, self.params, self.get_j2ee_ns(req, resp)) + response_callable = start_response_object(req, resp) + try: + app_return = self.call_application(app_callable, environ, response_callable) + if app_return is None: + raise ReturnNotIterable("Application returned None: must return an iterable") + self.deal_with_app_return(environ, response_callable, app_return) + except ModjyException, mx: + self.raise_exc(mx.__class__, str(mx)) + except Exception, x: + self.raise_exc(ApplicationException, str(x)) + + def call_application(self, app_callable, environ, response_callable): + if self.params['multithread']: + return app_callable.__call__(environ, response_callable) + else: + return synchronize.apply_synchronized( \ + app_callable, \ + app_callable, \ + (environ, response_callable)) + + def expand_relative_path(self, path): + if path.startswith("$"): + return self.servlet.getServletContext().getRealPath(path[1:]) + return path + + def raise_exc(self, exc_class, message): + self.log.error(message) + raise exc_class(message) Deleted: trunk/jython/Lib/modjy/modjy_exceptions.py =================================================================== --- branches/modjy/Lib/modjy/modjy_exceptions.py 2009-03-05 22:07:35 UTC (rev 6070) +++ trunk/jython/Lib/modjy/modjy_exceptions.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -1,91 +0,0 @@ -### -# -# 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 -# -### - -import sys -import StringIO -import traceback - -from java.lang import IllegalStateException -from java.io import IOException -from javax.servlet import ServletException - -class ModjyException(Exception): pass - -class ModjyIOException(ModjyException): pass - -class ConfigException(ModjyException): pass -class BadParameter(ConfigException): pass -class ApplicationNotFound(ConfigException): pass -class NoCallable(ConfigException): pass - -class RequestException(ModjyException): pass - -class ApplicationException(ModjyException): pass -class StartResponseNotCalled(ApplicationException): pass -class StartResponseCalledTwice(ApplicationException): pass -class ResponseCommitted(ApplicationException): pass -class HopByHopHeaderSet(ApplicationException): pass -class WrongLength(ApplicationException): pass -class BadArgument(ApplicationException): pass -class ReturnNotIterable(ApplicationException): pass -class NonStringOutput(ApplicationException): pass - -class exception_handler: - - def handle(self, req, resp, environ, exc, exc_info): - pass - - def get_status_and_message(self, req, resp, exc): - return resp.SC_INTERNAL_SERVER_ERROR, "Server configuration error" - -# -# Special exception handler for testing -# - -class testing_handler(exception_handler): - - def handle(self, req, resp, environ, exc, exc_info): - typ, value, tb = exc_info - err_msg = StringIO.StringIO() - err_msg.write("%s: %s\n" % (typ, value,) ) - err_msg.write(">Environment\n") - for k in environ.keys(): - err_msg.write("%s=%s\n" % (k, repr(environ[k])) ) - err_msg.write("<Environment\n") - err_msg.write(">TraceBack\n") - for line in traceback.format_exception(typ, value, tb): - err_msg.write(line) - err_msg.write("<TraceBack\n") - try: - status, message = self.get_status_and_message(req, resp, exc) - resp.setStatus(status) - resp.setContentLength(len(err_msg.getvalue())) - resp.getOutputStream().write(err_msg.getvalue()) - except IllegalStateException, ise: - raise exc # Let the container deal with it - -# -# Standard exception handler -# - -class standard_handler(exception_handler): - - def handle(self, req, resp, environ, exc, exc_info): - raise exc_info[0], exc_info[1], exc_info[2] Copied: trunk/jython/Lib/modjy/modjy_exceptions.py (from rev 6070, branches/modjy/Lib/modjy/modjy_exceptions.py) =================================================================== --- trunk/jython/Lib/modjy/modjy_exceptions.py (rev 0) +++ trunk/jython/Lib/modjy/modjy_exceptions.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -0,0 +1,91 @@ +### +# +# 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 +# +### + +import sys +import StringIO +import traceback + +from java.lang import IllegalStateException +from java.io import IOException +from javax.servlet import ServletException + +class ModjyException(Exception): pass + +class ModjyIOException(ModjyException): pass + +class ConfigException(ModjyException): pass +class BadParameter(ConfigException): pass +class ApplicationNotFound(ConfigException): pass +class NoCallable(ConfigException): pass + +class RequestException(ModjyException): pass + +class ApplicationException(ModjyException): pass +class StartResponseNotCalled(ApplicationException): pass +class StartResponseCalledTwice(ApplicationException): pass +class ResponseCommitted(ApplicationException): pass +class HopByHopHeaderSet(ApplicationException): pass +class WrongLength(ApplicationException): pass +class BadArgument(ApplicationException): pass +class ReturnNotIterable(ApplicationException): pass +class NonStringOutput(ApplicationException): pass + +class exception_handler: + + def handle(self, req, resp, environ, exc, exc_info): + pass + + def get_status_and_message(self, req, resp, exc): + return resp.SC_INTERNAL_SERVER_ERROR, "Server configuration error" + +# +# Special exception handler for testing +# + +class testing_handler(exception_handler): + + def handle(self, req, resp, environ, exc, exc_info): + typ, value, tb = exc_info + err_msg = StringIO.StringIO() + err_msg.write("%s: %s\n" % (typ, value,) ) + err_msg.write(">Environment\n") + for k in environ.keys(): + err_msg.write("%s=%s\n" % (k, repr(environ[k])) ) + err_msg.write("<Environment\n") + err_msg.write(">TraceBack\n") + for line in traceback.format_exception(typ, value, tb): + err_msg.write(line) + err_msg.write("<TraceBack\n") + try: + status, message = self.get_status_and_message(req, resp, exc) + resp.setStatus(status) + resp.setContentLength(len(err_msg.getvalue())) + resp.getOutputStream().write(err_msg.getvalue()) + except IllegalStateException, ise: + raise exc # Let the container deal with it + +# +# Standard exception handler +# + +class standard_handler(exception_handler): + + def handle(self, req, resp, environ, exc, exc_info): + raise exc_info[0], exc_info[1], exc_info[2] Deleted: trunk/jython/Lib/modjy/modjy_impl.py =================================================================== --- branches/modjy/Lib/modjy/modjy_impl.py 2009-03-05 22:07:35 UTC (rev 6070) +++ trunk/jython/Lib/modjy/modjy_impl.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -1,101 +0,0 @@ -### -# -# 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 -# -### - -import types -import sys - -from modjy_exceptions import * - -class modjy_impl: - - def deal_with_app_return(self, environ, start_response_callable, app_return): - self.log.debug("Processing app return type: %s" % str(type(app_return))) - if isinstance(app_return, types.StringTypes): - raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) - if type(app_return) is types.FileType: - pass # TBD: What to do here? can't call fileno() - if hasattr(app_return, '__len__') and callable(app_return.__len__): - expected_pieces = app_return.__len__() - else: - expected_pieces = -1 - try: - try: - ix = 0 - for next_piece in app_return: - if not isinstance(next_piece, types.StringTypes): - raise NonStringOutput("Application returned iterable containing non-strings: %s" % str(type(next_piece))) - if ix == 0: - # The application may have called start_response in the first iteration - if not start_response_callable.called: - raise StartResponseNotCalled("Start_response callable was never called.") - if not start_response_callable.content_length \ - and expected_pieces == 1 \ - and start_response_callable.write_callable.num_writes == 0: - # Take the length of the first piece - start_response_callable.set_content_length(len(next_piece)) - start_response_callable.write_callable(next_piece) - ix += 1 - if ix == expected_pieces: - break - if expected_pieces != -1 and ix != expected_pieces: - raise WrongLength("Iterator len() was wrong. Expected %d pieces: got %d" % (expected_pieces, ix) ) - except AttributeError, ax: - if str(ax) == "__getitem__": - raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) - else: - raise ax - except TypeError, tx: - raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) - except ModjyException, mx: - raise mx - except Exception, x: - raise ApplicationException(x) - finally: - if hasattr(app_return, 'close') and callable(app_return.close): - app_return.close() - - def init_impl(self): - self.do_j_env_params() - - def add_packages(self, package_list): - packages = [p.strip() for p in package_list.split(';')] - for p in packages: - self.log.info("Adding java package %s to jython" % p) - sys.add_package(p) - - def add_classdirs(self, classdir_list): - classdirs = [cd.strip() for cd in classdir_list.split(';')] - for cd in classdirs: - self.log.info("Adding directory %s to jython class file search path" % cd) - sys.add_classdir(cd) - - def add_extdirs(self, extdir_list): - extdirs = [ed.strip() for ed in extdir_list.split(';')] - for ed in extdirs: - self.log.info("Adding directory %s for .jars and .zips search path" % ed) - sys.add_extdir(self.expand_relative_path(ed)) - - def do_j_env_params(self): - if self.params['packages']: - self.add_packages(self.params['packages']) - if self.params['classdirs']: - self.add_classdirs(self.params['classdirs']) - if self.params['extdirs']: - self.add_extdirs(self.params['extdirs']) Copied: trunk/jython/Lib/modjy/modjy_impl.py (from rev 6070, branches/modjy/Lib/modjy/modjy_impl.py) =================================================================== --- trunk/jython/Lib/modjy/modjy_impl.py (rev 0) +++ trunk/jython/Lib/modjy/modjy_impl.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -0,0 +1,101 @@ +### +# +# 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 +# +### + +import types +import sys + +from modjy_exceptions import * + +class modjy_impl: + + def deal_with_app_return(self, environ, start_response_callable, app_return): + self.log.debug("Processing app return type: %s" % str(type(app_return))) + if isinstance(app_return, types.StringTypes): + raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) + if type(app_return) is types.FileType: + pass # TBD: What to do here? can't call fileno() + if hasattr(app_return, '__len__') and callable(app_return.__len__): + expected_pieces = app_return.__len__() + else: + expected_pieces = -1 + try: + try: + ix = 0 + for next_piece in app_return: + if not isinstance(next_piece, types.StringTypes): + raise NonStringOutput("Application returned iterable containing non-strings: %s" % str(type(next_piece))) + if ix == 0: + # The application may have called start_response in the first iteration + if not start_response_callable.called: + raise StartResponseNotCalled("Start_response callable was never called.") + if not start_response_callable.content_length \ + and expected_pieces == 1 \ + and start_response_callable.write_callable.num_writes == 0: + # Take the length of the first piece + start_response_callable.set_content_length(len(next_piece)) + start_response_callable.write_callable(next_piece) + ix += 1 + if ix == expected_pieces: + break + if expected_pieces != -1 and ix != expected_pieces: + raise WrongLength("Iterator len() was wrong. Expected %d pieces: got %d" % (expected_pieces, ix) ) + except AttributeError, ax: + if str(ax) == "__getitem__": + raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) + else: + raise ax + except TypeError, tx: + raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) + except ModjyException, mx: + raise mx + except Exception, x: + raise ApplicationException(x) + finally: + if hasattr(app_return, 'close') and callable(app_return.close): + app_return.close() + + def init_impl(self): + self.do_j_env_params() + + def add_packages(self, package_list): + packages = [p.strip() for p in package_list.split(';')] + for p in packages: + self.log.info("Adding java package %s to jython" % p) + sys.add_package(p) + + def add_classdirs(self, classdir_list): + classdirs = [cd.strip() for cd in classdir_list.split(';')] + for cd in classdirs: + self.log.info("Adding directory %s to jython class file search path" % cd) + sys.add_classdir(cd) + + def add_extdirs(self, extdir_list): + extdirs = [ed.strip() for ed in extdir_list.split(';')] + for ed in extdirs: + self.log.info("Adding directory %s for .jars and .zips search path" % ed) + sys.add_extdir(self.expand_relative_path(ed)) + + def do_j_env_params(self): + if self.params['packages']: + self.add_packages(self.params['packages']) + if self.params['classdirs']: + self.add_classdirs(self.params['classdirs']) + if self.params['extdirs']: + self.add_extdirs(self.params['extdirs']) Deleted: trunk/jython/Lib/modjy/modjy_log.py =================================================================== --- branches/modjy/Lib/modjy/modjy_log.py 2009-03-05 22:07:35 UTC (rev 6070) +++ trunk/jython/Lib/modjy/modjy_log.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -1,80 +0,0 @@ -### -# -# 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 -# -### - -import java - -import sys - -DEBUG = 'debug' -INFO = 'info' -WARN = 'warn' -ERROR = 'error' -FATAL = 'fatal' - -levels_dict = {} -ix = 0 -for level in [DEBUG, INFO, WARN, ERROR, FATAL, ]: - levels_dict[level]=ix - ix += 1 - -class modjy_logger: - - def __init__(self, context): - self.log_ctx = context - self.format_str = "%(lvl)s:\t%(msg)s" - self.log_level = levels_dict[DEBUG] - - def _log(self, level, level_str, msg, exc): - if level >= self.log_level: - msg = self.format_str % {'lvl': level_str, 'msg': msg, } - if exc: -# java.lang.System.err.println(msg, exc) - self.log_ctx.log(msg, exc) - else: -# java.lang.System.err.println(msg) - self.log_ctx.log(msg) - - def debug(self, msg, exc=None): - self._log(0, DEBUG, msg, exc) - - def info(self, msg, exc=None): - self._log(1, INFO, msg, exc) - - def warn(self, msg, exc=None): - self._log(2, WARN, msg, exc) - - def error(self, msg, exc=None): - self._log(3, ERROR, msg, exc) - - def fatal(self, msg, exc=None): - self._log(4, FATAL, msg, exc) - - def set_log_level(self, level_string): - try: - self.log_level = levels_dict[level_string] - except KeyError: - raise BadParameter("Invalid log level: '%s'" % level_string) - - def set_log_format(self, format_string): - # BUG! Format string never actually used in this function. - try: - self._log(debug, "This is a log formatting test", None) - except KeyError: - raise BadParameter("Bad format string: '%s'" % format_string) Copied: trunk/jython/Lib/modjy/modjy_log.py (from rev 6070, branches/modjy/Lib/modjy/modjy_log.py) =================================================================== --- trunk/jython/Lib/modjy/modjy_log.py (rev 0) +++ trunk/jython/Lib/modjy/modjy_log.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -0,0 +1,80 @@ +### +# +# 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 +# +### + +import java + +import sys + +DEBUG = 'debug' +INFO = 'info' +WARN = 'warn' +ERROR = 'error' +FATAL = 'fatal' + +levels_dict = {} +ix = 0 +for level in [DEBUG, INFO, WARN, ERROR, FATAL, ]: + levels_dict[level]=ix + ix += 1 + +class modjy_logger: + + def __init__(self, context): + self.log_ctx = context + self.format_str = "%(lvl)s:\t%(msg)s" + self.log_level = levels_dict[DEBUG] + + def _log(self, level, level_str, msg, exc): + if level >= self.log_level: + msg = self.format_str % {'lvl': level_str, 'msg': msg, } + if exc: +# java.lang.System.err.println(msg, exc) + self.log_ctx.log(msg, exc) + else: +# java.lang.System.err.println(msg) + self.log_ctx.log(msg) + + def debug(self, msg, exc=None): + self._log(0, DEBUG, msg, exc) + + def info(self, msg, exc=None): + self._log(1, INFO, msg, exc) + + def warn(self, msg, exc=None): + self._log(2, WARN, msg, exc) + + def error(self, msg, exc=None): + self._log(3, ERROR, msg, exc) + + def fatal(self, msg, exc=None): + self._log(4, FATAL, msg, exc) + + def set_log_level(self, level_string): + try: + self.log_level = levels_dict[level_string] + except KeyError: + raise BadParameter("Invalid log level: '%s'" % level_string) + + def set_log_format(self, format_string): + # BUG! Format string never actually used in this function. + try: + self._log(debug, "This is a log formatting test", None) + except KeyError: + raise BadParameter("Bad format string: '%s'" % format_string) Deleted: trunk/jython/Lib/modjy/modjy_params.py =================================================================== --- branches/modjy/Lib/modjy/modjy_params.py 2009-03-05 22:07:35 UTC (rev 6070) +++ trunk/jython/Lib/modjy/modjy_params.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -1,84 +0,0 @@ -### -# -# 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 -# -### - -from UserDict import UserDict - -BOOLEAN = ('boolean', int) -INTEGER = ('integer', int) -FLOAT = ('float', float) -STRING = ('string', None) - -modjy_servlet_params = { - - 'multithread': (BOOLEAN, 1), - 'cache_callables': (BOOLEAN, 1), - 'reload_on_mod': (BOOLEAN, 0), - - 'app_import_name': (STRING, None), - - 'app_directory': (STRING, None), - 'app_filename': (STRING, 'application.py'), - 'app_callable_name': (STRING, 'handler'), - 'callable_query_name': (STRING, None), - - 'exc_handler': (STRING, 'standard'), - - 'log_level': (STRING, 'info'), - - 'packages': (STRING, None), - 'classdirs': (STRING, None), - 'extdirs': (STRING, None), - - 'initial_env': (STRING, None), -} - -class modjy_param_mgr(UserDict): - - def __init__(self, param_types): - UserDict.__init__(self) - self.param_types = param_types - for pname in self.param_types.keys(): - typ, default = self.param_types[pname] - self.__setitem__(pname, default) - - def __getitem__(self, name): - return self._get_defaulted_value(name) - - def __setitem__(self, name, value): - self.data[name] = self._convert_value(name, value) - - def _convert_value(self, name, value): - if self.param_types.has_key(name): - typ, default = self.param_types[name] - typ_str, typ_func = typ - if typ_func: - try: - return typ_func(value) - except ValueError: - raise BadParameter("Illegal value for %s parameter '%s': %s" % (typ_str, name, value) ) - return value - - def _get_defaulted_value(self, name): - if self.data.has_key(name): - return self.data[name] - if self.param_types.has_key(name): - typ, default = self.param_types[name] - return default - raise KeyError(name) Copied: trunk/jython/Lib/modjy/modjy_params.py (from rev 6070, branches/modjy/Lib/modjy/modjy_params.py) =================================================================== --- trunk/jython/Lib/modjy/modjy_params.py (rev 0) +++ trunk/jython/Lib/modjy/modjy_params.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -0,0 +1,84 @@ +### +# +# 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 +# +### + +from UserDict import UserDict + +BOOLEAN = ('boolean', int) +INTEGER = ('integer', int) +FLOAT = ('float', float) +STRING = ('string', None) + +modjy_servlet_params = { + + 'multithread': (BOOLEAN, 1), + 'cache_callables': (BOOLEAN, 1), + 'reload_on_mod': (BOOLEAN, 0), + + 'app_import_name': (STRING, None), + + 'app_directory': (STRING, None), + 'app_filename': (STRING, 'application.py'), + 'app_callable_name': (STRING, 'handler'), + 'callable_query_name': (STRING, None), + + 'exc_handler': (STRING, 'standard'), + + 'log_level': (STRING, 'info'), + + 'packages': (STRING, None), + 'classdirs': (STRING, None), + 'extdirs': (STRING, None), + + 'initial_env': (STRING, None), +} + +class modjy_param_mgr(UserDict): + + def __init__(self, param_types): + UserDict.__init__(self) + self.param_types = param_types + for pname in self.param_types.keys(): + typ, default = self.param_types[pname] + self.__setitem__(pname, default) + + def __getitem__(self, name): + return self._get_defaulted_value(name) + + def __setitem__(self, name, value): + self.data[name] = self._convert_value(name, value) + + def _convert_value(self, name, value): + if self.param_types.has_key(name): + typ, default = self.param_types[name] + typ_str, typ_func = typ + if typ_func: + try: + return typ_func(value) + except ValueError: + raise BadParameter("Illegal value for %s parameter '%s': %s" % (typ_str, name, value) ) + return value + + def _get_defaulted_value(self, name): + if self.data.has_key(name): + return self.data[name] + if self.param_types.has_key(name): + typ, default = self.param_types[name] + return default + raise KeyError(name) Deleted: trunk/jython/Lib/modjy/modjy_publish.py =================================================================== --- branches/modjy/Lib/modjy/modjy_publish.py 2009-03-05 22:07:35 UTC (rev 6070) +++ trunk/jython/Lib/modjy/modjy_publish.py 2009-03-06 18:27:15 UTC (rev 6075) @@ -1,138 +0,0 @@ -### -# -# 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 -# -### - -import sys -import synchronize - -from java.io import File - -from modjy_exceptions import * - -class modjy_publisher: - - def init_publisher(self): - self.cache = None - if self.params['app_directory']: - self.app_directory = self.expand_relative_path(self.params['app_directory']) - else: - self.app_directory = self.servlet_context.getRealPath('/') - self.params['app_directory'] = self.app_directory - if not self.app_directory in sys.path: - sys.path.append(self.app_directory) - - def map_uri(self, req, environ): - source_uri = '%s%s%s' % (self.app_directory, File.separator, self.params['app_filename']) - callable_name = self.params['app_callable_name'] - if self.params['callable_query_name']: - query_string = req.getQueryString() - if query_string and '=' in query_string: - for name_val in query_string.split('&'): - name, value = name_val.split('=') - if name == self.params['callable_query_name']: - callable_name = value - return source_uri, callable_name - - def get_app_object(self, req, environ): - environ["SCRIPT_NAME"] = "%s%s" % (req.getContextPath(), req.getServletPath()) - path_info = req.getPathInfo() or "" - environ["PATH_INFO"] = path_info - environ["PATH_TRANSLATED"] = File(self.app_directory, path_info).getPath() - - if self.params['app_import_name'] is not None: - return self.get_app_object_importable(self.params['app_import_name']) - else: - if self.cache is None: - self.cache = {} - return self.get_app_object_old_style(req, environ) - - get_app_object = synchronize.make_synchronized(get_app_object) - - def get_app_object_importable(self, importable_name): - self.log.debug("Attempting to import application callable '%s'\n" % (importable_name, )) - # Under the importable mechanism, the cache contains a single object - if self.cache is None: - application, instantiable, method_name = self.load_importable(importable_name.strip()) - if instantiable and self.params['cache_callables']: - application = application() - self.cache = application, instantiable, method_name - application, instantiable, method_name = self.cache - self.log.debug("Application is " + str(application)) - if instantiable and not self.params['cache_callables']: - application = application() - self.log.debug("Instantiated application is " + str(application)) - if method_name is not None: - if not hasattr(application, method_name): - self.log.fatal("Attribute error application callable '%s' as no method '%s'" % (application, method_name)) - self.raise_exc(ApplicationNotFound, "Attribute error application callable '%s' as no method '%s'" % (application, method_name)) - application = getattr(application, method_name) - self.log.debug("Application method is " + str(application)) - return application - - def load_importable(sel... [truncated message content] |