Bob Ippolito (@etrepum) on Haskell, Python, Erlang, JavaScript, etc.

aeve-o-rama vol.1


I've been working on totally rewriting aeve the past well, too long. This week I've made some huge progress. This is the beginning of a series of blog entries where I'm going to talk about the different components of aeve. I will probably only talk about ones that are finished, or mostly finished :) Today I'm just going to stick to the ones that have nothing in particular to do with Apple Events.


aeve._hacks is a package where I store things I shouldn't have to do, and it is the source of any import time side-effects that aeve has. Currently the only things in there are the Python 2.4 CVS versions of applesingle, and pprint. applesingle was replaced because it throws a string exception and because it has warnings. pprint was replaced because the Python 2.3 version won't pretty-print subclasses of pretty-printable types. Both of these hacks happen immediately on import of the aeve package, but nothing happens if you happen to be running a build of Python 2.4.


aeve.util is my repository for generic usable-elsewhere cross-platform Python code. I am pretty sure that I'm done with all of the modules in here.


This is one of my favories, and is strangely enough inspired by a similar construct in C#. In C# you can add metadata to just about anything (I think it's called attributes). You can, of course, do this in Python, but it's less of a "meta-protocol" than it is in C# (which has syntax support for the feature). aeve carries around a lot of enumerations whose enumerators need to carry around metadata (such as enumeration it came from, or its name). It works by making a per-enumeration subclass of the desired base type that has a modified __new__ and __repr__, and carries around a reference to the parent enumeration. The base type is typically int but in aeve it's usually a FourCharCode. FourCharCode is a str subclass that will __new__ from an int by struct.pack. The reason for this (as opposed to regular str) is that new-style Apple header files use integers to represent four char codes that contain macroman characters, presumably so that the header files are unix-tool friendly (7-bit unambiguous good ol' american ASCII). Enough of that, this is how it looks:

>>> from aeve.util import Enumerations
>>> class MyEnum(Enumerations.Enumeration):
...   a = 1
...   b = 2
>>> MyEnum.a
>>> MyEnum.a + 4
>>> MyEnum.fromName('a')
>>> MyEnum.fromValue(1)
>>> MyEnum.fromValue(1).enumeration
<class '__main__.MyEnum'>


I've talked about this one before, but I just want to let Just know that I took all the lambdas out ;) NamedTuple is used to build magically delicious tuple trees out of terminologies. I wrote this so that I could introspect the objects (used in aeteViewer: pdf screenshot), but primarily because using named attributes instead of arbitrary indexes is a whole hell of a lot nicer to look at. It's now relatively easy to tell what aeve.compiler.core is doing, for example.


Here's where I'm going to stash all of the generic descriptors I need. So far, I've only used one generic descriptor: metamethod. This has been discussed previously, I used Phillip's implementation.


microfailure is a homebrew version of twisted.python.failure. I just use it to capture exceptions and pass them along "safely" without ignoring them. It's used by aeve.terminology.resfinder and aeve.compiler.core.


namemangling makes strings safe for python names/atributes by appending underscores and replacing unicode with ascii. This is so it doesn't clash with a keyword or builtin. It will do substitution of particular unicode characters such as u'N{DIVISION SIGN}' (aka ÷) with pythonic ascii names like 'div'. If it doesn't have a built-in translation it will use, or at worst case, it will use the hex representation of the unichar.

... to be continued