MCPcopy Index your code
hub / github.com/python/cpython / read_token

Method read_token

Lib/shlex.py:131–275  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

129 return raw
130
131 def read_token(self):
132 quoted = False
133 escapedstate = ' '
134 while True:
135 if self.punctuation_chars and self._pushback_chars:
136 nextchar = self._pushback_chars.pop()
137 else:
138 nextchar = self.instream.read(1)
139 if nextchar == '\n':
140 self.lineno += 1
141 if self.debug >= 3:
142 print("shlex: in state %r I see character: %r" % (self.state,
143 nextchar))
144 if self.state is None:
145 self.token = '' # past end of file
146 break
147 elif self.state == ' ':
148 if not nextchar:
149 self.state = None # end of file
150 break
151 elif nextchar in self.whitespace:
152 if self.debug >= 2:
153 print("shlex: I see whitespace in whitespace state")
154 if self.token or (self.posix and quoted):
155 break # emit current token
156 else:
157 continue
158 elif nextchar in self.commenters:
159 self.instream.readline()
160 self.lineno += 1
161 elif self.posix and nextchar in self.escape:
162 escapedstate = 'a'
163 self.state = nextchar
164 elif nextchar in self.wordchars:
165 self.token = nextchar
166 self.state = 'a'
167 elif nextchar in self.punctuation_chars:
168 self.token = nextchar
169 self.state = 'c'
170 elif nextchar in self.quotes:
171 if not self.posix:
172 self.token = nextchar
173 self.state = nextchar
174 elif self.whitespace_split:
175 self.token = nextchar
176 self.state = 'a'
177 else:
178 self.token = nextchar
179 if self.token or (self.posix and quoted):
180 break # emit current token
181 else:
182 continue
183 elif self.state in self.quotes:
184 quoted = True
185 if not nextchar: # end of file
186 if self.debug >= 2:
187 print("shlex: I see EOF in quotes state")
188 # XXX what error should be raised here?

Callers 1

get_tokenMethod · 0.95

Calls 4

popMethod · 0.45
readMethod · 0.45
readlineMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected