Moved the file_types to module level so they get processed once

This commit is contained in:
Felipe Polo-Wood 2013-11-10 19:13:03 -05:00
parent 20a1a2ad70
commit 45bcbe9272

View File

@ -128,6 +128,15 @@ from openlp.core.common import AppLocation, Settings, translate
from openlp.core.lib import Registry, PluginStatus, StringContent, image_to_byte from openlp.core.lib import Registry, PluginStatus, StringContent, image_to_byte
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
file_types = {
'.html': 'text/html',
'.css': 'text/css',
'.js': 'application/javascript',
'.jpg': 'image/jpeg',
'.gif': 'image/gif',
'.ico': 'image/x-icon',
'.png': 'image/png'
}
class HttpRouter(object): class HttpRouter(object):
@ -372,18 +381,10 @@ class HttpRouter(object):
def get_content_type(self, file_name): def get_content_type(self, file_name):
""" """
Examines the extension of the file and determines Examines the extension of the file and determines
what header to send back what the content_type should be, defaults to text/plain
Returns the extension found Returns the extension and the content_type
""" """
content_type = 'text/plain' content_type = 'text/plain'
file_types = {'.html': 'text/html',
'.css': 'text/css',
'.js': 'application/javascript',
'.jpg': 'image/jpeg',
'.gif': 'image/gif',
'.ico': 'image/x-icon',
'.png': 'image/png'
}
ext = os.path.splitext(file_name)[1] ext = os.path.splitext(file_name)[1]
content_type = file_types.get(ext, 'text/plain') content_type = file_types.get(ext, 'text/plain')
return ext, content_type return ext, content_type