Jython
November 25, 2011
Jython and Django Trial
# cd /Users/paulhollands/jython2.5.2/bin
# django-admin.py startproject dss
# jython manage.py runserver
Validating models...
0 errors found
Django version 1.3.1, using settings 'dss.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[25/Nov/2011 23:00:47] "GET / HTTP/1.1" 200 2045
Posted by pj at 11:02 PM | Comments (0)
October 28, 2011
Jython and Django
Chapter 14: Web Applications With Django — Jython Book v1.0 documentation
Posted by pj at 10:00 PM | Comments (0)
March 15, 2009
My Jython Regex Servlet
The servlet:
from javax.servlet.http import HttpServlet
import re
import string
class regexTest(HttpServlet):
def doGet(self,request,response):
self.doPost (request,response)
def doPost(self,request,response):
#param_names = request.getParameterNames()
writer = response.getWriter()
response.setContentType ("text/plain")
try: expr = request.getParameterValues("expr")[0]
except:
final_hash = { "errors" : ['']}
final_hash['errors'][0] = 'You must enter an expression.'
writer.println(final_hash)
sys.exit
try: this_text = request.getParameterValues("text")[0]
except:
final_hash = { "errors" : ['']}
final_hash['errors'][0] = 'You must enter some text.'
writer.println(final_hash)
sys.exit
reg = regexTest()
try: final_hash = reg.test_it(expr, this_text)
except:
final_hash = { "errors" : ['']}
final_hash['errors'][0] = 'Failed to run test.'
writer.println(final_hash)
sys.exit
#except: writer.println('')
#writer.println('')
writer.println(final_hash)
#def __init__(self, text="Stuff"):
# self.text = text
def test_it(self, exp, text):
final_hash = {}
try: this_reg = re.compile(exp)
except:
final_hash['error'] = ['Your expression did not compile']
return final_hash
#print this_reg
this_match = this_reg.findall(text)
final_hash["results"] = this_match
if this_match:
return final_hash
else:
final_hash['error'] = ['Your expression found no matches']
return final_hash
#if __name__ == "__main__":
# reg = regexTest()
# print reg.test_it('[\d]+', 'These are words and phone 07590 574469')
The JSP with the JSON:
<%@ page contentType="text/html" %>
<!-- %@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" % -->
<html>
<head>
<link rel="stylesheet" href="styles.css" type="text/css" media="all"/>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/set_date.js"></script>
<script type="text/javascript">
function do_regex(){
if(($('text').value == '') || ($('regex').value == '')){ alert('You must enter some text and an expression'); return false; }
var url = 'regexTest.py';
var params = '?text=' + escape($('text').value) + '&expr=' + escape($('regex').value);
var myAjax = new Ajax.Request(
url,
{
method: 'get',
parameters: params,
onComplete: show_response
});
function show_response(this_request){
this_result = this_request.responseText;
$('regex_here').value = this_result;
}
}
</script>
<title>Regular Expression Test Harness</title>
</head>
<body>
<h2 style="margin-left: 1em;">Regex Test Harness</h2>
<form action="#" method="post" style="width: 80%; margin: 2em; border: 1px solid #dcdcdc;">
<p style="margin-left: 1em;">
<label id="text_block_label" class="label_italic">Text
<em class="astrix" id="text_mandatory" style="display: none;">*</em></label>
<br/>
<em id="text_outer">
<input type="text" name="text" id="text" class="four_c" value=""/>
</em>
</p>
<p style="margin-left: 1em;">
<label id="regex_block_label" class="label_italic">Regex
<em class="astrix" id="regex_mandatory" style="display: none;">*</em></label>
<br/>
<em id="regex_outer">
<input type="regex" name="regex" id="regex" class="four_c" value="" onblur="do_regex()"/>
</em> <input type="button" value="Go»" class="button" onclick="do_regex()"/>
</p>
<form>
<textarea style="height: 100px; width: 400px; margin: 1em; color: red;" id="regex_here">
</textarea>
</form>
</form>
</body>
</html>
Posted by pj at 10:01 PM | Comments (0)
March 09, 2009
Getting PyServlet and Jython working
After a couple of days of hairloss I put the following into the container web.xml:
<servlet>
<servlet-name>PyServlet</servlet-name>
<servlet-class>org.python.util.PyServlet</servlet-class>
<param-name>python.home</param-name>
<param-value>/usr/local/jython</param-value>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>PyServlet</servlet-name>
<url-pattern>*.py</url-pattern>
</servlet-mapping>
Also I had to link:
/usr/local/jython/Lib to /Library/Tomcat/Home/conf/common/lib/Lib
and do the same for my application lib directory.
Now my jylets work.
Posted by pj at 11:37 AM | Comments (0)
March 07, 2009
Jython Webapp Tutorial
Jython Webapp Tutorial - Part 1 - Writing Servlets in Jython
Posted by pj at 03:41 PM | Comments (0)
November 15, 2007
Jython FTP Client
I've lashed together the following in Jython:
To compile:
/Users/paulhollands/jython2.2.1/jythonc -j ftp_upload.jar --all ftp_upload.py
Posted by pj at 05:09 PM | Comments (0)
May 23, 2006
Jython servlet version of AsciiDammit
I've turned AsciiDammit.py into a Jython servlet using Netbeans and Coyote.
Get the source curlyQuoteParser.py or get the .war Quote.war.
You'll need Jython 2.1 in /usr/local/jython-2.1
Posted by pj at 03:39 PM | Comments (0)
May 22, 2006
Coyote project rolls Jython support into Netbeans
Coyote: Dynamic language support in NetBeans
Watch out though. It breaks a projects web.xml by adding multiple <context-param/> nodes when you make the project Jython enabled.
This needs to be fixed in the XML by hand.
Posted by pj at 10:59 AM | Comments (0)
November 01, 2005
Tutorial about servlets in Jython
Jython Webapp Tutorial - Part 1 - Writing Servlets in Jython
Posted by pj at 08:45 PM
June 15, 2005
Eclipse and Jython
Apparently there are Jython plug-ins for Eclipse too:
Posted by pj at 01:09 PM