| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
pyparsing.ParseResults Class Reference
Inheritance diagram for pyparsing.ParseResults:
[legend]
Collaboration diagram for pyparsing.ParseResults:
[legend]

## Public Member Functions
def | __new__
def | __init__
def | __getitem__
def | __setitem__
def | __delitem__
def | __contains__
def | __len__
def | __bool__
def | __iter__
def | __reversed__
def | keys
def | pop
def | get
def | insert
def | items
def | values
def | __getattr__
def | __add__
def | __iadd__
def | __repr__
def | __str__
def | asList
def | asDict
def | copy
def | asXML
def | getName
def | dump
def | __getstate__
def | __setstate__
def | __dir__

## Private Member Functions
def | _asStringList
def | __lookup

## Private Attributes
| __doinit
| __name
| __parent
| __accumNames
| __toklist
| __tokdict

## Static Private Attributes
tuple | __slots__ ( "__toklist", "__tokdict", "__doinit", "__name", "__parent", "__accumNames", "__weakref__" )
| __nonzero__ __bool__

## Detailed Description

    Structured parse results, to provide multiple means of access to the parsed data:
       - as a list (len(results))
       - by list index (results[0], results[1], etc.)
       - by attribute (results.<resultsName>)

Definition at line 268 of file pyparsing.py.

## Constructor & Destructor Documentation

def pyparsing.ParseResults.__init__ | ( |  | self,
|  |  | toklist,
|  |  | name = `None`,
|  |  | asList = `True`,
|  |  | modal = `True`
| ) |  |

Definition at line 284 of file pyparsing.py.

284
285 def __init__( self, toklist, name=None, asList=True, modal=True ):
286 if self.__doinit:
287 self.__doinit = False
288 self.__name = None
289 self.__parent = None
290 self.__accumNames = {}
291 if isinstance(toklist, list):
292 self.__toklist = toklist[:]
293 else:
294 self.__toklist = [toklist]
295 self.__tokdict = dict()
296
297 if name:
298 if not modal:
299 self.__accumNames[name] = 0
300 if isinstance(name,int):
301 name = _ustr(name) # will always return a str, but use _ustr for consistency
302 self.__name = name
303 if not toklist in (None,'',[]):
304 if isinstance(toklist,basestring):
305 toklist = [ toklist ]
306 if asList:
307 if isinstance(toklist,ParseResults):
308 self[name] = _ParseResultsWithOffset(toklist.copy(),0)
309 else:
310 self[name] = _ParseResultsWithOffset(ParseResults(toklist[0]),0)
311 self[name].__name = name
312 else:
313 try:
314 self[name] = toklist[0]
315 except (KeyError,TypeError,IndexError):
316 self[name] = toklist

## Member Function Documentation

def pyparsing.ParseResults.__add__ | ( |  | self,
|  |  | other
| ) |  |

Definition at line 416 of file pyparsing.py.

416
417 def __add__( self, other ):
418 ret = self.copy()
419 ret += other
420 return ret

def pyparsing.ParseResults.__bool__ | ( |  | self | ) |

Definition at line 365 of file pyparsing.py.

365
def __bool__(self): return len( self.__toklist ) > 0

def pyparsing.ParseResults.__contains__ | ( |  | self,
|  |  | k
| ) |  |

Definition at line 361 of file pyparsing.py.

361
362 def __contains__( self, k ):
363 return k in self.__tokdict

def pyparsing.ParseResults.__delitem__ | ( |  | self,
|  |  | i
| ) |  |

Definition at line 339 of file pyparsing.py.

339
340 def __delitem__( self, i ):
341 if isinstance(i,(int,slice)):
342 mylen = len( self.__toklist )
343 del self.__toklist[i]
344
345 # convert int to slice
346 if isinstance(i, int):
347 if i < 0:
348 i += mylen
349 i = slice(i, i+1)
350 # get removed indices
351 removed = list(range(*i.indices(mylen)))
352 removed.reverse()
353 # fixup indices in token dictionary
354 for name in self.__tokdict:
355 occurrences = self.__tokdict[name]
356 for j in removed:
357 for k, (value, position) in enumerate(occurrences):
358 occurrences[k] = _ParseResultsWithOffset(value, position - (position > j))
359 else:
360 del self.__tokdict[i]

def pyparsing.ParseResults.__dir__ | ( |  | self | ) |

Definition at line 616 of file pyparsing.py.

616
617 def __dir__(self):
618 return dir(super(ParseResults,self)) + self.keys()

def pyparsing.ParseResults.__getattr__ | ( |  | self,
|  |  | name
| ) |  |

Definition at line 405 of file pyparsing.py.

405
406 def __getattr__( self, name ):
407 if name not in self.__slots__:
408 if name in self.__tokdict:
409 if name not in self.__accumNames:
410 return self.__tokdict[name][-1][0]
411 else:
412 return ParseResults([ v[0] for v in self.__tokdict[name] ])
413 else:
414 return ""
415 return None

def pyparsing.ParseResults.__getitem__ | ( |  | self,
|  |  | i
| ) |  |

Definition at line 317 of file pyparsing.py.

317
318 def __getitem__( self, i ):
319 if isinstance( i, (int,slice) ):
320 return self.__toklist[i]
321 else:
322 if i not in self.__accumNames:
323 return self.__tokdict[i][-1][0]
324 else:
325 return ParseResults([ v[0] for v in self.__tokdict[i] ])

def pyparsing.ParseResults.__getstate__ | ( |  | self | ) |

Definition at line 596 of file pyparsing.py.

596
597 def __getstate__(self):
598 return ( self.__toklist,
599 ( self.__tokdict.copy(),
600 self.__parent is not None and self.__parent() or None,
601 self.__accumNames,
602 self.__name ) )

def pyparsing.ParseResults.__iadd__ | ( |  | self,
|  |  | other
| ) |  |

Definition at line 421 of file pyparsing.py.

421
422 def __iadd__( self, other ):
423 if other.__tokdict:
424 offset = len(self.__toklist)
425 addoffset = ( lambda a: (a<0 and offset) or (a+offset) )
426 otheritems = other.__tokdict.items()
427 otherdictitems = [(k, _ParseResultsWithOffset(v[0],addoffset(v[1])) )
428 for (k,vlist) in otheritems for v in vlist]
429 for k,v in otherdictitems:
430 self[k] = v
431 if isinstance(v[0],ParseResults):
432 v[0].__parent = wkref(self)
433
434 self.__toklist += other.__toklist
435 self.__accumNames.update( other.__accumNames )
436 del other
437 return self

def pyparsing.ParseResults.__iter__ | ( |  | self | ) |

Definition at line 367 of file pyparsing.py.

367
def __iter__( self ): return iter( self.__toklist )

def pyparsing.ParseResults.__len__ | ( |  | self | ) |

Definition at line 364 of file pyparsing.py.

364
def __len__( self ): return len( self.__toklist )

def pyparsing.ParseResults.__lookup | ( |  | self,
|  |  | sub
| ) |  |
| private

Definition at line 547 of file pyparsing.py.

547
548 def __lookup(self,sub):
549 for k,vlist in self.__tokdict.items():
550 for v,loc in vlist:
551 if sub is v:
552 return k
553 return None

def pyparsing.ParseResults.__new__ | ( |  | cls,
|  |  | toklist,
|  |  | name = `None`,
|  |  | asList = `True`,
|  |  | modal = `True`
| ) |  |

Definition at line 275 of file pyparsing.py.

275
276 def __new__(cls, toklist, name=None, asList=True, modal=True ):
277 if isinstance(toklist, cls):
278 return toklist
279 retobj = object.__new__(cls)
280 retobj.__doinit = True
281 return retobj

def pyparsing.ParseResults.__repr__ | ( |  | self | ) |

Definition at line 438 of file pyparsing.py.

438
439 def __repr__( self ):
440 return "(%s, %s)" % ( repr( self.__toklist ), repr( self.__tokdict ) )

def pyparsing.ParseResults.__reversed__ | ( |  | self | ) |

Definition at line 368 of file pyparsing.py.

368
def __reversed__( self ): return iter( reversed(self.__toklist) )

def pyparsing.ParseResults.__setitem__ | ( |  | self,
|  |  | k,
|  |  | v
| ) |  |

Definition at line 326 of file pyparsing.py.

326
327 def __setitem__( self, k, v ):
328 if isinstance(v,_ParseResultsWithOffset):
329 self.__tokdict[k] = self.__tokdict.get(k,list()) + [v]
330 sub = v[0]
331 elif isinstance(k,int):
332 self.__toklist[k] = v
333 sub = v
334 else:
335 self.__tokdict[k] = self.__tokdict.get(k,list()) + [_ParseResultsWithOffset(v,0)]
336 sub = v
337 if isinstance(sub,ParseResults):
338 sub.__parent = wkref(self)

def pyparsing.ParseResults.__setstate__ | ( |  | self,
|  |  | state
| ) |  |

Definition at line 603 of file pyparsing.py.

603
604 def __setstate__(self,state):
605 self.__toklist = state[0]
606 self.__tokdict, \
607 par, \
608 inAccumNames, \
609 self.__name = state[1]
610 self.__accumNames = {}
611 self.__accumNames.update(inAccumNames)
612 if par is not None:
613 self.__parent = wkref(par)
614 else:
615 self.__parent = None

def pyparsing.ParseResults.__str__ | ( |  | self | ) |

Definition at line 441 of file pyparsing.py.

441
442 def __str__( self ):
443 out = "["
444 sep = ""
445 for i in self.__toklist:
446 if isinstance(i, ParseResults):
447 out += sep + _ustr(i)
448 else:
449 out += sep + repr(i)
450 sep = ", "
451 out += "]"
452 return out

def pyparsing.ParseResults._asStringList | ( |  | self,
|  |  | sep = `''`
| ) |  |
| private

Definition at line 453 of file pyparsing.py.

453
454 def _asStringList( self, sep='' ):
455 out = []
456 for item in self.__toklist:
457 if out and sep:
458 out.append(sep)
459 if isinstance( item, ParseResults ):
460 out += item._asStringList()
461 else:
462 out.append( _ustr(item) )
463 return out

def pyparsing.ParseResults.asDict | ( |  | self | ) |

    Returns the named parse results as dictionary.

Definition at line 474 of file pyparsing.py.

474
475 def asDict( self ):
476 """Returns the named parse results as dictionary."""
477 return dict( self.items() )

def pyparsing.ParseResults.asList | ( |  | self | ) |

    Returns the parse results as a nested list of matching tokens, all converted to strings.

Definition at line 464 of file pyparsing.py.

464
465 def asList( self ):
466 """Returns the parse results as a nested list of matching tokens, all converted to strings."""
467 out = []
468 for res in self.__toklist:
469 if isinstance(res,ParseResults):
470 out.append( res.asList() )
471 else:
472 out.append( res )
473 return out

def pyparsing.ParseResults.asXML | ( |  | self,
|  |  | doctag = `None`,
|  |  | namedItemsOnly = `False`,
|  |  | indent = `""`,
|  |  | formatted = `True`
| ) |  |

    Returns the parse results as XML. Tags are created for tokens and lists that have defined results names.

Definition at line 487 of file pyparsing.py.

487
488 def asXML( self, doctag=None, namedItemsOnly=False, indent="", formatted=True ):
489 """Returns the parse results as XML. Tags are created for tokens and lists that have defined results names."""
490 nl = "\n"
491 out = []
492 namedItems = dict( [ (v[1],k) for (k,vlist) in self.__tokdict.items()
493 for v in vlist ] )
494 nextLevelIndent = indent + " "
495
496 # collapse out indents if formatting is not desired
497 if not formatted:
498 indent = ""
499 nextLevelIndent = ""
500 nl = ""
501
502 selfTag = None
503 if doctag is not None:
504 selfTag = doctag
505 else:
506 if self.__name:
507 selfTag = self.__name
508
509 if not selfTag:
510 if namedItemsOnly:
511 return ""
512 else:
513 selfTag = "ITEM"
514
515 out += [ nl, indent, "<", selfTag, ">" ]
516
517 worklist = self.__toklist
518 for i,res in enumerate(worklist):
519 if isinstance(res,ParseResults):
520 if i in namedItems:
521 out += [ res.asXML(namedItems[i],
522 namedItemsOnly and doctag is None,
523 nextLevelIndent,
524 formatted)]
525 else:
526 out += [ res.asXML(None,
527 namedItemsOnly and doctag is None,
528 nextLevelIndent,
529 formatted)]
530 else:
531 # individual token, see if there is a name for it
532 resTag = None
533 if i in namedItems:
534 resTag = namedItems[i]
535 if not resTag:
536 if namedItemsOnly:
537 continue
538 else:
539 resTag = "ITEM"
540 xmlBodyText = _xml_escape(_ustr(res))
541 out += [ nl, nextLevelIndent, "<", resTag, ">",
542 xmlBodyText,
543 "</", resTag, ">" ]
544
545 out += [ nl, indent, "</", selfTag, ">" ]
546 return "".join(out)

def pyparsing.ParseResults.copy | ( |  | self | ) |

    Returns a new copy of a ParseResults object.

Definition at line 478 of file pyparsing.py.

478
479 def copy( self ):
480 """Returns a new copy of a ParseResults object."""
481 ret = ParseResults( self.__toklist )
482 ret.__tokdict = self.__tokdict.copy()
483 ret.__parent = self.__parent
484 ret.__accumNames.update( self.__accumNames )
485 ret.__name = self.__name
486 return ret

def pyparsing.ParseResults.dump | ( |  | self,
|  |  | indent = `''`,
|  |  | depth = `0`
| ) |  |

    Diagnostic method for listing out the contents of a ParseResults.
       Accepts an optional indent argument so that this string can be embedded
       in a nested display of other data.

Definition at line 571 of file pyparsing.py.

571
572 def dump(self,indent='',depth=0):
573 """Diagnostic method for listing out the contents of a ParseResults.
574 Accepts an optional indent argument so that this string can be embedded
575 in a nested display of other data."""
576 out = []
577 out.append( indent+_ustr(self.asList()) )
578 keys = self.items()
579 keys.sort()
580 for k,v in keys:
581 if out:
582 out.append('\n')
583 out.append( "%s%s- %s: " % (indent,(' '*depth), k) )
584 if isinstance(v,ParseResults):
585 if v.keys():
586 #~ out.append('\n')
587 out.append( v.dump(indent,depth+1) )
588 #~ out.append('\n')
589 else:
590 out.append(_ustr(v))
591 else:
592 out.append(_ustr(v))
593 #~ out.append('\n')
594 return "".join(out)

def pyparsing.ParseResults.get | ( |  | self,
|  |  | key,
|  |  | defaultValue = `None`
| ) |  |

    Returns named result matching the given key, or if there is no
       such name, then returns the given defaultValue or None if no
       defaultValue is specified.

Definition at line 380 of file pyparsing.py.

380
381 def get(self, key, defaultValue=None):
382 """Returns named result matching the given key, or if there is no
383 such name, then returns the given defaultValue or None if no
384 defaultValue is specified."""
385 if key in self:
386 return self[key]
387 else:
388 return defaultValue

def pyparsing.ParseResults.getName | ( |  | self | ) |

    Returns the results name for this token expression.

Definition at line 554 of file pyparsing.py.

554
555 def getName(self):
556 """Returns the results name for this token expression."""
557 if self.__name:
558 return self.__name
559 elif self.__parent:
560 par = self.__parent()
561 if par:
562 return par.__lookup(self)
563 else:
564 return None
565 elif (len(self) == 1 and
566 len(self.__tokdict) == 1 and
567 self.__tokdict.values()[0][0][1] in (0,-1)):
568 return self.__tokdict.keys()[0]
569 else:
570 return None

def pyparsing.ParseResults.insert | ( |  | self,
|  |  | index,
|  |  | insStr
| ) |  |

Definition at line 389 of file pyparsing.py.

389
390 def insert( self, index, insStr ):
391 self.__toklist.insert(index, insStr)
392 # fixup indices in token dictionary
393 for name in self.__tokdict:
394 occurrences = self.__tokdict[name]
395 for k, (value, position) in enumerate(occurrences):
396 occurrences[k] = _ParseResultsWithOffset(value, position + (position > index))

def pyparsing.ParseResults.items | ( |  | self | ) |

    Returns all named result keys and values as a list of tuples.

Definition at line 397 of file pyparsing.py.

397
398 def items( self ):
399 """Returns all named result keys and values as a list of tuples."""
400 return [(k,self[k]) for k in self.__tokdict]

def pyparsing.ParseResults.keys | ( |  | self | ) |

    Returns all named result keys.

Definition at line 369 of file pyparsing.py.

369
370 def keys( self ):
371 """Returns all named result keys."""
372 return self.__tokdict.keys()

def pyparsing.ParseResults.pop | ( |  | self,
|  |  | index = `-1`
| ) |  |

    Removes and returns item at specified index (default=last).
       Will work with either numeric indices or dict-key indicies.

Definition at line 373 of file pyparsing.py.

373
374 def pop( self, index=-1 ):
375 """Removes and returns item at specified index (default=last).
376 Will work with either numeric indices or dict-key indicies."""
377 ret = self[index]
378 del self[index]
379 return ret

def pyparsing.ParseResults.values | ( |  | self | ) |

    Returns all named result values.

Definition at line 401 of file pyparsing.py.

401
402 def values( self ):
403 """Returns all named result values."""
404 return [ v[-1][0] for v in self.__tokdict.values() ]

## Member Data Documentation

pyparsing.ParseResults.__accumNames
| private

Definition at line 289 of file pyparsing.py.

pyparsing.ParseResults.__doinit
| private

Definition at line 286 of file pyparsing.py.

pyparsing.ParseResults.__name
| private

Definition at line 287 of file pyparsing.py.

pyparsing.ParseResults.__nonzero__ __bool__
| static private

Definition at line 366 of file pyparsing.py.

pyparsing.ParseResults.__parent
| private

Definition at line 288 of file pyparsing.py.

tuple pyparsing.ParseResults.__slots__ ( "__toklist", "__tokdict", "__doinit", "__name", "__parent", "__accumNames", "__weakref__" )
| static private

Definition at line 274 of file pyparsing.py.

pyparsing.ParseResults.__tokdict
| private

Definition at line 294 of file pyparsing.py.

pyparsing.ParseResults.__toklist
| private

Definition at line 291 of file pyparsing.py.

The documentation for this class was generated from the following file:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/cmake/cmt2cmake/pyparsing.py