Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cloudooo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tristan Cavelier
cloudooo
Commits
fe92b22f
Commit
fe92b22f
authored
Oct 19, 2016
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
b3328e6b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
18 deletions
+16
-18
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfHandler.py
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfHandler.py
+2
-2
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfServer.py
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfServer.py
+3
-3
cloudooo/manager.py
cloudooo/manager.py
+11
-13
No files found.
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfHandler.py
View file @
fe92b22f
...
@@ -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
)
...
...
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfServer.py
View file @
fe92b22f
...
@@ -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
():
...
...
cloudooo/manager.py
View file @
fe92b22f
...
@@ -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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment