Title: [96115] trunk/Tools
Revision
96115
Author
le...@chromium.org
Date
2011-09-27 08:52:14 -0700 (Tue, 27 Sep 2011)

Log Message

watchlist: Change watchlistparser.py to be class based.
https://bugs.webkit.org/show_bug.cgi?id=68869

Reviewed by Eric Seidel.

* Scripts/webkitpy/common/watchlist/watchlistparser.py:
* Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py:

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (96114 => 96115)


--- trunk/Tools/ChangeLog	2011-09-27 15:50:42 UTC (rev 96114)
+++ trunk/Tools/ChangeLog	2011-09-27 15:52:14 UTC (rev 96115)
@@ -1,5 +1,15 @@
 2011-09-27  David Levin  <le...@chromium.org>
 
+        watchlist: Change watchlistparser.py to be class based.
+        https://bugs.webkit.org/show_bug.cgi?id=68869
+
+        Reviewed by Eric Seidel.
+
+        * Scripts/webkitpy/common/watchlist/watchlistparser.py:
+        * Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py:
+
+2011-09-27  David Levin  <le...@chromium.org>
+
         watchlist: Break out the diff boilerplate to allow for re-use.
         https://bugs.webkit.org/show_bug.cgi?id=68871
 

Modified: trunk/Tools/Scripts/webkitpy/common/watchlist/watchlistparser.py (96114 => 96115)


--- trunk/Tools/Scripts/webkitpy/common/watchlist/watchlistparser.py	2011-09-27 15:50:42 UTC (rev 96114)
+++ trunk/Tools/Scripts/webkitpy/common/watchlist/watchlistparser.py	2011-09-27 15:52:14 UTC (rev 96115)
@@ -29,48 +29,47 @@
 import re
 from webkitpy.common.watchlist.watchlist import WatchList
 
-_DEFINITIONS = 'DEFINITIONS'
-_INVALID_DEFINITION_NAME_REGEX = r'\|'
 
+class WatchListParser(object):
+    _DEFINITIONS = 'DEFINITIONS'
+    _INVALID_DEFINITION_NAME_REGEX = r'\|'
 
-def _eval_watch_list(watch_list_contents):
-    return eval(watch_list_contents, {'__builtins__': None}, None)
+    def __init__(self):
+        self._section_parsers = {self._DEFINITIONS: self._parse_definition_section, }
+        self._definition_pattern_parsers = {}
 
-_DEFINITION_MATCH_PARSER = {}
+    def parse(self, watch_list_contents):
+        watch_list = WatchList()
 
+        # Change the watch list text into a dictionary.
+        dictionary = self._eval_watch_list(watch_list_contents)
 
-def _parse_definition_section(definition_section, watch_list):
-    definitions = {}
-    for name in definition_section:
-        invalid_character = re.search(_INVALID_DEFINITION_NAME_REGEX, name)
-        if invalid_character:
-            raise Exception('Invalid character "%s" in definition "%s".' % (invalid_character.group(0), name))
+        # Parse the top level sections in the watch list.
+        for section in dictionary:
+            parser = self._section_parsers.get(section)
+            if not parser:
+                raise Exception('Unknown section "%s" in watch list.' % section)
+            parser(dictionary[section], watch_list)
 
-        definition = definition_section[name]
-        definitions[name] = []
-        for pattern_type in definition:
-            pattern_parser = _DEFINITION_MATCH_PARSER.get(pattern_type)
-            if not pattern_parser:
-                raise Exception('Invalid pattern type "%s" in definition "%s".' % (pattern_type, name))
+        return watch_list
 
-            pattern = pattern_parser(definition[pattern_type])
-            definitions[name].append(pattern)
-    watch_list.set_definitions(definitions)
+    def _eval_watch_list(self, watch_list_contents):
+        return eval(watch_list_contents, {'__builtins__': None}, None)
 
-_SECTION_PARSERS = {_DEFINITIONS: _parse_definition_section, }
+    def _parse_definition_section(self, definition_section, watch_list):
+        definitions = {}
+        for name in definition_section:
+            invalid_character = re.search(self._INVALID_DEFINITION_NAME_REGEX, name)
+            if invalid_character:
+                raise Exception('Invalid character "%s" in definition "%s".' % (invalid_character.group(0), name))
 
+            definition = definition_section[name]
+            definitions[name] = []
+            for pattern_type in definition:
+                pattern_parser = self._definition_pattern_parsers.get(pattern_type)
+                if not pattern_parser:
+                    raise Exception('Invalid pattern type "%s" in definition "%s".' % (pattern_type, name))
 
-def parse_watch_list(watch_list_contents):
-    watch_list = WatchList()
-
-    # Change the watch list text into a dictionary.
-    dictionary = _eval_watch_list(watch_list_contents)
-
-    # Parse the top level sections in the watch list.
-    for section in dictionary:
-        parser = _SECTION_PARSERS.get(section)
-        if not parser:
-            raise Exception('Unknown section "%s" in watch list.' % section)
-        parser(dictionary[section], watch_list)
-
-    return watch_list
+                pattern = pattern_parser(definition[pattern_type])
+                definitions[name].append(pattern)
+        watch_list.set_definitions(definitions)

Modified: trunk/Tools/Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py (96114 => 96115)


--- trunk/Tools/Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py	2011-09-27 15:50:42 UTC (rev 96114)
+++ trunk/Tools/Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py	2011-09-27 15:52:14 UTC (rev 96115)
@@ -30,7 +30,7 @@
 
 import re
 import unittest
-from webkitpy.common.watchlist.watchlistparser import parse_watch_list
+from webkitpy.common.watchlist.watchlistparser import WatchListParser
 
 
 class WatchListParserTest(unittest.TestCase):
@@ -38,6 +38,7 @@
         # For versions of Python before 2.7.
         if not 'assertRaisesRegexp' in dir(self):
             self.assertRaisesRegexp = self._verifyException
+        self._watch_list_parser = WatchListParser()
 
     def _verifyException(self, regex_message, callable, *args):
         try:
@@ -49,7 +50,8 @@
 
     def test_bad_section(self):
         watch_list_with_bad_section = ('{"FOO": {}}')
-        self.assertRaisesRegexp('Unknown section "FOO" in watch list.', parse_watch_list, watch_list_with_bad_section)
+        self.assertRaisesRegexp('Unknown section "FOO" in watch list.',
+                                self._watch_list_parser.parse, watch_list_with_bad_section)
 
     def test_bad_definition(self):
         watch_list_with_bad_definition = (
@@ -61,7 +63,8 @@
             '     },'
             '}')
 
-        self._verifyException('Invalid character "|" in definition "WatchList1|A".', parse_watch_list, watch_list_with_bad_definition)
+        self._verifyException('Invalid character "|" in definition "WatchList1|A".',
+                              self._watch_list_parser.parse, watch_list_with_bad_definition)
 
     def test_bad_match_type(self):
         watch_list_with_bad_match_type = (
@@ -73,4 +76,5 @@
             '     },'
             '}')
 
-        self._verifyException('Invalid pattern type "nothing_matches_this" in definition "WatchList1".', parse_watch_list, watch_list_with_bad_match_type)
+        self._verifyException('Invalid pattern type "nothing_matches_this" in definition "WatchList1".',
+                              self._watch_list_parser.parse, watch_list_with_bad_match_type)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to