summaryrefslogtreecommitdiff
path: root/src/poezio_shlex.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-04-28 00:20:57 +0200
committermathieui <mathieui@mathieui.net>2014-04-28 00:20:57 +0200
commit069283e349b2e8dd324446aa5c30253a0993f1a3 (patch)
tree23433948b69cce0e41b5f32acd8fa8d30b19fb50 /src/poezio_shlex.py
parent31716565a74bcc3c41569297c4c8ddfe731ba364 (diff)
downloadpoezio-069283e349b2e8dd324446aa5c30253a0993f1a3.tar.gz
poezio-069283e349b2e8dd324446aa5c30253a0993f1a3.tar.bz2
poezio-069283e349b2e8dd324446aa5c30253a0993f1a3.tar.xz
poezio-069283e349b2e8dd324446aa5c30253a0993f1a3.zip
Don’t escape backslashes unless we are inside a quoted string and the next char is a quote
Sadly, we can’t doctest stuff with backslashes because it drives doctest crazy.
Diffstat (limited to 'src/poezio_shlex.py')
-rw-r--r--src/poezio_shlex.py21
1 files changed, 4 insertions, 17 deletions
diff --git a/src/poezio_shlex.py b/src/poezio_shlex.py
index 086b0707..032baeee 100644
--- a/src/poezio_shlex.py
+++ b/src/poezio_shlex.py
@@ -102,6 +102,7 @@ class shlex(object):
escapedstate = ' '
token_start = 0
token_end = -1
+ # read one char from the stream at once
while True:
nextchar = self.instream.read(1)
if nextchar == '\n':
@@ -126,13 +127,6 @@ class shlex(object):
break # emit current token
else:
continue
- elif nextchar in self.commenters:
- self.instream.readline()
- self.lineno = self.lineno + 1
- elif self.posix and nextchar in self.escape:
- token_start = self.instream.tell() - 1
- escapedstate = 'a'
- self.state = nextchar
elif nextchar in self.wordchars:
token_start = self.instream.tell() - 1
self.token = nextchar
@@ -181,10 +175,8 @@ class shlex(object):
# XXX what error should be raised here?
token_end = self.instream.tell()
break
- # In posix shells, only the quote itself or the escape
- # character may be escaped within quotes.
- if escapedstate in self.quotes and \
- nextchar != self.state and nextchar != escapedstate:
+ # only the quote may be escaped
+ if escapedstate in self.quotes and nextchar != escapedstate:
self.token = self.token + self.state
self.token = self.token + nextchar
self.state = escapedstate
@@ -202,13 +194,8 @@ class shlex(object):
break # emit current token
else:
continue
- elif self.posix and nextchar in self.quotes:
- self.state = nextchar
- elif self.posix and nextchar in self.escape:
- escapedstate = 'a'
- self.state = nextchar
elif nextchar in self.wordchars or nextchar in self.quotes \
- or self.whitespace_split:
+ or self.whitespace_split:
self.token = self.token + nextchar
else:
self.pushback.appendleft(nextchar)