Commit fe92b22f authored by Tristan Cavelier's avatar Tristan Cavelier

wip

parent b3328e6b
...@@ -39,8 +39,8 @@ class TestHandler(HandlerTestCase): ...@@ -39,8 +39,8 @@ class TestHandler(HandlerTestCase):
def _testBase(self, html_path, **conversion_kw): def _testBase(self, html_path, **conversion_kw):
html_file = open(html_path).read() html_file = open(html_path).read()
handler = Handler(self.tmp_url, html_file, "html", **self.kw) handler = Handler(self.tmp_url, html_file, "text/html", **self.kw)
pdf_file = handler.convert("pdf", **conversion_kw) pdf_file = handler.convert("application/pdf", **conversion_kw)
mime = magic.Magic(mime=True) mime = magic.Magic(mime=True)
pdf_mimetype = mime.from_buffer(pdf_file) pdf_mimetype = mime.from_buffer(pdf_file)
self.assertEquals("application/pdf", pdf_mimetype) self.assertEquals("application/pdf", pdf_mimetype)
......
...@@ -33,8 +33,8 @@ class TestServer(TestCase): ...@@ -33,8 +33,8 @@ class TestServer(TestCase):
def ConversionScenarioList(self): def ConversionScenarioList(self):
return [ return [
(join('data', 'test_with_png_dataurl.html'), "html", "pdf", "application/pdf"), (join('data', 'test_with_png_dataurl.html'), "text/html", "application/pdf", "application/pdf"),
(join('data', 'test_with_script.html'), "html", "pdf", "application/pdf"), (join('data', 'test_with_script.html'), "text/html", "application/pdf", "application/pdf"),
] ]
def testConvertHtmltoPdf(self): def testConvertHtmltoPdf(self):
...@@ -46,7 +46,7 @@ class TestServer(TestCase): ...@@ -46,7 +46,7 @@ class TestServer(TestCase):
# Test to verify if server fail when a empty string is sent # Test to verify if server fail when a empty string is sent
('', '', ''), ('', '', ''),
# Try convert one html for a invalid format # 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(): def test_suite():
......
...@@ -45,25 +45,23 @@ from cloudooo.handler.ooo.mimemapper import mimemapper ...@@ -45,25 +45,23 @@ from cloudooo.handler.ooo.mimemapper import mimemapper
class HandlerNotFound(Exception): class HandlerNotFound(Exception):
pass pass
def getHandlerClass(source_format, destination_format, mimetype_registry, def getHandlerClass(source_mimetype, destination_mimetype, mimetype_registry,
handler_dict): handler_dict):
"""Select handler according to source_format and destination_format """Select handler according to source_mimetype and destination_mimetype
""" """
if "/" in source_format: original_source_mimetype = source_mimetype
source_mimetype = source_format original_destination_mimetype = destination_mimetype
else: if "/" not in source_mimetype:
source_mimetype = mimetypes.types_map.get('.%s' % source_format, "*") source_mimetype = mimetypes.types_map.get('.%s' % source_mimetype, "*")
if "/" in destination_format: if "/" not in destination_mimetype:
destination_mimetype = destination_format destination_mimetype = mimetypes.types_map.get('.%s' % destination_mimetype, "*")
else:
destination_mimetype = mimetypes.types_map.get('.%s' % destination_format, "*")
for pattern in mimetype_registry: for pattern in mimetype_registry:
registry_list = pattern.split() registry_list = pattern.split()
if fnmatch(source_mimetype, registry_list[0]) and \ 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]] return handler_dict[registry_list[2]]
raise HandlerNotFound('No Handler found for %r=>%r' % (source_format, raise HandlerNotFound('No Handler found for %r=>%r' % (original_source_mimetype,
destination_format)) original_destination_mimetype))
class Manager(object): 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