In which I avoid the inverse unicode sandwich

Jun 22, 2012 | categories: python, toscawidgets, testing, turbogears View Comments

Problem #1 - I need to test tons of HTML output for correctness (because I maintain toscawidgets2). That output varies slightly because tw2 supports five different templating languages (mako, genshi, jinja2, kajiki, and chameleon). Using double-equals (==) just won't do it.

Solution #1 - We used strainer. It works!

Problem #2 - Imagine porting this to Python 3. Yes, that's right. The encoding is sniffed by hand and then used to encode regular expressions; these are in turn applied to parse XML. Think "inverse unicode sandwich with a side of Cthulhu."

Solution #2 - I wrote sieve: a baby module child of one corner of FormEncode and another corner of strainer. It works on pythons 2.6, 2.7, and 3.2. If you like, you may use it:

>>> from sieve.operators import eq_xml, in_xml
>>> a = "<foo><bar>Value</bar></foo>"
>>> b = """
... <foo>
...     <bar>
...         Value
...     </bar>
... </foo>
... """
>>> eq_xml(a, b)
>>> c = "<html><body><foo><bar>Value</bar></foo></body></html"
>>> in_xml(a, c)  # 'needle' in a 'haystack'

p.s. -- I looked into xmldiff. Awesome!

View Comments

Teaching Open Source, Web-Based, Game Programming at RIT

Mar 06, 2012 | categories: python, teachingopensource, openshift, turbogears View Comments

This last quarter at RIT I taught (for the first time) a course on open source, web-based, game programming. The quarter just came to an end and I really want to brag on my students. But before I do that, here's a glimmer of what we covered:

  • How to use bash and vim
  • How to use git and github
  • How to submit patches to projects you know nothing about
  • What makes a good, casual game
  • How to make games with HTML5
  • How to program in JavaScript, CoffeeScript, and Python
  • Serverside programming with Turbogears2
  • How to get your code running on Red Hat's Openshift cloud.
  • How to give a lightning talk(!)

Really cool stuff was built into the class; it was about making open source software, so we open sourced the syllabus! Really cool stuff happened along the way; we hit ugly problems with openshift, so we patched the quickstarter script!

You can endure my self-indulgent drivel yes, but you get the best picture from reading the students' blog posts themselves. Enough of this! Les projets de cours!

#1 - Lazorz teamed up with the Boston Museum of Science to make "[An] educational game about the physics of light. In it's current incarnation it helps demonstrate the concepts of reflection and color filtering. The development team has plans to include other concepts such as refraction and prisms in future releases."


They got a nasty front-end built, by hand, with javascript and HTML5 that works on every mobile device we could test it on. It is intuitive and fun. They have almost-working Facebook auth and they have an almost-working Turbogears2 backed JSON store. (really, this close to completion!)

#2 - Gold Rush is visually and game-ly amazing. If I had to pick which of the three project was going to make one million dollars, it'd be this one.


The front-end is built in Unity (closed source, but compiles to a ton of platforms) and the back-end JSON store is built in TurboGears2. These guys completely flew through development, mastering skills they'd never heard of in a day. Its 3D with a moving camera and an incredibly fun game. The original game idea belongs to team member Eric Heaney. It's fun to play as a normal old card game (I've played it at a number of parties since he pitched it to the class).

#3 -- WebBotWar (the python web robot fighting game) wins the prize for master hack. They:

  • Forked pybotwar, ripped it's UI off and made it export JSON.
  • Reimplemented the front-end with jCanvas (and cooked up all their own art assets!).
  • Wrote a TurboGears2 app that spins up serverside instances of their pybotwar fork.
    • Those instances dump their state into mongodb (or memcached, long story).
    • Their javascript client polls the TG2 app for the game state and voilà.

They have (awesome) plans to:

  • Allow you to upload your own scripts (they have it working, just not secured).
  • Make a built-in script editor.
  • Tighter facebook integration (challenge your friends!)

BTW, it works on android and iPad. It even works on Epiphany (wat?) They also want you to know that python box2d is a pain in the ass.

View Comments

ToscaWidgets2 Bugsprint Report

Mar 04, 2012 | categories: python, toscawidgets, pyramid, turbogears View Comments

Here's the rundown of the pre-PyCon tw2 bugsprint. The unstoppable Greg Jurman and I coordinated in google+ and IRC (with lots of ad-hoc visitors in both) and did all the damage we could do to the bug list. Our goal was to close enough that we could justify a solid 2.0 non-beta release but we didn't quite get there. We settled on 2.0 release candidate 1.

tl;dr - Big progress. We'll seal the deal on 2.0 at PyCon US next week.


Tickets closed:

Tickets worked on, but not complete:

Tickets created:

View Comments

TW2 Bugsprint; the Final Countdown

Mar 02, 2012 | categories: python, toscawidgets, pyramid, turbogears View Comments

Tomorrow marks the start of the toscawidgets2 24 hour bugsprint and I couldn't be more stoked. We haven't even started yet but tw2 development pushed ahead anyways.

We have:

Goal: (solidly) close as many bugs as possible and push as many libraries from beta to release as we can.

Here's to winning that game.

View Comments

Hacking tw2 resource injection

Dec 13, 2011 | categories: python, toscawidgets, turbogears View Comments

Tonight, VooDooNOFX was asking in IRC in #turbogears how to disable the injection of jquery.js by tw2.jquery into her/his TG2 app. Using the inject_resources=False middleware config value wouldn't cut it, since she/he wanted tw2 to inject all other resources, they were loading jQuery via google CDN beforehand and tw2's injection was clobbering their code.

I came up with the following hack to myapp/lib/base.py which will remove tw2.jquery.jquery_js from the list of resources tw2 would inject into each page served by a TG2.1 app.

At the top of myapp/lib/base.py import:

import tw2.core.core
import tw2.jquery

and then replace:

        return TGController.__call__(self, environ, start_response)

with the following:

        stream = TGController.__call__(self, environ, start_response)

        # Disable the injection of tw2.jquery
        offending_link = tw2.jquery.jquery_js.req().link
        local = tw2.core.core.request_local()
        local['resources'] = [
            r for r in local.get('resources', list()) if r.link != offending_link

        return stream

The two tricks to this are

  • Simply knowing that tw2 resources register themselves with the 'request_local' object and that during the return-phase of the WSGI pipeline, the tw2 middleware refers to that list when injecting resources
  • Figuring out where in a TG2 app's request flow to place the call to alter that object after all widgets that might register jquery have declared their resources but before the resources list is injected into the output stream.

We came out of it with a bug filed in the tw2 issue tracker so we can take care of it properly in the future.

View Comments

Next Page »