see whatever…

jump to menu

March 24, 2006

I am a “sock thief hero”

Filed under: Uncategorized — see @ 10:16 pm

or maybe even better “cook three fish”…

see the anagram maker nanagram 

March 18, 2006

encutils obsolete I guess

Filed under: encutils,Python — see @ 3:25 pm

I guess encutils are obsolete as I found chardet (Universal Encoding Detector) today which actually is from last year. I assumed there would be a similar (and better) library to detect encodings but never found anyone so started encutils which is probably much inferior to chardet. Now everyone needing this functionality is better off with chardet whose author Mark Pilgrim is someone much more involved in these things. But I guess it was worth the effort writing my own lib and maybe I try to update some things off it with just using chardet…

March 15, 2006

RelaxNG Test with Selenium (a bit contrived I know ;)

Filed under: Programming,Python,RelaxNG,Web,XML — see @ 12:09 am

Maybe it is easier to validate an XML file with RelaxNG with a simple program. But as I wanted to try something with Selenium anyway (and other tests – UI tests – need Selenium) I build something a bit around.

I built a servlet which did a RelaxNG validation on a given XML file and prints out a “Validates: True” message with a log of errors and the XML source. The XML file to validate itself can be given via an URI in a request parameter so that the validation servlet would fetch the XML via HTTP itself. Selenium than could test the output of the validation servlet.

So the first step is the XML server which is just used as a kind of webservice to access files on a machine. This server is a very simple Python server based on BaseHTTPServer. Could have been (as the following one) a Java servlet but I just found this approach much easier than working around servlet limitations. I used port 8081 but that could have been any other of course.

The second step is the validation servlet which runs in a standard tomcat just because Jing is a Java lib and therefore easiest to use with Java. Actually the servlet is written in Jython but only because I am much more comfortable with Jython than with raw Java. I use the standard Tomcat 8080 port.

The third step – Selenium – actually runs in a Twisted server which enables the Selenium tests to work with any given server as no cross site scripting issues arise. The setup for this is very nicely explained in Web app testing with Python part 2: Selenium and Twisted. I used port 8082 here as Tomcat already uses 8080.

The test itself just does 2 Selenium commands:

1. open the test URL on the validation server, e.g. (not escaped)
- Twisted URL: http://localhost:8082/AUT/00000A/…
- followed by path: …/http/validationserver:8080?…
- followed by query param: …?xmlURI=http://xmlserver:8081/example.xml

2. verifyTextPresent “Validates: True”

So quite an effort just to do a XML validation but on the other hand nice to do all tests in just one tool.

Only annoying thing is that the Twisted Selenium server needs Twisted 1.3.0 and does not work with the current 2.2.0 version. Maybe that was the reason that running tests on about 300 files do fail after about 25, seems to stress Twisted (or my laptop ;) too much. I guess I am not skilled enough to bring Selenium to work on Twisted 2.2.0 but maybe I try. If anybody has a solution already, let me know

Alltogether quite fun doing admittedly a bit contrived but working setup and at least I did even some more practive setting up simple but effective servers. I find working in such a way more comfortable than writing a standalone program which in the end cannot be split into components which the described setup actually is. Fact is that I only wrote the XML server from scratch but even that is used for other stuff, so perfectly separated components but working together quite nicely…

March 13, 2006

XSLT simple pipelining

Filed under: Python,XSLT — see @ 10:21 pm

Another migration project at work came up which mainly is a migration of XML files from one format to another. Of course best fit for XSLT and maybe the best: free whatever technology to use. I wanted to try XSLT 2.0 for a while but still sticked to 1.0 for this one due to Pyana’s (Python Xalan bridge) very easy integration of custom XSLT extension functions written in Python. String handling is rather nasty in XSLT 1.0 (I think much better in 2.0 but I guess still not as easy as Python’s) so writing all not real XML transformation work but actual string conversion in Python.

And this time (contrary to the first big complex migration) I did split the process in lots of small steps in a simple XSLT pipeline. Eventually I may add a schema validation (RelaxNG) to it but that may even better fit into a Selenium based test as I built this functionality with a simple webapp anyway.
Currently 7 steps of quite small and therefor quite simple to handle units makes this into quite a nice work actually. Not as unwieldy and errorprone as one big, massive and quite mazelike monolith XSLT stylesheet…
I don’t know really why I like XSLT so much being quite different (sometimes mindboggling, very verbose as XML programming can be etc) to my other favourite language which is Python. That I like for its sheer “niceness” meaning clean design both in the language itself, the libs and even the simple “niceness” of the source code (maybe I like it because I am basically a designer). So I would assume I would like one or the other and not both. But they just fit together really well, at least for XML processing.

March 9, 2006

bored but checked out C# and IronPython

Filed under: Python — see @ 10:30 pm

was a bit bored this evening so I installed the Visual C# Express edition which came with one of the latest issues of c’t magazine. I remembered at least a bit of the articles I had skimmed through so wrote a “hi there” console app in a minute. Not bad and the IDE feels much faster than e.g. Eclipse which is still a bit sluggish. (BTW, Oxygen which I just got at work this week is horribly slow, but has lots of nice features which makes it much better than XMLSpy which I used until now. And that is not too quick too, especially with larger (> 1MB files)…)

Anyway, as the C# install installed .NET 2.0 I remembered I wanted to check out IronPython which I never did until now as I avoided the .NET 2 installation (which took a looooong time indeed).

IronPython felt just fine, a quick loop, a few looks at version infos and I even imported System from .NET and run almost the same “hi there” here again.

IronPython feels almost nicer than Jython which I use quite often these days. Python still seems a very good choice to learn as I now can (well, at least theoretically ;) use it with Java, C#, just by itself which I prefer of course or even hopefully on the new mobile I am looking for which should be a Nokia Series 60 phone with Python support naturally…

Powered by WordPress