Skip to content

Commit

Permalink
now it's dark.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmischler committed Sep 20, 2021
1 parent 6ed9686 commit fa62a8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions fpdf/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,24 @@ def load_elements(self, elements):

@staticmethod
def _parse_colorcode(s):
""" Allow hex and oct values for colors """
"""Allow hex and oct values for colors"""
s = s.strip()
if not s:
raise ValueError('Foreground and Background must be numeric')
if s[:2] in ['0x', '0X']:
raise ValueError("Foreground and Background must be numeric")
if s[:2] in ["0x", "0X"]:
return int(s, 16)
if s[0] == '0':
if s[0] == "0":
return int(s, 8)
return int(s)

def parse_csv(self, infile, delimiter=",", decimal_sep=".", encoding=None):
"""Parse template format csv file and create elements dict"""

def varsep_float(s):
"""Convert to float with given decimal seperator"""
# glad to have nonlocal scoping...
return float(s.replace(decimal_sep, '.'))
return float(s.replace(decimal_sep, "."))

handlers = (
("name", str.strip),
("type", str.strip),
Expand Down
4 changes: 2 additions & 2 deletions test/template/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_template_nominal_hardcoded(tmp_path):
"italic": 0,
"underline": 0,
"foreground": 0,
"background": 0x88ff00,
"background": 0x88FF00,
"align": "I",
"text": "Lorem ipsum dolor sit amet, consectetur adipisici elit",
"priority": 2,
Expand Down Expand Up @@ -150,7 +150,7 @@ def test_template_nominal_hardcoded(tmp_path):

def test_template_nominal_csv(tmp_path):
"""Same data as in docs/Templates.md
The numeric_text tests for a regression."""
The numeric_text tests for a regression."""
tmpl = Template(format="A4", title="Sample Invoice")
tmpl.parse_csv(HERE / "mycsvfile.csv", delimiter=";")
tmpl.add_page()
Expand Down

0 comments on commit fa62a8d

Please sign in to comment.