diff options
Diffstat (limited to 'buildscripts/resmokelib/utils/jscomment.py')
-rw-r--r-- | buildscripts/resmokelib/utils/jscomment.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/buildscripts/resmokelib/utils/jscomment.py b/buildscripts/resmokelib/utils/jscomment.py index 67758197c5c..21d1cfa783c 100644 --- a/buildscripts/resmokelib/utils/jscomment.py +++ b/buildscripts/resmokelib/utils/jscomment.py @@ -1,13 +1,11 @@ """Utility for parsing JS comments.""" -from __future__ import absolute_import - import re import yaml # TODO: use a more robust regular expression for matching tags -_JSTEST_TAGS_RE = re.compile(r".*@tags\s*:\s*(\[[^\]]*\])", re.DOTALL) +_JSTEST_TAGS_RE = re.compile(b".*@tags\s*:\s*(\[[^\]]*\])", re.DOTALL) def get_tags(pathname): @@ -29,19 +27,19 @@ def get_tags(pathname): */ """ - with open(pathname) as fp: + with open(pathname, 'rb') as fp: match = _JSTEST_TAGS_RE.match(fp.read()) if match: try: # TODO: it might be worth supporting the block (indented) style of YAML lists in # addition to the flow (bracketed) style tags = yaml.safe_load(_strip_jscomments(match.group(1))) - if not isinstance(tags, list) and all(isinstance(tag, basestring) for tag in tags): + if not isinstance(tags, list) and all(isinstance(tag, str) for tag in tags): raise TypeError("Expected a list of string tags, but got '%s'" % (tags)) return tags except yaml.YAMLError as err: - raise ValueError("File '%s' contained invalid tags (expected YAML): %s" % (pathname, - err)) + raise ValueError( + "File '%s' contained invalid tags (expected YAML): %s" % (pathname, err)) return [] @@ -68,6 +66,9 @@ def _strip_jscomments(string): yaml_lines = [] + if isinstance(string, bytes): + string = string.decode("utf-8") + for line in string.splitlines(): # Remove leading whitespace and symbols that commonly appear in JS comments. line = line.lstrip("\t ").lstrip("*/") |