2017-05-01 18:04:05 +02:00
|
|
|
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:
|
2019-08-12 15:49:14 +02:00
|
|
|
return yaml.safe_load(match.group(1))
|
2017-05-01 18:04:05 +02:00
|
|
|
except (yaml.scanner.ScannerError, yaml.parser.ParserError):
|
|
|
|
return None
|