Example #1
0
 def __init__(self, tags):
     self.validate = True
     self.use_fallback = False
     self.parser_args = None
     self.db = HachoirParserList.getInstance()
     self.parsers = set(self.db)
     parsers = []
     for tag in tags:
         if not self.parsers:
             break
         parsers += self._getByTag(tag)
         if self.fallback is None:
             self.fallback = len(parsers) == 1
     if self.parsers:
         other = len(parsers)
         parsers += list(self.parsers)
         self.other = parsers[other]
     self.parsers = parsers
Example #2
0
 def test_random_stream(self, tests=(1, 8)):
     a = array('L')
     parser_list = HachoirParserList()
     n = max(tests) * max(parser.getParserTags()["min_size"]
                          for parser in parser_list)
     k = 8 * a.itemsize
     for i in range((n - 1) // k + 1):
         a.append(random.getrandbits(k))
     a = StringInputStream(a.tobytes(), source="<random data>")
     for parser in parser_list:
         size = parser.getParserTags()["min_size"]
         for test in tests:
             a._size = a._current_size = size * test
             try:
                 parser(a, validate=True)
                 error("[%s] Parser didn't reject random data" %
                       parser.__name__)
             except ValidateError:
                 continue
Example #3
0
def displayParserList(*args):
    HachoirParserList().print_()
    sys.exit(0)