All things Jythonic

March 2006
MoTuWeThFrSaSu
   1 2 3 4 5
6 7 8 9101112
13141516171819
20212223242526
2728293031  
Dec
2005
 Apr
2006

A blog tracking jython developments

XML-Image Syndication

XML-Image Comment Feed

Letterimage Contact me

2006-03-28

This Blog Has Moved

I have been fighting off comment and trackback spam and have been finally driven to move to another tool. It is with great sadness that I leave my beloved PyDS and PyCS (python rules!) tools. This weblog has been moved to http://www.fishandcross.com/blog and is now being driven by WordPress.

I have imported the posts from this site have not been able to get the comments. I trust this site will stay available.

posted at 18:57:52    #
2005-12-20

PyDS Broken

Everytime I try to display the Upstreaming menu ... I get this: Exception exceptions.TypeError: wrong type for StringProp File Line Function Source C:\Python\lib\site-packages\PyDS\Tool.py 935 process_request s = tool.index_html(req) C:\Python\lib\site-packages\PyDS\UpstreamTool.py 561 index_html self.pingCloud(1) C:\Python\lib\site-packages\PyDS\UpstreamTool.py 694 pingCloud return self._driver.pingCloud(online, category) C:\Python\lib\site-packages\PyDS\XSSDriver.py 240 pingCloud tool.set('status', 'usernum', cloud['usernum']) C:\Python\lib\site-packages\PyDS\UpstreamTool.py 866 set setattr(self.status[0], field, value) Oddly, it still posts ...
posted at 19:38:24    #

The Python Web services developer: RSS for Python

The Python Web services developer: RSS for Python Mark Pilgrim offers rssparse.py for RSS file parsing.. and it seems to be Jython friendly.
posted at 19:27:44    #
2005-08-05

Jython Bibliography - Updated

I've corrected a few of the IBM articles that seem to have moved and have added a few articles that have appeared in 2005 on Jython. Enjoy!
posted at 02:49:36    #
2005-05-05

Weird Python News of the Day - Attack of the Malformed Pickle

In the extremely unlikely event that you are victim of one of these attacks ... DO NOT EAT THE MALFORMED PICKLE!


** Warning ** - If you are exchanging SSLCrypto key objects over the internet, it is imperative you switch immediately to SSLCrypto 0.1.1. If you stay with SSLCrypto 0.1, you could be susceptible to malformed pickle attacks.

posted at 23:09:52    #
2005-04-28

Jython, Velocity, Jetty and ... REST

Jason Briggs has put together a great article on REST ( Representational State Transfer ) style application development using Jython and Velocity on Jetty.  His goal is simpler servlet development that is more standards compliant.  You don't need to use Gets and Posts only and he shows you how to do it all with Jython.  He even includes as a resource in the article a jar file combining Velocity and the JythonUperspect customizer to let velocity work with Jython objects. 
 
posted at 22:25:04    #
2005-04-26

PushToTest - Free open-source software test automation solutions - Writing Threaded Applications in Jython

Here is a quick tutorial on writing thread safe jython scripts. The author implements thread safe examples using both Python and Java methods. Here is the article's conclusion

Based on my experience writing threaded applications in Jython, using Java Threads and the Runnable interface is the best practice. The following Jython script implements the best practice for building threaded applications in Jython:

from java.lang import Thread, Runnable
import synchronize

  class myclass( Runnable ):
    def __init__( self, myparam ):
      self.storeit = myparam

    def setMyparam( self, myparam ):
      self.storeit = myparam
    setMyparam=synchronize.make_synchronized( setMyparam )

    def printMyparam( self ):
      print "myclass: myparam =",self.storeit
    printMyparam=synchronize.make_synchronized( printMyparam )

    def run( self ):
      for self.i in range(5):
        self.printMyparam()

  count = 2

  a = myclass()
  a.setMyparam( "frank" )

  t = Thread( a, "MyThread %d" % count )
  t.start()
posted at 22:05:52    #
2005-02-16

Palm T3 + WIFI SDIO Experiences

I noticed while wander a Frys Electronics store in Plano that there is now a WIFI SD card available for my T3. Its a heafty $129.00 or so ... Has anyone out there in the blogosphere tried this? Any feedback on whether it is worth it?
posted at 15:05:20    #
2005-01-24

Brian Zimmers Blog

Brian, now officially working on Jython, has a blog. Also has a nice comments feed.

posted at 10:08:48    #
2005-01-18

Daily Python-URL: Python port of SWT?

Scott Sanders (dotnot) asks: Is anyone working on a port of SWT to Python? Is anyone interested in such a thing?

Of course this is something that is possible today using Jython.  I have configured the RedRobin Jython Eclipse plugin to allow me to easily script SWT (and JFace from Jython ... works like a charm.)  Here is a quick Jython Hello World for SWT.

from org.eclipse.jface.window import *
from org.eclipse.swt import *
from org.eclipse.swt.widgets import *
import sys

class Hello(ApplicationWindow):
  def createContents(self, parent):
  b = Button(parent, SWT.PUSH, widgetSelected=self.helloWorld)
  b.text = "Hello World"
  return b    
  def helloWorld(self, evt):
     print "Hello There ..." 
     sys.exit(0)        
 
w = Hello(None)
w.blockOnOpen = 1
w.open()
Display.getCurrent().dispose()

In order to get this to work in eclipse using the Jython plugin, you need to either create a jython project in eclipse or add the Jython nature to an existing project, add the swt and jface jars into the class path in the project's jython properties and finally set the java.library.path to the location of the swt library also in the project's jython  properties.  This last step is so that swt can find its os native libraries. 

posted at 09:11:12    #
2005-01-17

Brian Zimmer's 'An Introduction to Jython' presentation

Brian Zimmer presented Jython to the Chicago Python Users Group (chipy). Here is a link to his slides.

posted at 21:20:48    #
2005-01-15

And the Winner is: Jython

The Java Republic poll asks"What is Your Scripting Language for Java of the Year 2004?". And the winner with 59% of the votes is Jython!
posted at 22:31:12    #

Use Jython to time Java code

Here is an interesting Jython receipe - Use Jython to time Java code   A clever way to do some low level timing of java functions, all from Jython. 

posted at 01:02:40    #
2005-01-12

Updated Jython Bibliography

I've updated the Jython Bibliography, adding a few new articles and some older ones that were missed before. Please let me know if I've missed any!

posted at 18:34:24    #
2005-01-02

Inline Java code into Jython

This recipe shows how to insert java code into a jython program. The java code is automatically compiled and the resulting class is imported and returned. Compilation only occurs after a change of the java source.
 
posted at 16:30:40    #

Moving Jython Forward: PSF Grant!

Jython has recieved a grant injection from the PSF!  One of the three selected grant proposals deals specifically with revitalizing Jython development and Brian Zimmer will manage the project now called: Moving Jython Forward.

posted at 16:26:24    #
2004-12-03

A WSGI server for jython 2.1

Modjy is an implementation of a WSGI compliant gateway/server for jython, built on J2EE servlets. Python Web Server Gateway Interface, as specified in Python Enhancement Proposal 333, is a proposal for a "simple and universal interface between web servers and [python] web applications or frameworks".

posted at 15:39:28    #

Jython Webapp Tutorial - Part 1 - Writing Servlets in Jython

Here is a tutorial on setting up and building Jython webapps.  Quick Contents:

Looks good and there is more coming. Here is the overal direction the effort is taking:

  • Part 1 - Writing Servlets with Jython
  • Part 2 - Process XML with the Xerces and Xalan libraries from Jython
  • Part 3 - JMS Messaging from Jython with ActiveMQ
  • Part 4 - From web-front end to process-to-process integration with Jython
  • Part 5 - Summarizing the benefits of Jython and dynamic typing in general for Webapp development.

I'm looking forward to the rest!

posted at 15:35:12    #
2004-09-28

Looking for a Really Light Weight Java Wiki

I am looking for a light weight java servlet based wiki that I can use to "embed" in an existing web application.  My basic requirements are:

  • Servlet based but not 2.3 servlet... I have to run it on an older version of Jetty which isn't up to the latest and greatest servlet api.
  • No JSP stuff .. see above
  • No database behind it .. .just simple filesystem (versioning would be nice ...)
  • No Hibernate, Spring, Struts, etc.  See above...
  • Nice to have would be customization via Jython ... or to have it written in Jython .. even better

Just a simple java servlet that implements basic wiki features.  I'm coming up empty so far.

posted at 09:58:24    #
2004-09-15

Jython and Spring framework

It seems that Kent is having issues getting Jython to work with the Spring framework.  He says:

One of the limitations of Jython is that it doesn't play very well with Java introspection. If you want your Jython methods to be visible to Java introspection you have two choices:

  • compile your scripts with jythonc
  • implement a Java interface containing the methods of interest

The first option is problematic (I have had too much trouble with jythonc).

The jythonc that he is referring to I think is the decorator language you can use in a jython class definition that forces jythonc to generate a specific java class with the function signature you want.  For Example:

[via Python Rocks! and other rants]

posted at 08:39:28    #
2004-09-03

How to do an XSL transformation in Jython

Here is a quick way to do xsl transformation in jython.  I also found at the same site the a quick intro to dom style parsing of xml files from Jython.  You might also look at using jdom to do this as well.
posted at 16:56:32    #
2004-08-26

deque collection class for Jython

Raymond Hettinger  provided a Pure python drop in replacement for collections.deque() from Py2.4 and it works with Jython.  Hurray!  Its available at the ActiveState Python Cookbook.  See the Python 2.4 documentation at: http://www.python.org/dev/doc/devel/lib/module-collections.html for how to use this. 


 

posted at 13:14:40    #
2004-08-18

Some Python Aspect Oriented Programming Links

Python Aspect Oriented Links:

 This introduces a Python module which implements one essential concept in Aspect Oriented Programming (AOP)... The aspects module provides a function called wrap_around.

 The Pythius package high level AOP support. See here for examples.

aspects is a python module that enables Aspect Oriented Programming in Python. For now, it provides a set of ready-to-use aspects and an easy way to create your own aspects. The current possibilities are still a bit limited, but it will soon provide a more exhaustive way to define and use more complex aspects.

Most readers are already familiar with the concepts of object-oriented programming: inheritance, encapsulation, polymorphism. But the creation of objects of a given class, with certain parents, is usually thought of as a "just so" operation. It turns out that a number of new programming constructs become either easier, or possible at all, when you can customize the process of object creation. Metaclasses enable certain types of "aspect-oriented programming," for example, you can enhance classes with features like tracing capabilities, object persistence, exception logging, and more.

As far as I can see only Lightweight Python AOP seems to work with Jython.  I was able to successfully run the tracer example with Jython although the timing example failed but not in the aspect library code.  The other libraries require Python 2.2 or greater which currently eliminates Jython.

UPDATE

If you are new to Aspect Oriented Programming, here is a quick definition:

Aspect Oriented Programming (AOP) is a technique for separating and isolating crosscutting concerns into modular components called aspects. A crosscutting concern is a behaviour that "cuts" across the boundaries of assigned responsibility for a given modular element. Examples of crosscutting concerns are process synchronization, location control, execution timing constraints, persistence, and failure recovery. There is also a wide range of algorithms and design patterns which are more naturally expressible using AOP.

-Christopher Diggins, Aspect Oriented Programming in C++, August 2004, Dr Dobbs Journal
posted at 03:08:48    #
2004-08-05

Why I Use Jython - Run Darn Near Everywhere

I've just putting the finishing touches on several small projects that are centered around Jython and several widely available java libraries.  I chose Jython for several reasons. 

  • Python just fits how my brain works. Weird I know, but that is my reality.
  • But not everyone has Python installed, or has the right release of python.
  • So I write my software in python that I can compile into a java jar using Jython and thus piggy back on the general availability of the Java platform! 
  • So my software is easily deployed!
posted at 14:10:08    #
2004-07-27

Python Resource List

In my continuing search for Python UML tools I stumbled across this long list of python resources.

posted at 01:11:28    #

PyNSource - UML Modelling Tools for Python

I have been looking for a good class diagram generator for my jython / python work and stumbled on PyNSource. Here is a quick list of features:

A python code scanner and UML modelling tool that generates

  • UML diagram models that you can layout, arrange and print out.
  • UML text diagrams, which you can paste into your source code for documentation purposes.
  • Java or Delphi code (which can be subsequently imported into more sophisticated UML modelling tools, like Enterprise Architect or ESS-Model (free).)

Features

  • Resilient: doesn't import the python files, thus will never get "stuck" when syntax is wrong.
  • Fast
  • Recognises inheritance and composition relationships
  • Detects the cardinality of associations e.g. one to one or 1..* etc
  • Optionally treat modules as classes - creating a pseudo class for each module - module variables and functions are treated as Attributes and methods of a class
  • Has been developed using unit tests (supplied) so that you can trust it just that little bit more ;-)
  • Free

I gave it a quick try and here is what it looks like (click on the image to see the larger text):

I know that a number of python ide's have class browsers built in but how about a class diagram a-la uml as well? I think that would be pretty handy. Please let me know if there are are other python aware tools out there.

posted at 16:54:24    #
2004-07-13

SQLObject + MySQL CachedValues Rant

We interrupt your regularly scheduled Jython coverage to bring you this therapeutic rant:

[RANT ON]

OK, so if you are using SQLObject_ with MySQL 4.X and you notice that queries executed after table updates do not reflect the changes .... TURN OFF _CACHE_VALUES for your database classes (you do this by defining the following class attribute:

_cache_values = False 

Since MySQL does autocommit by default your database changes are invisible to queries if you don't do this ... That only cost me several hours.  Ok I feel better now.

[RANT OFF]

And now back to your regularly scheduled Jython coverage.

posted at 01:52:00    #
2004-07-12

Scripting LDAP with Jython -- Store Java Objects in LDAP

This is the complement to the earlier example that read a java Hastable out of an ldap directory entry. Here is how you get the data in there to begin with.

# Jython LDAP - Store Java Hashtable into LDAP Example

from javax.naming import *
from java.util import *
from javax.naming.directory import *

# Credentials to access LDAP
user = "cn=master"
passwd = "password"

# Setup LDAP Context Options
settings = Hashtable()
settings.put(Context.INITIAL_CONTEXT_FACTORY, \ 
       "com.sun.jndi.ldap.LdapCtxFactory")
settings.put(Context.PROVIDER_URL, "ldap://localhost:389")
settings.put(Context.SECURITY_PRINCIPAL, user)
settings.put(Context.SECURITY_CREDENTIALS, passwd)

# Connect to LDAP Server
ctx = InitialDirContext(settings)

# build Hastable we want to store
userPrefs = Hashtable()
userPrefs.put("Server", "Someserver.com")
userPrefs.put("Color", "Red")
userPrefs.put("Wine", "Cabernet")
userPrefs.put("Year", "1994")

ctx.bind("cn=test_user,ou=Preferences,dc=Company,dc=com", userPrefs)

#done

If the entry already exists you need to use the context's rebind method like this:

ctx.rebind("cn=test_user,ou=Preferences,dc=Company,dc=com", \
    userPrefs)
posted at 01:11:28    #

Scripting LDAP with Jython -- Load Java Objects from LDAP

A common way to store user preference data for applications is to store them in LDAP as a serialized Java Hastable object. The application then reads that back from ldap on startup using the authenticated userid as the key. Its a convenient way to store application settings. But what if you need to adjust or migrate settings from one place to the other? Here is an approach to reading that data out using Jython. Look for a future post about how to save it back using the context's bind method ...

# Jython LDAP - Retrieve Stored Object from LDAP Example

from javax.naming import *
from java.util import *
from javax.naming.directory import *

# Credentials to access LDAP
user = "cn=master"
passwd = "password"

# Setup LDAP Context Options
settings = Hashtable()
settings.put(Context.INITIAL_CONTEXT_FACTORY, \ 
     "com.sun.jndi.ldap.LdapCtxFactory")
settings.put(Context.PROVIDER_URL, "ldap://localhost:389")
settings.put(Context.SECURITY_PRINCIPAL, user)
settings.put(Context.SECURITY_CREDENTIALS, passwd)

# Connect to LDAP Server
ctx = InitialDirContext(settings)

# load the java Hashtable out of the ldap server
prefs = ctx.lookup("cn=ccm_root,ou=Preferences,dc=Company,dc=com")

for pref in prefs.keys():
        print "PREF: %s\n VALUE: %s " % (pref, prefs[pref])
posted at 23:44:00    #

Scripting LDAP with Jython -- Queries

I've been playing with LDAP directories from Jython and thought I should share a couple of useful examples of what you can do. The first of these is a quick barebones query example. Enjoy.

# Jython LDAP Example

from javax.naming import *
from java.util import *
from javax.naming.directory import *

# Credentials to access LDAP
user = "cn=master"
passwd = "password"

# Query starting point and query target 
search_start = "ou=People,dc=Company,dc=com"
search_target = "uid=aUserID"

# Setup LDAP Context Options
settings = Hashtable()
settings.put(Context.INITIAL_CONTEXT_FACTORY, \ 
     "com.sun.jndi.ldap.LdapCtxFactory")
settings.put(Context.PROVIDER_URL, "ldap://localhost:389")
settings.put(Context.SECURITY_PRINCIPAL, user)
settings.put(Context.SECURITY_CREDENTIALS, passwd)

# Connect to LDAP Server
ctx = InitialDirContext(settings)

srch = SearchControls()
srch.setSearchScope(SearchControls.SUBTREE_SCOPE)

# Execute LDAP Search
results = ctx.search(search_start, search_target, srch )

#Display Search`
for result in results:

     attributes = result.getAttributes()
     names = []
     for atr in attributes.getIDs():
             names.append(str(atr))

     for name in names:
             print attributes.get(name)
posted at 23:29:04    #
2004-07-09

alt.lang.jre: Get to know Jython

Here is a great new Jython article by Barry Feigenbaum over on IBM's developerWorks.  Check it out.

alt.lang.jre: Get to know Jython Get to know Jython, in this first article in our new series introducing alternate languages for the Java Runtime Environment, "alt.lang.jre". Jython is an implementation of the popular scripting language Python, but running on a JVM. For Python developers Jython is the best possible entry point to the Java platform; for Java developers it may be the strongest incentive to learn another language. Frequent developerWorks contributor and alternate language enthusiast Barry Feigenbaum introduces Jython and shows you what it can do to enhance your productivity on the Java platform.

posted at 01:43:28    #
2004-07-02

Jython Bibliography -- Updated and Corrected

Thanks to reader feedback including several of the authors I have corrected the bibliography (its pretty neat to receieve feedback from the cited authors. You have to love the 'net.). Additionally, I have added several older articles on JPython which preceeded Jython. Again, if there is anything missing or incorrect please let me know either in comments here or via email to etaekema-at-earthlink-dot-net.

posted at 23:48:16    #
2004-06-30

edittwiki - external editor tool for TWiki

Announcing edittwiki 0.1, an external editor launcher for the popular TWiki wiki. This is similar in spirit to the editMoin tool for MoinMoin wikis. I wrote this in Jython and compiled into a java jar so it should run on a wide set of operating systems. It features a configurable editor setting so you can edit TWiki topics using your favourite editor (including html editors) and works with TWiki installations that are password secured.

This is the initial release, so please be gentle! and feel free to provide feedback here or via email to etaekema-at-earthlink-dot-net.

posted at 01:56:16    #
2004-06-28

Jython and Swing

Not so useless Jython from the Useless Python blog . A basic example of how to get going with Jython and Swing!

The following is an example of using the Jython interactive interpreter from the Windows 2000 command prompt. On this page, we demonstrate several Jython basics, including:

  • use of the jython interpreter from the MS Windows 2000 command prompt

  • collection of user input with javax.swing.JOptionPane.showInputDialog()

  • conversion of strings to integers, and integers to strings, plus simple addition

  • display of output with javax.swing.JOptionPane.showMessageDialog()

posted at 00:01:04    #

Write Your Own Mini Aggregator with Jython and Rome!

Rome is a new java API for reading RSS and ATOM feeds. Here is a quick demonstration of what you can do with it using Jython, the Java Scripting Swiss Army Knife.

Ok, you will need to add both the latest build of Rome and JDOM to your classpath. Next fire up jython or if you like use the Jython Console which will make exploring the ROME api a little easier.

Here is the source code then of a simple aggregator written in jython.

from java.net import URL
from com.sun.syndication.feed.synd import SyndFeedI
from com.sun.syndication.io import SyndFeedInput

myUrl = URL('http://www.pycs.net/users/0000177/rss.xml')

input = SyndFeedInput()
feed = input.build(myUrl.openStream())

entries = feed.getEntries()

for post in entries:
    title = post.getTitle()
    link = post.getLink()

    print """<a href='%s'>%s</a>""" % (title, link)

When you run this, you will get a list of links pointing to the posts in the feed, in this case the feed for my main site.

posted at 16:52:16    #
Creative Commons License
This work is licensed under a Creative Commons License.