summaryrefslogtreecommitdiffstats
path: root/Lib/asynchat.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-02-07 03:19:10 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-02-07 03:19:10 (GMT)
commitac093c6af04237deceedaab55d299819cbede7f9 (patch)
tree68ee285664c90051f7aa9bb01880a30975a408bf /Lib/asynchat.py
parentc058fd14a9abdffff4f65ebd87a042fad6e68a2e (diff)
downloadcpython-ac093c6af04237deceedaab55d299819cbede7f9.zip
cpython-ac093c6af04237deceedaab55d299819cbede7f9.tar.gz
cpython-ac093c6af04237deceedaab55d299819cbede7f9.tar.bz2
Use collection.deque() instead of a list for a FIFO queue.
Diffstat (limited to 'Lib/asynchat.py')
-rw-r--r--Lib/asynchat.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/asynchat.py b/Lib/asynchat.py
index dfe5ea6..4bfab30 100644
--- a/Lib/asynchat.py
+++ b/Lib/asynchat.py
@@ -48,6 +48,7 @@ you - by calling your self.found_terminator() method.
import socket
import asyncore
+from collections import deque
class async_chat (asyncore.dispatcher):
"""This is an abstract class. You must derive from this class, and add
@@ -250,9 +251,9 @@ class simple_producer:
class fifo:
def __init__ (self, list=None):
if not list:
- self.list = []
+ self.list = deque()
else:
- self.list = list
+ self.list = deque(list)
def __len__ (self):
return len(self.list)
@@ -261,14 +262,18 @@ class fifo:
return self.list == []
def first (self):
- return self.list[0]
+ it = iter(self.list)
+ try:
+ return it.next()
+ except StopIteration:
+ raise IndexError
def push (self, data):
- self.list.append (data)
+ self.list.append(data)
def pop (self):
if self.list:
- return (1, self.list.pop(0))
+ return (1, self.list.popleft())
else:
return (0, None)