Getting libwbxml on MacPorts

January 13, 2009

I need to be able to receive wbxml (binary XML) and transform it to xml using the IMPS 1.1/1.2/1.3 dictionary in Python. In PHP, I was using the PHP PECL extension wbxml, which uses libwbxml (wbxml2). In python, I need pywbxml. I like MacPorts, and I’ll use that instead of compiling myself the packages.

  1. Install MacPorts.
  2. Self-update:
    sudo port -v selfupdate
    
  3. Some general goodness I can’t live without (wget will pull a long dependency list of things we’ll need for web development):
    sudo port install wget
    
  4. Wait.
  5. Install wbxml
    sudo port install wbxml2
    
  6. And we get an error:
    $ sudo port -v install wbxml2
    --->  Configuring wbxml2
    Error: Target org.macports.configure returned: invalid command name "cd"
    Warning: the following items did not execute (for wbxml2):
    org.macports.activate org.macports.configure org.macports.build
    org.macports.destroot org.macports.install
    Error: Status 1 encountered during processing.
    

So I filed a ticket. It seems like wbxml2 ownership moved to the opensync folks since the port was added. The port builds on 0.9.0 and the latest version is 0.10.1. I don’t much (nothing?) about MacPorts, but I went ahead and I patched it. You can find the patch on the ticket itself.

Finally, moving onto pywbxml. It seems the only maintained pywbxml code is from the synce folks.

  1. Download pywbxml from sourceforge.
  2. Enter the virtualenv:
    $ source ~/Sites/python/imps/bin/activate
    
  3. pywbxml needs pyrex, so we’ll install that first with:
    $ easy_install pyrex
    
  4. Install pywbxml:
    $ tar xzfv pywbxml-0.1.tar.gz
    $ cd pywbxml-0.1
    $ ./configure
    $ make
    $ make install
    
  5. Optionally, move the libraries to the virtualenv to keep things clean:
    $ mv /Library/Python/2.5/site-packages/pywbxml.* \
        /Users/brunofr/Sites/python/imps/lib/python2.5/site-packages
    

Now, we can test it:

  $ python
  Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
  [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  >>> from pywbxml import xml2wbxml, wbxml2xml
  >>> xml = """<?xml version="1.0"?><!DOCTYPE WV-CSP-Message PUBLIC "-//OMA//DTD WV-CSP 1.2//EN" "http://www.openmobilealliance.org/DTD/WV-CSP.DTD"><WV-CSP-Message xmlns="http://www.wireless-village.org/CSP1.1"><Session><SessionDescriptor><SessionType>Outband</SessionType></SessionDescriptor><Transaction><TransactionDescriptor><TransactionMode>Request</TransactionMode><TransactionID>nok1</TransactionID></TransactionDescriptor><TransactionContent xmlns="http://www.wireless-village.org/TRC1.1"><Login-Request><UserID>hermes.onesoup</UserID><ClientID><URL>WV:IMPEC01$00001@NOK.S60</URL></ClientID><Password>xxxxxx</Password><TimeToLive>86400</TimeToLive><SessionCookie>wv:nokia.1789505498</SessionCookie></Login-Request></TransactionContent></Transaction></Session></WV-CSP-Message>"""
  >>> binary = xml2wbxml(xml)
  >>> text = wbxml2xml(binary)
  >>> binary
  '\x03\x01j\x00Imnp\x80\x19\x01\x01rtv\x80 \x01u\x03nok1\x00\x01\x01s\x00\x01]\x00\x00z\x03hermes.onesoup\x00\x01Jw\x03WV:\x00\x80\x12\x03PEC01$00001@NOK.S60\x00\x01\x01\x00\x01a\x03xxxxxx\x00\x01r\xc3\x03\x01Q\x80\x01p\x03wv:nokia.1789505498\x00\x01\x01\x01\x01\x01\x01'
  >>> text
  '<?xml version="1.0"?><!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"><Delete xmlns="http://synce.org/formats/airsync_wm5/airsync"><unknown><unknown><unknown><Truncation/></unknown></unknown><unknown><unknown><unknown><Supported/></unknown><unknown>nok1</unknown></unknown><unknown><Email3Address><unknown>hermes.onesoup</unknown><Fetch xmlns="http://synce.org/formats/airsync_wm5/airsync"><unknown>WV:<CollectionId/>PEC01$00001@NOK.S60</unknown></Fetch><HomeCity>xxxxxx</HomeCity><PagerNumber>\x01Q\x80</PagerNumber><OtherState>wv:nokia.1789505498</OtherState></Email3Address></unknown></unknown></unknown></Delete>'

It seems like it’s not using the WV CSP 1.1/1.2 dictionary (not surprising since I did not specify it anywhere). Looking at the code, in pywbxml.pyx, I can see:

  params.lang = WBXML_LANG_AIRSYNC

So, whereas the PHP PECL wbxml extension is exposing all the parameters in libwbxml, it seems like the Python version pywbxml is not, and it’s hard-coding assumptions.

Lesson learned with my day on python, twisted, wbxml, etc.: spending my time fixing the basics, does not allow me to work on the problems I need to solve. Will I fix pywbxml? I don’t know, but most likely not.


blog comments powered by Disqus