Added allowed escaped strings to shlex.py

This commit is contained in:
Jeremy Fincher 2003-04-14 07:17:48 +00:00
parent 5c3cf2bc93
commit f5cf223ea6

View File

@ -28,6 +28,7 @@ class shlex:
self.lineno = 1 self.lineno = 1
self.debug = 0 self.debug = 0
self.token = '' self.token = ''
self.backslash = False
self.filestack = [] self.filestack = []
self.source = None self.source = None
if self.debug: if self.debug:
@ -134,9 +135,14 @@ class shlex:
continue continue
elif self.state in self.quotes: elif self.state in self.quotes:
self.token = self.token + nextchar self.token = self.token + nextchar
if nextchar == self.state: if nextchar == '\\':
self.backslash = True
else:
if not self.backslash and nextchar == self.state:
self.state = ' ' self.state = ' '
break break
elif self.backslash:
self.backslash = False
elif not nextchar: # end of file elif not nextchar: # end of file
if self.debug >= 2: if self.debug >= 2:
print "shlex: I see EOF in quotes state" print "shlex: I see EOF in quotes state"
@ -157,11 +163,8 @@ class shlex:
elif nextchar in self.commenters: elif nextchar in self.commenters:
self.instream.readline() self.instream.readline()
self.lineno = self.lineno + 1 self.lineno = self.lineno + 1
elif nextchar in self.wordchars: elif nextchar in self.wordchars or nextchar in self.quotes:
self.token = self.token + nextchar self.token = self.token + nextchar
elif nextchar in self.quotes:
self.state = nextchar
break
else: else:
self.pushback = [nextchar] + self.pushback self.pushback = [nextchar] + self.pushback
if self.debug >= 2: if self.debug >= 2:
@ -210,4 +213,3 @@ if __name__ == '__main__':
print "Token: " + repr(tt) print "Token: " + repr(tt)
else: else:
break break
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: