Passed
Push — main ( c109b9...4198d9 )
by Sat CFDI
04:48
created

satcfdi.printer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
wmc 6
eloc 26
dl 0
loc 38
ccs 16
cts 22
cp 0.7272
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A Representable.html_write() 0 8 2
A Representable.html_str() 0 8 2
A Representable.pdf_bytes() 0 3 1
A Representable.pdf_write() 0 4 1
1 1
from lxml.etree import QName
2 1
from weasyprint import HTML, CSS
3
4 1
from .transform import *
5 1
from .transform.pdf_environment import PDFEnvironment
6
7 1
PDF_CSS = CSS(string="@page {margin: 1.0cm 1.27cm 1.1cm 0.85cm;}")
8
9
10 1
class Representable:
11 1
    def html_write(self, target, templates_path=None):
12
        if templates_path:
13
            env = PDFEnvironment(templates_path=templates_path)
14
            init_template = env.get_template("_init.html")
15
        else:
16
            init_template = PDF_INIT_TEMPLATE
17
18
        init_template.stream({"c": self, "k": QName(self.tag).localname}).dump(target)
19
20 1
    def html_str(self, templates_path=None) -> str:
21 1
        if templates_path:
22 1
            env = PDFEnvironment(templates_path=templates_path)
23 1
            init_template = env.get_template("_init.html")
24
        else:
25 1
            init_template = PDF_INIT_TEMPLATE
26
27 1
        return init_template.render({"c": self, "k": QName(self.tag).localname})
28
29 1
    def pdf_write(self, target, templates_path=None):
30 1
        HTML(string=self.html_str(templates_path=templates_path)).write_pdf(
31
            target=target,
32
            stylesheets=[PDF_CSS]
33
        )
34
35 1
    def pdf_bytes(self, templates_path=None) -> bytes:
36
        return HTML(string=self.html_str(templates_path=templates_path)).write_pdf(
37
            stylesheets=[PDF_CSS]
38
        )
39