Exemplo n.º 1
0
def getFieldAttribute(fieldset, key, attrname):
    try:
        field = fieldset[key]
        if field.hasValue():
            return getattr(field, attrname)
    except Exception as err:
        warning("Unable to get %s of field %s/%s: %s" %
                (attrname, fieldset.path, key, err))
    return None
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def doparse(self, stream, fallback=True):
     fb = None
     warn = warning
     for parser in self.parsers:
         try:
             parser_obj = parser(stream, validate=self.validate)
             if self.parser_args:
                 for key, value in self.parser_args.iteritems():
                     setattr(parser_obj, key, value)
             return parser_obj
         except ValidateError as err:
             if fallback and self.fallback:
                 fb = parser
             if parser == self.other:
                 warn = info
             warn("Skip parser '%s': %s" % (parser.__name__, err))
         except Exception as err:
             if parser == self.other:
                 warn = info
             warn("Skip parser '%s': %s" % (parser.__name__, err))
         fallback = False
     if self.use_fallback and fb:
         warning(_("Force use of parser '%s'") % fb.__name__)
         return fb(stream)
Exemplo n.º 4
0
 def safe_func(*args, **kw):
     try:
         func(*args, **kw)
     except Exception as err:
         warning("Error when calling function %s(): %s" %
                 (func.__name__, err))