Code modernization. Replace v=s[i]; del s[i] with single lookup v=s.pop(i)

This commit is contained in:
Raymond Hettinger 2002-06-30 03:39:14 +00:00
parent 78e057a32a
commit 46ac8eb3c8
11 changed files with 19 additions and 42 deletions

View File

@ -146,6 +146,4 @@ class Queue:
# Get an item from the queue # Get an item from the queue
def _get(self): def _get(self):
item = self.queue[0] return self.queue.pop(0)
del self.queue[0]
return item

View File

@ -269,9 +269,7 @@ class fifo:
def pop (self): def pop (self):
if self.list: if self.list:
result = self.list[0] return (1, self.list.pop(0))
del self.list[0]
return (1, result)
else: else:
return (0, None) return (0, None)

View File

@ -323,8 +323,7 @@ def parse_header(line):
""" """
plist = map(lambda x: x.strip(), line.split(';')) plist = map(lambda x: x.strip(), line.split(';'))
key = plist[0].lower() key = plist.pop(0).lower()
del plist[0]
pdict = {} pdict = {}
for p in plist: for p in plist:
i = p.find('=') i = p.find('=')

View File

@ -109,8 +109,7 @@ class Cmd:
stop = None stop = None
while not stop: while not stop:
if self.cmdqueue: if self.cmdqueue:
line = self.cmdqueue[0] line = self.cmdqueue.pop(0)
del self.cmdqueue[0]
else: else:
if self.use_rawinput: if self.use_rawinput:
try: try:
@ -261,11 +260,10 @@ class Cmd:
names = [] names = []
classes = [self.__class__] classes = [self.__class__]
while classes: while classes:
aclass = classes[0] aclass = classes.pop(0)
if aclass.__bases__: if aclass.__bases__:
classes = classes + list(aclass.__bases__) classes = classes + list(aclass.__bases__)
names = names + dir(aclass) names = names + dir(aclass)
del classes[0]
return names return names
def complete_help(self, *args): def complete_help(self, *args):

View File

@ -973,11 +973,10 @@ class IMAP4:
return typ, dat return typ, dat
if not name in self.untagged_responses: if not name in self.untagged_responses:
return typ, [None] return typ, [None]
data = self.untagged_responses[name] data = self.untagged_responses.pop(name)
if __debug__: if __debug__:
if self.debug >= 5: if self.debug >= 5:
self._mesg('untagged_responses[%s] => %s' % (name, data)) self._mesg('untagged_responses[%s] => %s' % (name, data))
del self.untagged_responses[name]
return typ, data return typ, data

View File

@ -202,8 +202,7 @@ class MHMailbox:
def next(self): def next(self):
if not self.boxes: if not self.boxes:
return None return None
fn = self.boxes[0] fn = self.boxes.pop(0)
del self.boxes[0]
fp = open(os.path.join(self.dirname, fn)) fp = open(os.path.join(self.dirname, fn))
return self.factory(fp) return self.factory(fp)
@ -233,8 +232,7 @@ class Maildir:
def next(self): def next(self):
if not self.boxes: if not self.boxes:
return None return None
fn = self.boxes[0] fn = self.boxes.pop(0)
del self.boxes[0]
fp = open(fn) fp = open(fn)
return self.factory(fp) return self.factory(fp)

View File

@ -160,8 +160,7 @@ class MultiFile:
self.level = max(0, self.level - 1) self.level = max(0, self.level - 1)
del self.stack[0] del self.stack[0]
if self.seekable: if self.seekable:
self.start = self.posstack[0] self.start = self.posstack.pop(0)
del self.posstack[0]
if self.level > 0: if self.level > 0:
self.lastpos = abslastpos - self.start self.lastpos = abslastpos - self.start

View File

@ -44,8 +44,7 @@ class mutex:
"""Unlock a mutex. If the queue is not empty, call the next """Unlock a mutex. If the queue is not empty, call the next
function with its argument.""" function with its argument."""
if self.queue: if self.queue:
function, argument = self.queue[0] function, argument = self.queue.pop(0)
del self.queue[0]
function(argument) function(argument)
else: else:
self.locked = 0 self.locked = 0

View File

@ -692,11 +692,7 @@ class Unpickler:
dispatch[PERSID] = load_persid dispatch[PERSID] = load_persid
def load_binpersid(self): def load_binpersid(self):
stack = self.stack pid = self.stack.pop()
pid = stack[-1]
del stack[-1]
self.append(self.persistent_load(pid)) self.append(self.persistent_load(pid))
dispatch[BINPERSID] = load_binpersid dispatch[BINPERSID] = load_binpersid
@ -977,8 +973,7 @@ class Unpickler:
def load_append(self): def load_append(self):
stack = self.stack stack = self.stack
value = stack[-1] value = stack.pop()
del stack[-1]
list = stack[-1] list = stack[-1]
list.append(value) list.append(value)
dispatch[APPEND] = load_append dispatch[APPEND] = load_append
@ -995,9 +990,8 @@ class Unpickler:
def load_setitem(self): def load_setitem(self):
stack = self.stack stack = self.stack
value = stack[-1] value = stack.pop()
key = stack[-2] key = stack.pop()
del stack[-2:]
dict = stack[-1] dict = stack[-1]
dict[key] = value dict[key] = value
dispatch[SETITEM] = load_setitem dispatch[SETITEM] = load_setitem
@ -1014,8 +1008,7 @@ class Unpickler:
def load_build(self): def load_build(self):
stack = self.stack stack = self.stack
value = stack[-1] value = stack.pop()
del stack[-1]
inst = stack[-1] inst = stack[-1]
try: try:
setstate = inst.__setstate__ setstate = inst.__setstate__
@ -1038,8 +1031,7 @@ class Unpickler:
dispatch[MARK] = load_mark dispatch[MARK] = load_mark
def load_stop(self): def load_stop(self):
value = self.stack[-1] value = self.stack.pop()
del self.stack[-1]
raise _Stop(value) raise _Stop(value)
dispatch[STOP] = load_stop dispatch[STOP] = load_stop

View File

@ -633,8 +633,7 @@ def _test():
while not self.queue: while not self.queue:
self._note("get(): queue empty") self._note("get(): queue empty")
self.rc.wait() self.rc.wait()
item = self.queue[0] item = self.queue.pop(0)
del self.queue[0]
self._note("get(): got %s, %d left", item, len(self.queue)) self._note("get(): got %s, %d left", item, len(self.queue))
self.wc.notify() self.wc.notify()
self.mon.release() self.mon.release()

View File

@ -779,16 +779,14 @@ class Unmarshaller:
dispatch["name"] = end_string # struct keys are always strings dispatch["name"] = end_string # struct keys are always strings
def end_array(self, data): def end_array(self, data):
mark = self._marks[-1] mark = self._marks.pop()
del self._marks[-1]
# map arrays to Python lists # map arrays to Python lists
self._stack[mark:] = [self._stack[mark:]] self._stack[mark:] = [self._stack[mark:]]
self._value = 0 self._value = 0
dispatch["array"] = end_array dispatch["array"] = end_array
def end_struct(self, data): def end_struct(self, data):
mark = self._marks[-1] mark = self._marks.pop()
del self._marks[-1]
# map structs to Python dictionaries # map structs to Python dictionaries
dict = {} dict = {}
items = self._stack[mark:] items = self._stack[mark:]