Revision: e599b53bfc03
Author: Pekka Klärck
Date: Tue Aug 28 13:41:31 2012
Log: parsing: little cleanup while browsing through the code
http://code.google.com/p/robotframework/source/detail?r=e599b53bfc03
Added:
/src/robot/parsing/comments.py
Modified:
/src/robot/parsing/model.py
/src/robot/parsing/populators.py
/src/robot/parsing/tablepopulators.py
=======================================
--- /dev/null
+++ /src/robot/parsing/comments.py Tue Aug 28 13:41:31 2012
@@ -0,0 +1,40 @@
+# Copyright 2008-2012 Nokia Siemens Networks Oyj
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+class CommentCache(object):
+
+ def __init__(self):
+ self._comments = []
+
+ def add(self, comment):
+ self._comments.append(comment)
+
+ def consume(self, function):
+ map(function, self._comments)
+ self.__init__()
+
+
+class Comments(object):
+
+ def __init__(self):
+ self._comments = []
+
+ def add(self, row):
+ if row.comments:
+ self._comments.extend(c.strip() for c in row.comments if
c.strip())
+
+ @property
+ def value(self):
+ return self._comments
=======================================
--- /src/robot/parsing/model.py Wed Jun 13 00:59:40 2012
+++ /src/robot/parsing/model.py Tue Aug 28 13:41:31 2012
@@ -459,7 +459,7 @@
if name.startswith('$') and value == []:
value = ''
if isinstance(value, basestring):
- value = [value] # Must support scalar lists until RF 2.7
(issue 939)
+ value = [value] # Must support scalar lists until RF 2.8
(issue 939)
self.value = value
self.comment = Comment(comment)
=======================================
--- /src/robot/parsing/populators.py Fri Jun 8 01:14:49 2012
+++ /src/robot/parsing/populators.py Tue Aug 28 13:41:31 2012
@@ -45,7 +45,7 @@
def __init__(self, datafile):
self._datafile = datafile
- self._current_populator = NullPopulator()
+ self._populator = NullPopulator()
self._curdir = self._get_curdir(datafile.directory)
def _get_curdir(self, path):
@@ -77,21 +77,21 @@
raise DataError("Unsupported file format '%s'." % extension)
def start_table(self, header):
- self._current_populator.populate()
+ self._populator.populate()
table = self._datafile.start_table(DataRow(header).all)
- self._current_populator = self._populators[table.type](table) \
- if table is not None else
NullPopulator()
- return bool(self._current_populator)
+ self._populator = self._populators[table.type](table) \
+ if table is not None else NullPopulator()
+ return bool(self._populator)
def eof(self):
- self._current_populator.populate()
+ self._populator.populate()
def add(self, row):
if PROCESS_CURDIR and self._curdir:
row = self._replace_curdirs_in(row)
data = DataRow(row)
if data:
- self._current_populator.add(data)
+ self._populator.add(data)
def _replace_curdirs_in(self, row):
return [cell.replace('${CURDIR}', self._curdir) for cell in row]
=======================================
--- /src/robot/parsing/tablepopulators.py Thu May 31 00:04:27 2012
+++ /src/robot/parsing/tablepopulators.py Tue Aug 28 13:41:31 2012
@@ -14,42 +14,42 @@
import re
-from robot.parsing.settings import Documentation, MetadataList
+from .comments import CommentCache, Comments
+from .settings import Documentation, MetadataList
class Populator(object):
"""Explicit interface for all populators."""
- def add(self, row): raise NotImplementedError()
- def populate(self): raise NotImplementedError()
+ def add(self, row):
+ raise NotImplementedError
-class CommentCacher(object):
+ def populate(self):
+ raise NotImplementedError
- def __init__(self):
- self._init_comments()
- def _init_comments(self):
- self._comments = []
+class NullPopulator(Populator):
- def add(self, comment):
- self._comments.append(comment)
+ def add(self, row):
+ pass
- def consume_comments_with(self, function):
- for c in self._comments:
- function(c)
- self._init_comments()
+ def populate(self):
+ pass
+ def __nonzero__(self):
+ return False
+
class _TablePopulator(Populator):
def __init__(self, table):
self._table = table
self._populator = NullPopulator()
- self._comments = CommentCacher()
+ self._comment_cache = CommentCache()
def add(self, row):
if self._is_cacheable_comment_row(row):
- self._comments.add(row)
+ self._comment_cache.add(row)
else:
self._add(row)
@@ -57,11 +57,14 @@
if not self._is_continuing(row):
self._populator.populate()
self._populator = self._get_populator(row)
- self._comments.consume_comments_with(self._populator.add)
+ self._comment_cache.consume(self._populator.add)
self._populator.add(row)
+ def _get_populator(self, row):
+ raise NotImplementedError
+
def populate(self):
- self._comments.consume_comments_with(self._populator.add)
+ self._comment_cache.consume(self._populator.add)
self._populator.populate()
def _is_continuing(self, row):
@@ -150,7 +153,7 @@
self._test_or_uk_creator = test_or_uk_creator
self._test_or_uk = None
self._populator = NullPopulator()
- self._comments = CommentCacher()
+ self._comments = CommentCache()
def add(self, row):
if row.is_commented():
@@ -166,9 +169,9 @@
if not self._continues(row):
self._populator.populate()
self._populator = self._get_populator(row)
- self._flush_comments_with(self._populate_comment_row)
+ self._comments.consume(self._populate_comment_row)
else:
- self._flush_comments_with(self._populator.add)
+ self._comments.consume(self._populator.add)
self._populator.add(row)
def _populate_comment_row(self, crow):
@@ -176,12 +179,9 @@
populator.add(crow)
populator.populate()
- def _flush_comments_with(self, function):
- self._comments.consume_comments_with(function)
-
def populate(self):
self._populator.populate()
- self._flush_comments_with(self._populate_comment_row)
+ self._comments.consume(self._populate_comment_row)
def _get_populator(self, row):
if row.starts_test_or_user_keyword_setting():
@@ -212,20 +212,6 @@
_item_type = 'keyword'
-class Comments(object):
-
- def __init__(self):
- self._comments = []
-
- def add(self, row):
- if row.comments:
- self._comments.extend(c.strip() for c in row.comments if
c.strip())
-
- @property
- def value(self):
- return self._comments
-
-
class _PropertyPopulator(Populator):
def __init__(self, setter):
@@ -249,8 +235,7 @@
self._name = name
def populate(self):
- self._setter(self._name, self._value,
- self._comments.value)
+ self._setter(self._name, self._value, self._comments.value)
class SettingPopulator(_PropertyPopulator):
@@ -317,9 +302,3 @@
def populate(self):
if self._value or self._comments:
self._setter(self._value, self._comments.value)
-
-
-class NullPopulator(Populator):
- def add(self, row): pass
- def populate(self): pass
- def __nonzero__(self): return False