Use True in a few more places.

Use isinstance(somestring, basestring) instead of type() as per PEP 8
This commit is contained in:
Neal Norwitz 2003-04-17 23:09:08 +00:00
parent a6bdf2aef6
commit 10cf21802d
2 changed files with 6 additions and 8 deletions

View File

@ -177,7 +177,7 @@ includes just \character{"} by default.
\end{memberdesc} \end{memberdesc}
\begin{memberdesc}{whitespace_split} \begin{memberdesc}{whitespace_split}
If true, tokens will only be split in whitespaces. This is useful, for If \code{True}, tokens will only be split in whitespaces. This is useful, for
example, for parsing command lines with \class{shlex}, getting tokens example, for parsing command lines with \class{shlex}, getting tokens
in a similar way to shell arguments. in a similar way to shell arguments.
\versionadded{2.3} \versionadded{2.3}

View File

@ -10,8 +10,6 @@
import os.path import os.path
import sys import sys
from types import StringTypes
try: try:
from cStringIO import StringIO from cStringIO import StringIO
except ImportError: except ImportError:
@ -22,7 +20,7 @@
class shlex: class shlex:
"A lexical analyzer class for simple shell-like syntaxes." "A lexical analyzer class for simple shell-like syntaxes."
def __init__(self, instream=None, infile=None, posix=False): def __init__(self, instream=None, infile=None, posix=False):
if type(instream) in StringTypes: if isinstance(instream, basestring):
instream = StringIO(instream) instream = StringIO(instream)
if instream is not None: if instream is not None:
self.instream = instream self.instream = instream
@ -65,7 +63,7 @@ def push_token(self, tok):
def push_source(self, newstream, newfile=None): def push_source(self, newstream, newfile=None):
"Push an input source onto the lexer's input source stack." "Push an input source onto the lexer's input source stack."
if type(newstream) in StringTypes: if isinstance(newstream, basestring):
newstream = StringIO(newstream) newstream = StringIO(newstream)
self.filestack.insert(0, (self.infile, self.instream, self.lineno)) self.filestack.insert(0, (self.infile, self.instream, self.lineno))
self.infile = newfile self.infile = newfile
@ -122,7 +120,7 @@ def get_token(self):
def read_token(self): def read_token(self):
quoted = False quoted = False
escapedstate = ' ' escapedstate = ' '
while 1: while True:
nextchar = self.instream.read(1) nextchar = self.instream.read(1)
if nextchar == '\n': if nextchar == '\n':
self.lineno = self.lineno + 1 self.lineno = self.lineno + 1
@ -252,7 +250,7 @@ def sourcehook(self, newfile):
if newfile[0] == '"': if newfile[0] == '"':
newfile = newfile[1:-1] newfile = newfile[1:-1]
# This implements cpp-like semantics for relative-path inclusion. # This implements cpp-like semantics for relative-path inclusion.
if type(self.infile) in StringTypes and not os.path.isabs(newfile): if isinstance(self.infile, basestring) and not os.path.isabs(newfile):
newfile = os.path.join(os.path.dirname(self.infile), newfile) newfile = os.path.join(os.path.dirname(self.infile), newfile)
return (newfile, open(newfile, "r")) return (newfile, open(newfile, "r"))
@ -273,7 +271,7 @@ def next(self):
raise StopIteration raise StopIteration
return token return token
def split(s, posix=1, spaces=1): def split(s, posix=True, spaces=True):
lex = shlex(s, posix=posix) lex = shlex(s, posix=posix)
lex.whitespace_split = spaces lex.whitespace_split = spaces
return list(lex) return list(lex)