Skip to content

Commit 80c81d6

Browse files
committed
[IMP] papermuncher: Refactor and update the Python bindings
1 parent 1d94930 commit 80c81d6

File tree

11 files changed

+602
-153
lines changed

11 files changed

+602
-153
lines changed

meta/bindings/python/papermuncher.py

Lines changed: 0 additions & 141 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .communication import Request, Response
2+
from .environ import Environ
3+
from .exceptions import PaperMuncherException
4+
from .bindings import PaperMuncher, PaperMuncherProcess
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
if __name__ == "__main__":
3+
# get the arguments from the command line
4+
import argparse
5+
import logging
6+
7+
parser = argparse.ArgumentParser(description="Paper Muncher CLI")
8+
parser.add_argument(
9+
"--test",
10+
action="store_true",
11+
help="Run the test environment with mocked data"
12+
)
13+
parser.add_argument(
14+
"--test-enable",
15+
action="store_true",
16+
help="Enable run the full test suite"
17+
)
18+
# print the given arguments
19+
args = parser.parse_args()
20+
21+
if args.test:
22+
from .testing import TestEnvironMocked
23+
from .bindings import PaperMuncher
24+
logger = logging.getLogger(__name__)
25+
logger.setLevel(logging.DEBUG)
26+
27+
env = TestEnvironMocked(
28+
html="<html><body><h1>Hello, World!</h1></body></html>",
29+
data_dir={
30+
'/style.css': 'body { background-color: #0000ff; }',
31+
}
32+
)
33+
pm = PaperMuncher(env, mode='print')
34+
html_content = """<html>
35+
<head>
36+
<link rel="stylesheet" href="/style.css">
37+
<link rel="stylesheet2" href="/not_found.css">
38+
</head>
39+
<body>
40+
<h1>Hello, World!</h1>
41+
</body>
42+
</html>"""
43+
pdf_bytes = pm.to_pdf(html_content)
44+
with open("output.pdf", "wb") as f:
45+
f.write(pdf_bytes)
46+
47+
elif args.test_enable:
48+
from .tests import run_tests
49+
run_tests()

0 commit comments

Comments
 (0)