So, the meeting happened, and I meant to do a report on it. Sorry for
the delay.
Present were Tom, Joe, Peter, Robin, Bryan and myself.
We started off by talking over the recent PyConUK - Joe and I had both
been there. Much of the talk had been on Larch, which Tom had also
been reading about elsewhere. There are interesting videos linked off
its homepage at
https://sites.google.com/site/larchenv/. I recommend
looking - it's not really quite like anything else, and the talk at
the conference was one of the high points for me.
Tom did finally drag us back to the idea that we should do some
coding, and we revisited some of the ideas of the last coding session,
and how one goes about parsing binary formats in a simple, friendly
manner. His idea was that it would be interesting to look at what we
thought would be a simple way (so not much code) to describe (at
first) simple formats. We got a little way with this approach, but
might have gotten further if we'd been wiling to look at the
documentation (perhaps it was more fun to think of things from first
principle - this works better in Python than some other places).
I'll paste the small amount of code/text we developed below - I'm not
entirely sure if it will survive my hitting the "send" button...
class Field(object):
order = {}
names = {}
def __init__(self):
Field.order[self] = len(Field.order)
class UInt32(Field):
pass
class MetaStructure(type):
def __new__(klass, bases, attributes):
print 'm.__new__', bases, attributes
for k in attributes:
Field.name[attributes[k]] = k
return type.__new__(klass, bases, attributes)
def __init__(self, *args, **kwargs):
print 'm.__init__', args, kwargs
class Structure(object):
__metaclass__ = MetaStructure
def __new__(klass, *args, **kwargs):
print '__new__', args, kwargs
return object.__new__(klass)
def __init__(self, *args, **kwargs):
print '__init__', args, kwargs
class Spam(Structure):
file_length = UInt32()
x = UInt32()
spam = Spam(3, spam='beans')
print Field.order
print Field.names
# How to specify arrays?
# array_no1 = Array(UInt32, 4) # simple and explicit
# array_no2 = [UInt32() for _ in range(4)] # hard to make it do
what we want
# array_no3 = Uint32[4]() # Tom's suggestion
# array_no4 = Uint32()*4 # compare with numpy
# array_no5 = Uint32(repeat=4)
# name = NullTerminatedString()
# str_len = SByte()
# manifest = CountedString(size=str_len)
# vim: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: