summaryrefslogtreecommitdiffstats
path: root/Lib/shlex.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-01-29 06:37:52 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-01-29 06:37:52 (GMT)
commit756b3f3c15bd314ffa25299ca25465ae21e62a30 (patch)
treef504d3ab53c151b7e88ebfebd069a034f80f5025 /Lib/shlex.py
parent141d4e564314abde44189eb5e3a9f509dab045ff (diff)
downloadcpython-756b3f3c15bd314ffa25299ca25465ae21e62a30.zip
cpython-756b3f3c15bd314ffa25299ca25465ae21e62a30.tar.gz
cpython-756b3f3c15bd314ffa25299ca25465ae21e62a30.tar.bz2
* Move collections.deque() in from the sandbox
* Add unittests, newsitem, and whatsnew * Apply to Queue.py mutex.py threading.py pydoc.py and shlex.py * Docs are forthcoming
Diffstat (limited to 'Lib/shlex.py')
-rw-r--r--Lib/shlex.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/shlex.py b/Lib/shlex.py
index b302699..ccf9038 100644
--- a/Lib/shlex.py
+++ b/Lib/shlex.py
@@ -9,6 +9,7 @@
import os.path
import sys
+from collections import deque
try:
from cStringIO import StringIO
@@ -45,11 +46,11 @@ class shlex:
self.escape = '\\'
self.escapedquotes = '"'
self.state = ' '
- self.pushback = []
+ self.pushback = deque()
self.lineno = 1
self.debug = 0
self.token = ''
- self.filestack = []
+ self.filestack = deque()
self.source = None
if self.debug:
print 'shlex: reading from %s, line %d' \
@@ -59,13 +60,13 @@ class shlex:
"Push a token onto the stack popped by the get_token method"
if self.debug >= 1:
print "shlex: pushing token " + `tok`
- self.pushback.insert(0, tok)
+ self.pushback.appendleft(tok)
def push_source(self, newstream, newfile=None):
"Push an input source onto the lexer's input source stack."
if isinstance(newstream, basestring):
newstream = StringIO(newstream)
- self.filestack.insert(0, (self.infile, self.instream, self.lineno))
+ self.filestack.appendleft((self.infile, self.instream, self.lineno))
self.infile = newfile
self.instream = newstream
self.lineno = 1
@@ -78,8 +79,7 @@ class shlex:
def pop_source(self):
"Pop the input source stack."
self.instream.close()
- (self.infile, self.instream, self.lineno) = self.filestack[0]
- self.filestack = self.filestack[1:]
+ (self.infile, self.instream, self.lineno) = self.filestack.popleft()
if self.debug:
print 'shlex: popping to %s, line %d' \
% (self.instream, self.lineno)
@@ -88,7 +88,7 @@ class shlex:
def get_token(self):
"Get a token from the input stream (or from stack if it's nonempty)"
if self.pushback:
- tok = self.pushback.pop(0)
+ tok = self.pushback.popleft()
if self.debug >= 1:
print "shlex: popping token " + `tok`
return tok
@@ -226,7 +226,7 @@ class shlex:
or self.whitespace_split:
self.token = self.token + nextchar
else:
- self.pushback.insert(0, nextchar)
+ self.pushback.appendleft(nextchar)
if self.debug >= 2:
print "shlex: I see punctuation in word state"
self.state = ' '