Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv6672
Modified Files:
bits.py
Log Message:
minor cleanup of Bits.__getitem__ and Bits.__setitem__
Index: bits.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/bits.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- bits.py 26 Apr 2003 21:33:49 -0000 1.9
+++ bits.py 27 Apr 2003 07:33:24 -0000 1.10
@@ -40,27 +40,26 @@
def __getitem__ (this, index):
if isinstance(index, SliceType):
- if index.start == None or index.stop != None or \
- not index.step in (1, 2, 4):
+ start, stop, step = index.start, index.stop, index.step
+ if start == None or stop != None or not step in (1, 2, 4):
raise 'Bad slice for Bits.__getitem__', index
- if index.step == 1: return ord(this._contents[index.start])
+ if step == 1: return ord(this._contents[start])
else:
- data = this._contents[index.start : index.start + index.step]
- tpl = this._byte_order + {2: 'H', 4: 'L'}[index.step]
+ data = this._contents[start : start + step]
+ tpl = this._byte_order + {2: 'H', 4: 'L'}[step]
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):
+ start, stop, step = index.start, index.stop, index.step
+ if start == None or stop != None or not step in (1, 2, 4):
raise 'Bad slice for Bits.__setitem__', index
- if index.start > len(this._contents):
- raise IndexError, index.start
- if index.step == 1: this._contents[index.start] = chr(value % 0x100)
+ 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'}[index.step]
- this._contents[index.start : index.start + index.step] = \
- array('c', pack(tpl, value % (1L << (index.step << 3))))
+ tpl = this._byte_order + {2: 'H', 4: 'L'}[step]
+ this._contents[start : start + step] = \
+ array('c', pack(tpl, value % (1L << (step << 3))))
else:
if index > len(this._contents):
raise IndexError, index
|