1010import os .path
1111import sys
1212
13- from types import StringTypes
14-
1513try :
1614 from cStringIO import StringIO
1715except ImportError :
2220class 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