[Wisp-cvs] wisp/users/dig bits.py,1.12,1.13
Status: Alpha
Brought to you by:
digg
From: <di...@us...> - 2003-04-27 08:24:53
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv2388 Modified Files: bits.py Log Message: extracted Bits.set_single_item from Bits.__setitem__ Index: bits.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/bits.py,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- bits.py 27 Apr 2003 07:53:02 -0000 1.12 +++ bits.py 27 Apr 2003 08:24:50 -0000 1.13 @@ -49,6 +49,14 @@ tpl = this._byte_order + {2: 'H', 4: 'L'}[step] return unpack(tpl, data)[0] else: return ord(this._contents[index]) + def set_single_item (this, index, step, value): # for easy extension + if index < 0 or index > len(this._contents): + raise IndexError, index + if step == 1: this._contents[start] = chr(value % 0x100) + else: + tpl = this._byte_order + {2: 'H', 4: 'L'}[step] + this._contents[index : index + step] = \ + array('c', pack(tpl, value % (1L << (step << 3)))) def __setitem__ (this, index, value): if isinstance(index, SliceType): start, stop, step = index.start, index.stop, index.step @@ -62,12 +70,6 @@ if stop != None or not step in (1, 2, 4): raise 'Bad slice for Bits.__setitem__', index if start > len(this._contents): raise IndexError, start - if step == 1: this._contents[start] = chr(value % 0x100) - else: - tpl = this._byte_order + {2: 'H', 4: 'L'}[step] - this._contents[start : start + step] = \ - array('c', pack(tpl, value % (1L << (step << 3)))) + this.set_single_item(start, step, value) else: - if index > len(this._contents): - raise IndexError, index this._contents[index] = chr(value % 0x100) |