Пример #1
0
 def __call__(self, prev):
     name = self.path + "[]"
     address, size, last = self.cluster.next()
     if self.filesize:
         if self.done >= self.filesize:
             error("(FAT) bad metadata for " + self.path)
             return
         field = File(self.root, name, size=size)
         if prev.first is None:
             field._description = 'File size: %s' % humanFilesize(
                 self.filesize // 8)
             field.setSubIStream(self.createInputStream)
         field.datasize = min(self.filesize - self.done, size)
         self.done += field.datasize
     else:
         field = Directory(self.root, name, size=size)
     padding = self.root.getFieldByAddress(address, feed=False)
     if not isinstance(padding, (PaddingBytes, RawBytes)):
         error("(FAT) address %u doesn't point to a padding field" %
               address)
         return
     if last:
         next = None
     else:
         next = lambda: self(field)
     field.setLinks(prev.first, next)
     self.root.writeFieldsIn(padding, address, (field, ))
     return field
Пример #2
0
 def __call__(self, prev):
     name = self.path + "[]"
     address, size, last = self.cluster.next()
     if self.filesize:
         if self.done >= self.filesize:
             error("(FAT) bad metadata for " + self.path)
             return
         field = File(self.root, name, size=size)
         if prev.first is None:
             field._description = 'File size: %s' % humanFilesize(self.filesize//8)
             field.setSubIStream(self.createInputStream)
         field.datasize = min(self.filesize - self.done, size)
         self.done += field.datasize
     else:
         field = Directory(self.root, name, size=size)
     padding = self.root.getFieldByAddress(address, feed=False)
     if not isinstance(padding, (PaddingBytes, RawBytes)):
         error("(FAT) address %u doesn't point to a padding field" % address)
         return
     if last:
         next = None
     else:
         next = lambda: self(field)
     field.setLinks(prev.first, next)
     self.root.writeFieldsIn(padding, address, (field,))
     return field
Пример #3
0
 def _getContentSize(self):
     if not hasattr(self, "_content_size"):
         try:
             self._content_size = self.createContentSize()
         except HACHOIR_ERRORS, err:
             error("Unable to compute %s content size: %s" % (self.__class__.__name__, err))
             self._content_size = None
Пример #4
0
 def _getContentSize(self):
     if not hasattr(self, "_content_size"):
         try:
             self._content_size = self.createContentSize()
         except HACHOIR_ERRORS, err:
             error("Unable to compute %s content size: %s" %
                   (self.__class__.__name__, err))
             self._content_size = None
Пример #5
0
 def _getDescription(self):
     if self._description is None:
         try:
             self._description = self.createDescription()
             if isinstance(self._description, str):
                 self._description = makeUnicode(self._description)
         except HACHOIR_ERRORS, err:
             error("Error getting description of %s: %s" \
                 % (self.path, unicode(err)))
             self._description = self.PARSER_TAGS["description"]
Пример #6
0
 def _getDescription(self):
     if self._description is None:
         try:
             self._description = self.createDescription()
             if isinstance(self._description, str):
                 self._description = makeUnicode(self._description)
         except HACHOIR_ERRORS, err:
             error("Error getting description of %s: %s" \
                 % (self.path, unicode(err)))
             self._description = self.PARSER_TAGS["description"]
def extractMetadata(parser, quality=QUALITY_NORMAL):
    """
    Create a Metadata class from a parser. Returns None if no metadata
    extractor does exist for the parser class.
    """
    try:
        extractor = extractors[parser.__class__]
    except KeyError:
        return None
    metadata = extractor(quality)
    try:
        metadata.extract(parser)
    except HACHOIR_ERRORS, err:
        error("Error during metadata extraction: %s" % unicode(err))
Пример #8
0
def extractMetadata(parser, quality=QUALITY_NORMAL):
    """
    Create a Metadata class from a parser. Returns None if no metadata
    extractor does exist for the parser class.
    """
    try:
        extractor = extractors[parser.__class__]
    except KeyError:
        return None
    metadata = extractor(quality)
    try:
        metadata.extract(parser)
    except HACHOIR_ERRORS, err:
        error("Error during metadata extraction: %s" % unicode(err))
Пример #9
0
    def add(self, parser):
        tags = parser.getParserTags()
        err = self.validParser(parser, tags)
        if err:
            error("Skip parser %s: %s" % (parser.__name__, err))
            return

        _tags = []
        for tag in tags.iteritems():
            tag = self.translate(*tag)
            if isinstance(tag, tuple):
                _tags.append(tag)
            elif tag is not True:
                error("[%s] %s" % (parser.__name__, tag))
                return

        self.parser_list.append(parser)

        for name, values in _tags:
            byname = self.bytag.setdefault(name, {})
            for value in values:
                byname.setdefault(value, []).append(parser)
Пример #10
0
    def add(self, parser):
        tags = parser.getParserTags()
        err = self.validParser(parser, tags)
        if err:
            error("Skip parser %s: %s" % (parser.__name__, err))
            return

        _tags = []
        for tag in tags.iteritems():
            tag = self.translate(*tag)
            if isinstance(tag, tuple):
                _tags.append(tag)
            elif tag is not True:
                error("[%s] %s" % (parser.__name__, tag))
                return

        self.parser_list.append(parser)

        for name, values in _tags:
            byname = self.bytag.setdefault(name,{})
            for value in values:
                byname.setdefault(value,[]).append(parser)