[Wisp-cvs] wisp/users/dig bindump.py,1.1,1.2
Status: Alpha
Brought to you by:
digg
From: <di...@us...> - 2003-04-14 23:38:00
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv2708 Modified Files: bindump.py Log Message: wrote shorthex and ftake Index: bindump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/bindump.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- bindump.py 14 Apr 2003 22:31:23 -0000 1.1 +++ bindump.py 14 Apr 2003 23:37:56 -0000 1.2 @@ -11,6 +11,7 @@ from __future__ import nested_scopes import string +import struct def state_enum (field_name, value, dict): print '%s: %i' % (field_name, value), @@ -44,3 +45,15 @@ else: return all[start:stop] +def shorthex (s): + return ' '.join(['%02X' % ord(c) for c in s]) + +def ftake (f, tpl): + amount = 0 + struc = '<' + for c in tpl: + amount += {'b': 1, 'w': 2, 't': 4}[c] + struc += {'b': 'B', 'w': 'H', 't': 'L'}[c] + data = struct.unpack(struc, f.read(amount)) + if len(data) == 1: data, = data + return data |