def get_icon(config, default_icon, req_width, req_height, filename): if len(filename) > 0: if os.path.isfile(filename): f = open(filename, "rb") data = f.read() f.close() if is_valid_tbmp(data, default_icon): icon = data else: # Not a Tbmp, so convert it to a Tbmp with the image parser. parser = ImageParser.get_default_parser(config) # Make some image attribs for calling the image parser. # Maxheight and Maxwidth remain strings (get converted to int in the image parser), # but bpp needs to be int. bpp is always 1 on these appinfo block images. attribs = {} attribs["maxheight"] = req_height attribs["maxwidth"] = req_width attribs["bpp"] = 1 # Do parsing. The final zero parameter is to not compress the images. parsed = parser(filename, Retriever.GuessType(filename), data, config, attribs, 0) data = parsed.get_plucker_doc() data = data._data # Check it again if is_valid_tbmp(data, default_icon): icon = data else: # Something is wrong with the icon. Give up print "Something is wrong with %s, using default" % filename icon = default_icon else: print "File %s not found, using default" % filename icon = default_icon else: icon = default_icon return icon
def get_icon(config, default_icon, req_width, req_height, filename): if len(filename) > 0: if os.path.isfile(filename): f = open(filename, 'rb') data = f.read() f.close() if is_valid_tbmp(data,default_icon): icon = data else: # Not a Tbmp, so convert it to a Tbmp with the image parser. parser = ImageParser.get_default_parser(config) # Make some image attribs for calling the image parser. # Maxheight and Maxwidth remain strings (get converted to int in the image parser), # but bpp needs to be int. bpp is always 1 on these appinfo block images. attribs = {} attribs['maxheight'] = req_height attribs['maxwidth'] = req_width attribs['bpp'] = 1 # Do parsing. The final zero parameter is to not compress the images. parsed = parser(filename, Retriever.GuessType(filename), data, config, attribs, 0) data = parsed.get_plucker_doc() data = data._data # Check it again if is_valid_tbmp(data,default_icon): icon = data else: # Something is wrong with the icon. Give up print "Something is wrong with %s, using default" % filename icon = default_icon else: print "File %s not found, using default" % filename icon = default_icon else: icon = default_icon return icon
def generic_parser(url, headers, data, config, attributes): try: url = str(url) # convert to string if this is still a Url.ULR type = headers["content-type"] verbosity = config.get_int("verbosity", 1) if type == "unknown/unknown" and attributes.has_key("type"): # note that this type is not an HTTP header, and may not contain parameters type = attributes["type"] if type == "text/html": parser = TextParser.StructuredHTMLParser(url, data, headers, config, attributes) for item in parser.get_unknown(): if unknown_things.has_key(item): unknown_things[item].append(url) else: unknown_things[item] = [url] return parser.get_plucker_doc() # DRS 2004-12-29 # pretend message/rfc822 is really text elif type == "text/plain" or type == "message/rfc822": parser = TextParser.PlainTextParser(url, data, headers, config, attributes) return parser.get_plucker_doc() elif type == "mailto/text": # These are easy to handle, the document does it itself, so no # parsing needed as we generate the document directly return PluckerDocs.PluckerMailtoDocument(url) elif type[:6] == "image/": # this can fail, as some parsers do not recognize all image types... parser = ImageParser.get_default_parser(config) parsed = parser(url, type, data, config, attributes) return parsed.get_plucker_doc() elif type[:18] == "application/msword": return WordParser(url, data, headers, config, attributes) else: message(0, "%s type not yet handled (%s)" % (type, url)) return None except RuntimeError, text: error("Runtime error parsing document %s: %s" % (url, text)) return None
def generic_parser(url, headers, data, config, attributes): try: url = str(url) # convert to string if this is still a Url.ULR type = headers['content-type'] verbosity = config.get_int('verbosity', 1) if type == 'unknown/unknown' and attributes.has_key('type'): # note that this type is not an HTTP header, and may not contain parameters type = attributes['type'] if type == "text/html": parser = TextParser.StructuredHTMLParser(url, data, headers, config, attributes) for item in parser.get_unknown(): if unknown_things.has_key(item): unknown_things[item].append(url) else: unknown_things[item] = [url] return parser.get_plucker_doc() elif type == "text/plain": parser = TextParser.PlainTextParser(url, data, headers, config, attributes) return parser.get_plucker_doc() elif type == "mailto/text": # These are easy to handle, the document does it itself, so no # parsing needed as we generate the document directly return PluckerDocs.PluckerMailtoDocument(url) elif type[:6] == "image/": # this can fail, as some parsers do not recognize all image types... parser = ImageParser.get_default_parser(config) parsed = parser(url, type, data, config, attributes) return parsed.get_plucker_doc() elif type[:18] == "application/msword": return WordParser(url, data, headers, config, attributes) else: message(0, "%s type not yet handled" % type) return None except RuntimeError, text: error("Runtime error parsing document %s: %s" % (url, text)) return None