summaryrefslogtreecommitdiff
path: root/Lib/shlex.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-01-29 06:37:52 +0000
committerRaymond Hettinger <python@rcn.com>2004-01-29 06:37:52 +0000
commit7061d55274fc384817180e73130e35c1e19d52b5 (patch)
treee86d801b425532a28feb26b7c46e44082ff3f93e /Lib/shlex.py
parentb49ed8a7025b95f002f7a069492d9f8181e3fa63 (diff)
downloadcpython-7061d55274fc384817180e73130e35c1e19d52b5.tar.gz
* 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 b302699c76..ccf903898a 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 = ' '