Skip to content

Commit a2ee89b

Browse files
committed
Write licenses and rules as plain text
Do not try funky binary writing Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 0d8804a commit a2ee89b

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

src/licensedcode/models.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -425,20 +425,13 @@ def dump(self, licenses_data_dir):
425425
- the license data as YAML frontmatter
426426
- the license text
427427
"""
428-
429-
def write(location, byte_string):
430-
# we write as binary because rules and licenses texts and data are
431-
# UTF-8-encoded bytes
432-
with io.open(location, 'wb') as of:
433-
of.write(byte_string)
434-
435428
metadata = self.to_dict()
436-
content = self.text.encode('utf-8')
429+
content = self.text
437430
rule_post = FrontmatterPost(content=content, handler=SaneYAMLHandler(), **metadata)
438-
output_string = dumps_frontmatter(post=rule_post)
439-
431+
output = dumps_frontmatter(post=rule_post)
440432
license_file = self.license_file(licenses_data_dir=licenses_data_dir)
441-
write(license_file, output_string.encode('utf-8'))
433+
with open(license_file, 'w') as of:
434+
of.write(output)
442435

443436
def load(self, license_file, check_consistency=True):
444437
"""
@@ -2078,19 +2071,14 @@ def dump(self, rules_data_dir):
20782071
if self.is_from_license or self.is_synthetic:
20792072
return
20802073

2081-
def write(location, byte_string):
2082-
# we write as binary because rules and licenses texts and data are
2083-
# UTF-8-encoded bytes
2084-
with io.open(location, 'wb') as of:
2085-
of.write(byte_string)
2086-
20872074
rule_file = self.rule_file(rules_data_dir=rules_data_dir)
20882075

20892076
metadata = self.to_dict()
2090-
content = self.text.encode('utf-8')
2077+
content = self.text
20912078
rule_post = FrontmatterPost(content=content, handler=SaneYAMLHandler(), **metadata)
2092-
output_string = dumps_frontmatter(post=rule_post)
2093-
write(rule_file, output_string.encode('utf-8'))
2079+
output = dumps_frontmatter(post=rule_post)
2080+
with open(rule_file, 'w') as of:
2081+
of.write(output)
20942082

20952083
def load(self, rule_file, with_checks=True):
20962084
"""

0 commit comments

Comments
 (0)