Exemple #1
0
 def useRoot(self, root):
     stream = root.getSubIStream()
     ministream = guessParser(stream)
     if not ministream:
         warning("Unable to create the OLE2 mini stream parser!")
         return
     self._extract(ministream, main_document=False)
Exemple #2
0
def getFieldAttribute(fieldset, key, attrname):
    try:
        field = fieldset[key]
        if field.hasValue():
            return getattr(field, attrname)
    except HACHOIR_ERRORS, err:
        warning("Unable to get %s of field %s/%s: %s" % (
            attrname, fieldset.path, key, err))
Exemple #3
0
def getFieldAttribute(fieldset, key, attrname):
    try:
        field = fieldset[key]
        if field.hasValue():
            return getattr(field, attrname)
    except HACHOIR_ERRORS, err:
        warning("Unable to get %s of field %s/%s: %s" %
                (attrname, fieldset.path, key, err))
Exemple #4
0
 def getField(self, fieldset, main_document, name):
     if name not in fieldset:
         return None
     # _feedAll() is needed to make sure that we get all fragments
     # eg. summary[0], summary[1], ..., summary[n]
     fieldset._feedAll()
     field = fieldset[name]
     if main_document:
         stream = field.getSubIStream()
         field = guessParser(stream)
         if not field:
             warning("Unable to create the OLE2 parser for %s!" % name)
             return None
     return field
Exemple #5
0
 def useProperties(self, properties):
     last = properties["total_str_length"]
     offset0 = last.address + last.size
     for index in properties.array("property"):
         # Search name and value
         value = properties.getFieldByAddress(offset0+index["value_offset"].value*8)
         if not value:
             continue
         value = value.value
         if not value:
             continue
         name = properties.getFieldByAddress(offset0+index["name_offset"].value*8)
         if not name:
             continue
         name = name.value
         if name not in self.PROP_TO_KEY:
             warning("Skip %s=%r" % (name, value))
             continue
         key = self.PROP_TO_KEY[name]
         setattr(self, key, value)
Exemple #6
0
                    for key, value in self.parser_args.iteritems():
                        setattr(parser_obj, key, value)
                return parser_obj
            except ValidateError, err:
                res = unicode(err)
                if fallback and self.fallback:
                    fb = parser
            except HACHOIR_ERRORS, err:
                res = unicode(err)
            if warn:
                if parser == self.other:
                    warn = info
                warn(_("Skip parser '%s': %s") % (parser.__name__, res))
            fallback = False
        if self.use_fallback and fb:
            warning(_("Force use of parser '%s'") % fb.__name__)
            return fb(stream)


def guessParser(stream):
    return QueryParser(stream.tags).parse(stream)


def createParser(filename, real_filename=None, tags=None):
    """
    Create a parser from a file or returns None on error.

    Options:
    - filename (unicode): Input file name ;
    - real_filename (str|unicode): Real file name.
    """
Exemple #7
0
                    for key, value in self.parser_args.iteritems():
                        setattr(parser_obj, key, value)
                return parser_obj
            except ValidateError, err:
                res = unicode(err)
                if fallback and self.fallback:
                    fb = parser
            except HACHOIR_ERRORS, err:
                res = unicode(err)
            if warn:
                if parser == self.other:
                    warn = info
                warn(_("Skip parser '%s': %s") % (parser.__name__, res))
            fallback = False
        if self.use_fallback and fb:
            warning(_("Force use of parser '%s'") % fb.__name__)
            return fb(stream)


def guessParser(stream):
    return QueryParser(stream.tags).parse(stream)


def createParser(filename, real_filename=None, tags=None):
    """
    Create a parser from a file or returns None on error.

    Options:
    - filename (unicode): Input file name ;
    - real_filename (str|unicode): Real file name.
    """
Exemple #8
0
 def safe_func(*args, **kw):
     try:
         func(*args, **kw)
     except HACHOIR_ERRORS, err:
         warning("Error when calling function %s(): %s" % (
             func.__name__, err))
Exemple #9
0
 def safe_func(*args, **kw):
     try:
         func(*args, **kw)
     except HACHOIR_ERRORS, err:
         warning("Error when calling function %s(): %s" %
                 (func.__name__, err))