MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / load_frontmatter

Function load_frontmatter

src/licensedcode/frontmatter.py:129–142  ·  view source on GitHub ↗

Load and parse a file-like object or filename `fd`, and return `content` and `metadata` with the text and the frontmatter metadata.

(fd, encoding="utf-8", **defaults)

Source from the content-addressed store, hash-verified

127
128
129def load_frontmatter(fd, encoding="utf-8", **defaults):
130 """
131 Load and parse a file-like object or filename `fd`, and return
132 `content` and `metadata` with the text and the frontmatter metadata.
133 """
134 if hasattr(fd, "read"):
135 text = fd.read()
136
137 else:
138 with codecs.open(fd, "r", encoding) as f:
139 text = f.read()
140
141 text = return_unicode(text, encoding)
142 return parse_frontmatter(text, encoding, **defaults)
143
144
145def dumps_frontmatter(content, metadata, handler=SaneYAMLHandler(), **kwargs):

Callers 2

loadMethod · 0.90
loadMethod · 0.90

Calls 4

return_unicodeFunction · 0.85
parse_frontmatterFunction · 0.85
readMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected