diff -r ad51ed93377c Lib/shlex.py --- a/Lib/shlex.py Thu Oct 11 00:11:26 2012 -0700 +++ b/Lib/shlex.py Thu Oct 11 14:17:26 2012 -0500 @@ -27,14 +27,10 @@ self.instream = sys.stdin self.infile = None self.posix = posix - if posix: - self.eof = None - else: - self.eof = '' self.commenters = '#' self.wordchars = ('abcdfeghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_') - if self.posix: + if self._posix: self.wordchars += ('ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ' 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ') self.whitespace = ' \t\r\n' @@ -53,6 +49,17 @@ print('shlex: reading from %s, line %d' \ % (self.instream, self.lineno)) + def _get_posix(self): + return self._posix + + def _set_posix(self, posix): + self._posix = posix + if posix: + self.eof = None + else: + self.eof = '' + posix = property(_get_posix, _set_posix) + def push_token(self, tok): "Push a token onto the stack popped by the get_token method" if self.debug >= 1: @@ -134,21 +141,21 @@ elif nextchar in self.whitespace: if self.debug >= 2: print("shlex: I see whitespace in whitespace state") - if self.token or (self.posix and quoted): + if self.token or (self._posix and quoted): 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: + elif self._posix and nextchar in self.escape: escapedstate = 'a' self.state = nextchar elif nextchar in self.wordchars: self.token = nextchar self.state = 'a' elif nextchar in self.quotes: - if not self.posix: + if not self._posix: self.token = nextchar self.state = nextchar elif self.whitespace_split: @@ -156,7 +163,7 @@ self.state = 'a' else: self.token = nextchar - if self.token or (self.posix and quoted): + if self.token or (self._posix and quoted): break # emit current token else: continue @@ -168,13 +175,13 @@ # XXX what error should be raised here? raise ValueError("No closing quotation") if nextchar == self.state: - if not self.posix: + if not self._posix: self.token = self.token + nextchar self.state = ' ' break else: self.state = 'a' - elif self.posix and nextchar in self.escape and \ + elif self._posix and nextchar in self.escape and \ self.state in self.escapedquotes: escapedstate = self.state self.state = nextchar @@ -201,22 +208,22 @@ if self.debug >= 2: print("shlex: I see whitespace in word state") self.state = ' ' - if self.token or (self.posix and quoted): + if self.token or (self._posix and quoted): break # emit current token else: continue elif nextchar in self.commenters: self.instream.readline() self.lineno = self.lineno + 1 - if self.posix: + if self._posix: self.state = ' ' - if self.token or (self.posix and quoted): + if self.token or (self._posix and quoted): break # emit current token else: continue - elif self.posix and nextchar in self.quotes: + elif self._posix and nextchar in self.quotes: self.state = nextchar - elif self.posix and nextchar in self.escape: + elif self._posix and nextchar in self.escape: escapedstate = 'a' self.state = nextchar elif nextchar in self.wordchars or nextchar in self.quotes \ @@ -233,7 +240,7 @@ continue result = self.token self.token = '' - if self.posix and not quoted and result == '': + if self._posix and not quoted and result == '': result = None if self.debug > 1: if result: diff -r ad51ed93377c Lib/test/test_shlex.py --- a/Lib/test/test_shlex.py Thu Oct 11 00:11:26 2012 -0700 +++ b/Lib/test/test_shlex.py Thu Oct 11 14:17:26 2012 -0500 @@ -189,6 +189,12 @@ self.assertEqual(shlex.quote("test%s'name'" % u), "'test%s'\"'\"'name'\"'\"''" % u) + def testPosixAttribute(self): + s = shlex.shlex(r"", posix=False) + s.posix = True + self.assertEqual(s.eof, None) + s.posix = False + self.assertEqual(s.eof, '') # Allow this test to be used with old shlex.py if not getattr(shlex, "split", None):