def DisplayAsMime(grph, node, entity_ids_arr): fileName = entity_ids_arr[0] groupName = entity_ids_arr[1] sys.stderr.write("fileName=%s groupName=%s\n" % (fileName, groupName)) # Using LoadLibrary (rather than CreateFile) is required otherwise # LoadResource, FindResource and others will fail hlib = win32api.LoadLibraryEx(fileName, 0, 2) sys.stderr.write("fileName=%s groupName=%s\n" % (fileName, str(groupName))) try: groupName = int(groupName) except: pass # The destructor will remove the temporary file. objTempFile = IconToFile(hlib, groupName) rsrcFilNam = objTempFile.Name try: lib_util.CopyFile(mimeTypeResource, rsrcFilNam) except Exception: exc = sys.exc_info()[1] lib_common.ErrorMessageHtml( "DisplayAsMime rsrcFilNam=%s, mime_type=%s caught:%s" % (rsrcFilNam, mime_type, str(exc)))
def ServeFile(filepath): if not re.match("/Tabular\..*\.csv", filepath): return False # lib_util.CopyFile( "text/csv", filepath, sys.stdout ) lib_util.CopyFile("text/csv", filepath) return True
def DisplayAsMime(grph, node, entity_ids_arr): file_name = entity_ids_arr[0] mime_stuff = lib_mime.FilenameToMime(file_name) DEBUG("DisplayAsMime fileName=%s MIME:%s", file_name, str(mime_stuff)) mime_type = mime_stuff[0] # It could also be a binary stream. if mime_type == None: lib_common.ErrorMessageHtml("No mime type for %s" % file_name) # TODO: Find a solution for JSON files such as: # "No mime type for C:\Users\rchateau\AppData\Roaming\Mozilla\Firefox\Profiles\gciw4sok.default/dh-ldata.json" try: # TODO: Change this with WSGI. lib_util.CopyFile(mime_type, file_name) except Exception as exc: lib_common.ErrorMessageHtml( "file_to_mime.py Reading fileName=%s, caught:%s" % (file_name, str(exc)))