Skip to content
Permalink
Browse files

Optimized re_meta().

  • Loading branch information
felixfontein committed Jul 1, 2017
1 parent 6717091 commit a03d4eab2a5ee238b63d2092fc691f4aa7bf47a9
Showing with 6 additions and 1 deletion.
  1. +6 −1 nikola/utils.py
@@ -2030,12 +2030,17 @@ def read_from_config(self, site, basename, posts_per_classification_per_language
signal('{}_translations_config'.format(basename.lower())).send(args)


# Moved to global variable to avoid recompilation
# of regex every time re_meta() is called.
_DEFAULT_REST_METADATA_PARSING = re.compile('^\.\. (.*?): (.*)')


def re_meta(line, match=None):
"""Find metadata using regular expressions."""
if match:
reStr = re.compile('^\.\. {0}: (.*)'.format(re.escape(match)))
else:
reStr = re.compile('^\.\. (.*?): (.*)')
reStr = _DEFAULT_REST_METADATA_PARSING
result = reStr.findall(line.strip())
if match and result:
return (match, result[0])

0 comments on commit a03d4ea

Please sign in to comment.