blob: 34edd1eac68a007736a3d75f86b718524275aa35 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
import re
import yaml
def parse(src):
'''Parse the YAML-formatted metadata found in a given string of source
code. Tolerate missing or invalid metadata; those conditions are handled by
a dedicated "Check" instance.'''
match = re.search(r'/\*---(.*)---\*/', src, re.DOTALL)
if not match:
return None
try:
return yaml.load(match.group(1))
except (yaml.scanner.ScannerError, yaml.parser.ParserError):
return None
|