[Wisp-cvs] wisp/users/dig bits.py,1.2,1.3
Status: Alpha
Brought to you by:
digg
From: <di...@us...> - 2003-04-26 21:08:44
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv8331 Modified Files: bits.py Log Message: introduced Bits.__setitem__ Index: bits.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/bits.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- bits.py 26 Apr 2003 20:56:56 -0000 1.2 +++ bits.py 26 Apr 2003 21:08:40 -0000 1.3 @@ -65,5 +65,16 @@ else: data = this._contents[index.start : index.start + index.step] tpl = this._byte_order + {2: 'H', 4: 'L'}[index.step] - return unpack(tpl, data) + return unpack(tpl, data)[0] + else: return ord(this._contents[index]) + def __setitem__ (this, index, value): + if isinstance(index, SliceType): + if index.start == None or index.stop != None or \ + not index.step in (1, 2, 4): + raise 'Bad slice for Bits.__getitem__', index + if index.step == 1: this._contents[index.start] = chr(value % 0x100) + else: + tpl = this._byte_order + {2: 'H', 4: 'L'}[index.step] + this._contents[index.start : index.start + index.step] = \ + array('c', pack(tpl, value % (1L << (index.step << 3)))) else: return ord(this._contents[index]) |