3 def filename_regex_extractor(f):
4 """This is a decorator to apply to functions that take a name and return
5 (filename, RegexObject) tuples. It converts it into a function
6 that takes a name and returns another function (the actual extractor)
7 which takes a deployment and returns the value of the extracted variable.
9 The regular expression requires a very specific form, essentially ()()()
10 (with the second subgroup being the value we care about), so that we can
11 reuse the regex for other things.
13 Its Haskell-style type signature would be:
14 (String -> (Filename, Regex)) -> (String -> (Deployment -> String))
16 It's a little bit like a transformer."""
20 contents = deployment.read(file) # cached
21 match = regex.search(contents)
22 if not match: return None
23 # assumes that the second match is the one we want.