Lines Matching refs:self
21 def __init__(self, instream=None, infile=None, posix=False,
26 self.instream = instream
27 self.infile = infile
29 self.instream = sys.stdin
30 self.infile = None
31 self.posix = posix
33 self.eof = None
35 self.eof = ''
36 self.commenters = '#'
37 self.wordchars = ('abcdfeghijklmnopqrstuvwxyz'
39 if self.posix:
40 self.wordchars += ('ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ'
42 self.whitespace = ' \t\r\n'
43 self.whitespace_split = False
44 self.quotes = '\'"'
45 self.escape = '\\'
46 self.escapedquotes = '"'
47 self.state = ' '
48 self.pushback = deque()
49 self.lineno = 1
50 self.debug = 0
51 self.token = ''
52 self.filestack = deque()
53 self.source = None
58 self._punctuation_chars = punctuation_chars
61 self._pushback_chars = deque()
63 self.wordchars += '~-./*?='
65 t = self.wordchars.maketrans(dict.fromkeys(punctuation_chars))
66 self.wordchars = self.wordchars.translate(t)
69 def punctuation_chars(self):
70 return self._punctuation_chars
72 def push_token(self, tok):
74 if self.debug >= 1:
76 self.pushback.appendleft(tok)
78 def push_source(self, newstream, newfile=None):
82 self.filestack.appendleft((self.infile, self.instream, self.lineno))
83 self.infile = newfile
84 self.instream = newstream
85 self.lineno = 1
86 if self.debug:
88 print('shlex: pushing to file %s' % (self.infile,))
90 print('shlex: pushing to stream %s' % (self.instream,))
92 def pop_source(self):
94 self.instream.close()
95 (self.infile, self.instream, self.lineno) = self.filestack.popleft()
96 if self.debug:
98 % (self.instream, self.lineno))
99 self.state = ' '
101 def get_token(self):
103 if self.pushback:
104 tok = self.pushback.popleft()
105 if self.debug >= 1:
109 raw = self.read_token()
111 if self.source is not None:
112 while raw == self.source:
113 spec = self.sourcehook(self.read_token())
116 self.push_source(newstream, newfile)
117 raw = self.get_token()
119 while raw == self.eof:
120 if not self.filestack:
121 return self.eof
123 self.pop_source()
124 raw = self.get_token()
126 if self.debug >= 1:
127 if raw != self.eof:
133 def read_token(self):
137 if self.punctuation_chars and self._pushback_chars:
138 nextchar = self._pushback_chars.pop()
140 nextchar = self.instream.read(1)
142 self.lineno += 1
143 if self.debug >= 3:
144 print("shlex: in state %r I see character: %r" % (self.state,
146 if self.state is None:
147 self.token = '' # past end of file
149 elif self.state == ' ':
151 self.state = None # end of file
153 elif nextchar in self.whitespace:
154 if self.debug >= 2:
156 if self.token or (self.posix and quoted):
160 elif nextchar in self.commenters:
161 self.instream.readline()
162 self.lineno += 1
163 elif self.posix and nextchar in self.escape:
165 self.state = nextchar
166 elif nextchar in self.wordchars:
167 self.token = nextchar
168 self.state = 'a'
169 elif nextchar in self.punctuation_chars:
170 self.token = nextchar
171 self.state = 'c'
172 elif nextchar in self.quotes:
173 if not self.posix:
174 self.token = nextchar
175 self.state = nextchar
176 elif self.whitespace_split:
177 self.token = nextchar
178 self.state = 'a'
180 self.token = nextchar
181 if self.token or (self.posix and quoted):
185 elif self.state in self.quotes:
188 if self.debug >= 2:
192 if nextchar == self.state:
193 if not self.posix:
194 self.token += nextchar
195 self.state = ' '
198 self.state = 'a'
199 elif (self.posix and nextchar in self.escape and self.state
200 in self.escapedquotes):
201 escapedstate = self.state
202 self.state = nextchar
204 self.token += nextchar
205 elif self.state in self.escape:
207 if self.debug >= 2:
213 if (escapedstate in self.quotes and
214 nextchar != self.state and nextchar != escapedstate):
215 self.token += self.state
216 self.token += nextchar
217 self.state = escapedstate
218 elif self.state in ('a', 'c'):
220 self.state = None # end of file
222 elif nextchar in self.whitespace:
223 if self.debug >= 2:
225 self.state = ' '
226 if self.token or (self.posix and quoted):
230 elif nextchar in self.commenters:
231 self.instream.readline()
232 self.lineno += 1
233 if self.posix:
234 self.state = ' '
235 if self.token or (self.posix and quoted):
239 elif self.state == 'c':
240 if nextchar in self.punctuation_chars:
241 self.token += nextchar
243 if nextchar not in self.whitespace:
244 self._pushback_chars.append(nextchar)
245 self.state = ' '
247 elif self.posix and nextchar in self.quotes:
248 self.state = nextchar
249 elif self.posix and nextchar in self.escape:
251 self.state = nextchar
252 elif (nextchar in self.wordchars or nextchar in self.quotes
253 or (self.whitespace_split and
254 nextchar not in self.punctuation_chars)):
255 self.token += nextchar
257 if self.punctuation_chars:
258 self._pushback_chars.append(nextchar)
260 self.pushback.appendleft(nextchar)
261 if self.debug >= 2:
263 self.state = ' '
264 if self.token or (self.posix and quoted):
268 result = self.token
269 self.token = ''
270 if self.posix and not quoted and result == '':
272 if self.debug > 1:
279 def sourcehook(self, newfile):
284 if isinstance(self.infile, str) and not os.path.isabs(newfile):
285 newfile = os.path.join(os.path.dirname(self.infile), newfile)
288 def error_leader(self, infile=None, lineno=None):
291 infile = self.infile
293 lineno = self.lineno
296 def __iter__(self):
297 return self
299 def __next__(self):
300 token = self.get_token()
301 if token == self.eof: