Commit fe92b22f authored by Tristan Cavelier's avatar Tristan Cavelier

wip

parent b3328e6b
......@@ -39,8 +39,8 @@ class TestHandler(HandlerTestCase):
def _testBase(self, html_path, **conversion_kw):
html_file = open(html_path).read()
handler = Handler(self.tmp_url, html_file, "html", **self.kw)
pdf_file = handler.convert("pdf", **conversion_kw)
handler = Handler(self.tmp_url, html_file, "text/html", **self.kw)
pdf_file = handler.convert("application/pdf", **conversion_kw)
mime = magic.Magic(mime=True)
pdf_mimetype = mime.from_buffer(pdf_file)
self.assertEquals("application/pdf", pdf_mimetype)
......
......@@ -33,8 +33,8 @@ class TestServer(TestCase):
def ConversionScenarioList(self):
return [
(join('data', 'test_with_png_dataurl.html'), "html", "pdf", "application/pdf"),
(join('data', 'test_with_script.html'), "html", "pdf", "application/pdf"),
(join('data', 'test_with_png_dataurl.html'), "text/html", "application/pdf", "application/pdf"),
(join('data', 'test_with_script.html'), "text/html", "application/pdf", "application/pdf"),
]
def testConvertHtmltoPdf(self):
......@@ -46,7 +46,7 @@ class TestServer(TestCase):
# Test to verify if server fail when a empty string is sent
('', '', ''),
# Try convert one html for a invalid format
(open(join('data', 'test_with_png_dataurl.html')).read(), 'html', 'xyz'),
(open(join('data', 'test_with_png_dataurl.html')).read(), 'text/html', 'application/octet-stream'),
]
def test_suite():
......
......@@ -45,25 +45,23 @@ from cloudooo.handler.ooo.mimemapper import mimemapper
class HandlerNotFound(Exception):
pass
def getHandlerClass(source_format, destination_format, mimetype_registry,
def getHandlerClass(source_mimetype, destination_mimetype, mimetype_registry,
handler_dict):
"""Select handler according to source_format and destination_format
"""Select handler according to source_mimetype and destination_mimetype
"""
if "/" in source_format:
source_mimetype = source_format
else:
source_mimetype = mimetypes.types_map.get('.%s' % source_format, "*")
if "/" in destination_format:
destination_mimetype = destination_format
else:
destination_mimetype = mimetypes.types_map.get('.%s' % destination_format, "*")
original_source_mimetype = source_mimetype
original_destination_mimetype = destination_mimetype
if "/" not in source_mimetype:
source_mimetype = mimetypes.types_map.get('.%s' % source_mimetype, "*")
if "/" not in destination_mimetype:
destination_mimetype = mimetypes.types_map.get('.%s' % destination_mimetype, "*")
for pattern in mimetype_registry:
registry_list = pattern.split()
if fnmatch(source_mimetype, registry_list[0]) and \
(fnmatch(destination_mimetype, registry_list[1]) or destination_format is None):
(fnmatch(destination_mimetype, registry_list[1]) or destination_mimetype is None):
return handler_dict[registry_list[2]]
raise HandlerNotFound('No Handler found for %r=>%r' % (source_format,
destination_format))
raise HandlerNotFound('No Handler found for %r=>%r' % (original_source_mimetype,
original_destination_mimetype))
class Manager(object):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment