[Xcb] Python X11 encoder/decoder based on XCB

Mark Seaborn mseaborn at onetel.com
Tue May 8 14:45:50 PDT 2007


Barton C Massey <bart at cs.pdx.edu> wrote:

> Very cool.  Thanks much for sharing this.
> 
> Being too lazy to download the code right now :-), what did
> you do about reading the XCB protocol definitions?  Did you
> do your own parser etc?

It uses lxml.etree to parse the XML into a tree.  Most XCB elements
get mapped to an object that can encode and decode the type that the
element represents to/from a stream.

<request>s, <reply>s, <struct>s and number types (CARD16, CARD32 etc.) 
get mapped to objects of one interface with encode()/decode() methods
that write/read whole values.  Structure elements -- <pad>, <field>,
<list>, <valueparam> -- get mapped to another interface (StructPart).

The constructors, along with make_struct_part_handler() and
make_list_decoder(), just read attributes and child elements off the
XML tree.  Parsing XCB was not really a big deal. :-)

I opted not to implement parts of XCB such as <exprfield> (which is
only used once, for QueryTextExtents) or <op op="*">.  Those parts
might make sense for encoding but they're not much use for decoding.
To keep the XML simple the odd cases are given special-case names, and
their en/decoders are written in Python as special cases.  eg. There
is a QueryTextExtentsStringField class instead of implementing
<exprfield>.


> I ask because we have a Google
> Summer of Code student working on Python code to read these
> things, and I'm sure he'll be interested :-).
> 
> Looks like fun.  Let us know if we can help.

Yes I discovered those Summer of Code projects last week after I
started working on this. :-) The students are of course welcome to use
my code (if SoC allows that?).  It could be useful for generating test
cases.  It sounds like there could be a lot of overlap with XCBScope.

Cheers,
Mark


More information about the Xcb mailing list