All things Jythonic 2004/7

July 2004
MoTuWeThFrSaSu
    1 2 3 4
5 6 7 8 91011
12131415161718
19202122232425
262728293031 
Jun
2004
 Aug
2004

A blog tracking jython developments

XML-Image Syndication

XML-Image Comment Feed

Letterimage Contact me

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    #
Creative Commons License
This work is licensed under a Creative Commons License.