Lines Matching refs:self

44     def __init__(self, type, name_or_data, attrs = None, line = None, column = None):
46 self.type = type
47 self.name_or_data = name_or_data
48 self.attrs = attrs
49 self.line = line
50 self.column = column
52 def __str__(self):
53 if self.type == ELEMENT_START:
54 return '<' + self.name_or_data + ' ...>'
55 if self.type == ELEMENT_END:
56 return '</' + self.name_or_data + '>'
57 if self.type == CHARACTER_DATA:
58 return self.name_or_data
59 if self.type == EOF:
67 def __init__(self, fp, skip_ws = True):
68 self.fp = fp
69 self.tokens = []
70 self.index = 0
71 self.final = False
72 self.skip_ws = skip_ws
74 self.character_pos = 0, 0
75 self.character_data = ''
77 self.parser = xpat.ParserCreate()
78 self.parser.StartElementHandler = self.handle_element_start
79 self.parser.EndElementHandler = self.handle_element_end
80 self.parser.CharacterDataHandler = self.handle_character_data
82 def handle_element_start(self, name, attributes):
83 self.finish_character_data()
84 line, column = self.pos()
86 self.tokens.append(token)
88 def handle_element_end(self, name):
89 self.finish_character_data()
90 line, column = self.pos()
92 self.tokens.append(token)
94 def handle_character_data(self, data):
95 if not self.character_data:
96 self.character_pos = self.pos()
97 self.character_data += data
99 def finish_character_data(self):
100 if self.character_data:
101 if not self.skip_ws or not self.character_data.isspace():
102 line, column = self.character_pos
103 token = XmlToken(CHARACTER_DATA, self.character_data, None, line, column)
104 self.tokens.append(token)
105 self.character_data = ''
107 def next(self):
109 while self.index >= len(self.tokens) and not self.final:
110 self.tokens = []
111 self.index = 0
112 data = self.fp.read(size)
113 self.final = len(data) < size
116 self.parser.Parse(data, self.final)
123 if self.index >= len(self.tokens):
124 line, column = self.pos()
127 token = self.tokens[self.index]
128 self.index += 1
131 def pos(self):
132 return self.parser.CurrentLineNumber, self.parser.CurrentColumnNumber
137 def __init__(self, expected, found):
138 self.expected = expected
139 self.found = found
141 def __str__(self):
142 return '%u:%u: %s expected, %s found' % (self.found.line, self.found.column, str(self.expected), str(self.found))
149 def __init__(self, fp):
150 self.tokenizer = XmlTokenizer(fp)
151 self.consume()
153 def consume(self):
154 self.token = self.tokenizer.next()
156 def match_element_start(self, name):
157 return self.token.type == ELEMENT_START and self.token.name_or_data == name
159 def match_element_end(self, name):
160 return self.token.type == ELEMENT_END and self.token.name_or_data == name
162 def element_start(self, name):
163 while self.token.type == CHARACTER_DATA:
164 self.consume()
165 if self.token.type != ELEMENT_START:
166 raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token)
167 if self.token.name_or_data != name:
168 raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token)
169 attrs = self.token.attrs
170 self.consume()
173 def element_end(self, name):
174 while self.token.type == CHARACTER_DATA:
175 self.consume()
176 if self.token.type != ELEMENT_END:
177 raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token)
178 if self.token.name_or_data != name:
179 raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token)
180 self.consume()
182 def character_data(self, strip = True):
184 while self.token.type == CHARACTER_DATA:
185 data += self.token.name_or_data
186 self.consume()
194 def __init__(self, fp):
195 XmlParser.__init__(self, fp)
196 self.last_call_no = 0
198 def parse(self):
199 self.element_start('trace')
200 while self.token.type not in (ELEMENT_END, EOF):
201 call = self.parse_call()
202 self.handle_call(call)
203 if self.token.type != EOF:
204 self.element_end('trace')
206 def parse_call(self):
207 attrs = self.element_start('call')
211 self.last_call_no += 1
212 no = self.last_call_no
214 self.last_call_no = no
220 while self.token.type == ELEMENT_START:
221 if self.token.name_or_data == 'arg':
222 arg = self.parse_arg()
224 elif self.token.name_or_data == 'ret':
225 ret = self.parse_ret()
226 elif self.token.name_or_data == 'call':
228 self.parse_call()
229 elif self.token.name_or_data == 'time':
230 time = self.parse_time()
232 raise TokenMismatch("<arg ...> or <ret ...>", self.token)
233 self.element_end('call')
237 def parse_arg(self):
238 attrs = self.element_start('arg')
240 value = self.parse_value(name)
241 self.element_end('arg')
245 def parse_ret(self):
246 attrs = self.element_start('ret')
247 value = self.parse_value('ret')
248 self.element_end('ret')
252 def parse_time(self):
253 attrs = self.element_start('time')
254 time = self.parse_value('time');
255 self.element_end('time')
258 def parse_value(self, name):
260 if self.token.type == ELEMENT_START:
261 if self.token.name_or_data in expected_tokens:
262 method = getattr(self, 'parse_' + self.token.name_or_data)
264 raise TokenMismatch(" or " .join(expected_tokens), self.token)
266 def parse_null(self, pname):
267 self.element_start('null')
268 self.element_end('null')
271 def parse_bool(self, pname):
272 self.element_start('bool')
273 value = int(self.character_data())
274 self.element_end('bool')
277 def parse_int(self, pname):
278 self.element_start('int')
279 value = int(self.character_data())
280 self.element_end('int')
283 def parse_uint(self, pname):
284 self.element_start('uint')
285 value = int(self.character_data())
286 self.element_end('uint')
289 def parse_float(self, pname):
290 self.element_start('float')
291 value = float(self.character_data())
292 self.element_end('float')
295 def parse_enum(self, pname):
296 self.element_start('enum')
297 name = self.character_data()
298 self.element_end('enum')
301 def parse_string(self, pname):
302 self.element_start('string')
303 value = self.character_data()
304 self.element_end('string')
307 def parse_bytes(self, pname):
308 self.element_start('bytes')
309 value = self.character_data()
310 self.element_end('bytes')
313 def parse_array(self, pname):
314 self.element_start('array')
316 while self.token.type != ELEMENT_END:
317 elems.append(self.parse_elem('array'))
318 self.element_end('array')
321 def parse_elem(self, pname):
322 self.element_start('elem')
323 value = self.parse_value('elem')
324 self.element_end('elem')
327 def parse_struct(self, pname):
328 attrs = self.element_start('struct')
331 while self.token.type != ELEMENT_END:
332 members.append(self.parse_member(name))
333 self.element_end('struct')
336 def parse_member(self, pname):
337 attrs = self.element_start('member')
339 value = self.parse_value(name)
340 self.element_end('member')
344 def parse_ptr(self, pname):
345 self.element_start('ptr')
346 address = self.character_data()
347 self.element_end('ptr')
351 def handle_call(self, call):
357 def __init__(self, fp, options, formatter):
358 TraceParser.__init__(self, fp)
359 self.options = options
360 self.formatter = formatter
361 self.pretty_printer = PrettyPrinter(self.formatter, options)
363 def handle_call(self, call):
364 call.visit(self.pretty_printer)
365 self.formatter.newline()
370 def __init__(self, fp, options, formatter):
371 SimpleTraceDumper.__init__(self, fp, options, formatter)
372 self.call_stack = []
374 def handle_call(self, call):
375 if self.options.named_ptrs:
376 self.call_stack.append(call)
378 call.visit(self.pretty_printer)
379 self.formatter.newline()
381 def dump_calls(self):
382 for call in self.call_stack:
383 call.visit(self.pretty_printer)
384 self.formatter.newline()
390 def __init__(self):
393 def main(self):
394 optparser = self.get_optparser()
411 self.process_arg(stream, args)
413 def get_optparser(self):
433 def process_arg(self, stream, options):