Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 10cf218

Browse files
committed
Use True in a few more places.
Use isinstance(somestring, basestring) instead of type() as per PEP 8
1 parent a6bdf2a commit 10cf218

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

Doc/lib/libshlex.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ \subsection{shlex Objects \label{shlex-objects}}
177177
\end{memberdesc}
178178

179179
\begin{memberdesc}{whitespace_split}
180-
If true, tokens will only be split in whitespaces. This is useful, for
180+
If \code{True}, tokens will only be split in whitespaces. This is useful, for
181181
example, for parsing command lines with \class{shlex}, getting tokens
182182
in a similar way to shell arguments.
183183
\versionadded{2.3}

Lib/shlex.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import os.path
1111
import sys
1212

13-
from types import StringTypes
14-
1513
try:
1614
from cStringIO import StringIO
1715
except ImportError:
@@ -22,7 +20,7 @@
2220
class shlex:
2321
"A lexical analyzer class for simple shell-like syntaxes."
2422
def __init__(self, instream=None, infile=None, posix=False):
25-
if type(instream) in StringTypes:
23+
if isinstance(instream, basestring):
2624
instream = StringIO(instream)
2725
if instream is not None:
2826
self.instream = instream
@@ -65,7 +63,7 @@ def push_token(self, tok):
6563

6664
def push_source(self, newstream, newfile=None):
6765
"Push an input source onto the lexer's input source stack."
68-
if type(newstream) in StringTypes:
66+
if isinstance(newstream, basestring):
6967
newstream = StringIO(newstream)
7068
self.filestack.insert(0, (self.infile, self.instream, self.lineno))
7169
self.infile = newfile
@@ -122,7 +120,7 @@ def get_token(self):
122120
def read_token(self):
123121
quoted = False
124122
escapedstate = ' '
125-
while 1:
123+
while True:
126124
nextchar = self.instream.read(1)
127125
if nextchar == '\n':
128126
self.lineno = self.lineno + 1
@@ -252,7 +250,7 @@ def sourcehook(self, newfile):
252250
if newfile[0] == '"':
253251
newfile = newfile[1:-1]
254252
# This implements cpp-like semantics for relative-path inclusion.
255-
if type(self.infile) in StringTypes and not os.path.isabs(newfile):
253+
if isinstance(self.infile, basestring) and not os.path.isabs(newfile):
256254
newfile = os.path.join(os.path.dirname(self.infile), newfile)
257255
return (newfile, open(newfile, "r"))
258256

@@ -273,7 +271,7 @@ def next(self):
273271
raise StopIteration
274272
return token
275273

276-
def split(s, posix=1, spaces=1):
274+
def split(s, posix=True, spaces=True):
277275
lex = shlex(s, posix=posix)
278276
lex.whitespace_split = spaces
279277
return list(lex)

0 commit comments

Comments
 (0)