Libbokka v.0.2 Tiny scripts for our projects. (c) Humane Magica, Bokkafokka dpt. http://humanemagica.com Please contact mailto:makiwara@humanemagica.com for any stuff related. Libbokka is a pack of 4 script-files, which simplifies usage of - JSON converting from & to - SQL abstraction over web.py framework - TPL abstraction over mako - XML converting to custom python structures === JSON converting === Simplejson is really simple. How can it be simplier? Look: >>> import libbokka >>> print libbokka.toJson( test=[1,2,3], str="string", dt=datetime.datetime.now()) ) >>> print libbokka.fromJson('{"t":6, "a":5}') === SQL absctration === Web.py is good, we need only to know how to - create tables >>> print libbokka.create( 'users', '__ID__, name varchar(1), active INT, about TEXT' ) - workaround "random() or rand()" >>> print libbokka.rand() - workaround and datetime issues >>> print libbokka.dtstr(datetime.datetime.now()) >>> print libbokka.dtstr('2008-01-08 00:00:12') >>> print libbokka.dtobj(datetime.datetime.now()) >>> print libbokka.dtobj('2008-01-08 00:00:12') === TPL abstraction === Mako is fine, but complicated a bit to just call it directly. So: >>> import libbokka >>> print libbokka.tpl("test.html", param=value) NB: templates must be located in "templates/" folder, but you can relocate it. If you use web.py (as we do), you can find useful our Static controller. === XML converting to pythonic structures === We all love Elementtree. We'ld love to receive simple python dicts from complicated XML. So we configure ruleset: >>> ruleset = { "foaf:nick" : "text", "foaf:name" : "text", "foaf:dateOfBirth" : "text", "foaf:tagLine" : "text", "foaf:img" : "rdf:resource", "foaf:interest" : ["dc:title", "rdf:resource"], } And then extract pythonic data from XML: >>> print libbokka.dexml( person, p, none="", strip_shortcuts=True ) NB: "person" in our example contains very complicated FOAF XML from Livejournal; it is prepared this way: >>> data = openanything.fetch( "http://freeformfactor.livejournal.com/data/foaf" )["data"] >>> feed = ET.XML(data) >>> person = feed.find( libbokka.ns("foaf:Person") ) ---- NB: Contents of examples/libs are provided AS-IS from some other respected developers. It contains: - web.py framework (http://webpy.org) and flup - mako templates engine (http://makotemplates.org) - elementtree xml library (http://effbot.org/zone/element-index.htm) - OpenAnything library (http://diveintopython.org/) Those packages are enlisted only for quick examples startup, they are not necessary for distribution of libbokka. Moreover, libbokka is only contented folder with same name.