def parseH248(msgstr): msg = Message.parseString(msgstr) return H248Message(msg)
def main(): trans = Message.searchString(logs) msg = H248Message(trans) print msg.msg print msg.xpath("//Media/Stream/Local")
import cPickle #The compile time of the parser took about 12 seconds, but for parsing more messages, there will be no such overhead. #So we pickle the parser into a static pickle file up front, thus every invocation to the parser programm will be much #faster. PARSER="h248parser.bin.pickle" tool_path = sys.argv[0] tool_base = os.path.dirname(tool_path) parser_pickle = os.path.join(tool_base, PARSER) if not os.path.exists(parser_pickle): from h248grammer import Message Message.streamline() parser_pickle = os.path.join("/tmp", PARSER) #print "pickling the parser to boost performance" cPickle.dump(Message, open(parser_pickle, "w"), -1) os.system("chmod 777 %s" % parser_pickle) Message = cPickle.load(open(parser_pickle)) def toDict(tokens): m = {} for pair in tokens: print "%(name)s, %(value)s" % pair m[pair.name] = pair.value return m class H248Parser: