[bind10-dev] Python classes vs modules vs other funny stuff

Jelte Jansen jelte at isc.org
Mon Oct 12 14:52:08 UTC 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael Graff wrote:
> Right now, the message en/decoding library I wrote uses this format:
> 
>   m = ISC.CC.Message()
>   wire_format = m.to_wire({...})
>   decoded = m.from_wire(wire_format)
> 
> What I would like is this:
> 
>   wire_format = ISC.CC.Message.to_wire({...})
>   decoded = ISC.CC.Message.from_wire(wire_format)
> 
> That is, I don't need an instance of a class here, as there is no
> internal state.  Each encode/decode is merely a function, under
> ISC.CC.Message name space.
> 
> I do not know how to do this in Python.  Can someone shed some light on
> this?
> 

if there isn't going to be any internal state, you could just leave out the
class definition there (and the self-references), and declare those functions
directly in message.py

then the test.py script could do something like

import ISC

ss = { "list": [ 1, 2, 3 ],
       "hash": { "hash1": 1, "hash2": 2 },
       "none": None,
       "string": "samplestring" }

s = ISC.CC.message.to_wire(ss)
ISC.Util.hexdump(s)

print ISC.CC.message.from_wire(s)

is that what you are looking for?

Jelte
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkrTQpgACgkQ4nZCKsdOncU1rwCgjKcTHCtbpsSRDvahqHDKdDSi
TzcAoKoheLdI/vsN/QIclpazvJJaIigX
=QWSO
-----END PGP SIGNATURE-----



More information about the bind10-dev mailing list