Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv22906
Modified Files:
bits.py
Log Message:
introduced Bits.emit_single_item
Index: bits.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/bits.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- bits.py 27 Apr 2003 08:24:50 -0000 1.13
+++ bits.py 27 Apr 2003 11:37:13 -0000 1.14
@@ -57,19 +57,18 @@
tpl = this._byte_order + {2: 'H', 4: 'L'}[step]
this._contents[index : index + step] = \
array('c', pack(tpl, value % (1L << (step << 3))))
+ def emit_single_item (this, step, value): # for easy extension
+ this.set_single_item(len(this._contents), step, value)
def __setitem__ (this, index, value):
if isinstance(index, SliceType):
start, stop, step = index.start, index.stop, index.step
- if start == None:
- if isinstance(value, int) or isinstance(value, long):
- start = len(this._contents)
- else:
- for v in value:
- this.__setitem__(index, v)
- return
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
- this.set_single_item(start, step, value)
else:
- this._contents[index] = chr(value % 0x100)
+ start, stop, step = index, None, 1
+ if start == None: # emit
+ if isinstance(value, int) or isinstance(value, long):
+ this.emit_single_item(step, value)
+ else:
+ for v in value: this.emit_single_item(step, value)
+ else: this.set_single_item(start, step, value)
|