3 new revisions:

Revision: ac8acc06221c
Author:   Pekka Klärck
Date:     Mon Feb 20 04:21:11 2012
Log:      cleanup - non-mutable default values and relative import
http://code.google.com/p/robotframework/source/detail?r=ac8acc06221c

Revision: b55b90ce85ed
Author:   Pekka Klärck
Date:     Mon Feb 20 04:32:33 2012
Log: utils: new utility for matching multiple patterns so that, by default,...
http://code.google.com/p/robotframework/source/detail?r=b55b90ce85ed

Revision: a7dce3985705
Author:   Pekka Klärck
Date:     Mon Feb 20 04:39:24 2012
Log: libdoc/console viewer: removed separate search mode and changed list t...
http://code.google.com/p/robotframework/source/detail?r=a7dce3985705

==============================================================================
Revision: ac8acc06221c
Author:   Pekka Klärck
Date:     Mon Feb 20 04:21:11 2012
Log:      cleanup - non-mutable default values and relative import
http://code.google.com/p/robotframework/source/detail?r=ac8acc06221c

Modified:
 /src/robot/utils/match.py
 /src/robot/utils/normalizing.py

=======================================
--- /src/robot/utils/match.py   Sat Nov  5 16:32:49 2011
+++ /src/robot/utils/match.py   Mon Feb 20 04:21:11 2012
@@ -15,23 +15,23 @@
 import re
 from functools import partial

-from normalizing import normalize
+from .normalizing import normalize


-def eq(str1, str2, ignore=[], caseless=True, spaceless=True):
+def eq(str1, str2, ignore=(), caseless=True, spaceless=True):
     str1 = normalize(str1, ignore, caseless, spaceless)
     str2 = normalize(str2, ignore, caseless, spaceless)
     return str1 == str2


-def matches(string, pattern, ignore=[], caseless=True, spaceless=True):
+def matches(string, pattern, ignore=(), caseless=True, spaceless=True):
     return Matcher(pattern, ignore, caseless, spaceless).match(string)


# TODO: matches_any should be removed and any(utils.match(...) for p in patterns) # used instead. Currently mainly used in robot.common.model and can be removed
 # after that module is nuked.
-def matches_any(string, patterns, ignore=[], caseless=True, spaceless=True): +def matches_any(string, patterns, ignore=(), caseless=True, spaceless=True):
     for pattern in patterns:
         if matches(string, pattern, ignore, caseless, spaceless):
             return True
@@ -42,7 +42,7 @@
     _match_pattern_tokenizer = re.compile('(\*|\?)')
     _wildcards = {'*': '.*', '?': '.'}

-    def __init__(self, pattern, ignore=[], caseless=True, spaceless=True):
+    def __init__(self, pattern, ignore=(), caseless=True, spaceless=True):
         self.pattern = pattern
self._normalize = partial(normalize, ignore=ignore, caseless=caseless,
                                   spaceless=spaceless)
=======================================
--- /src/robot/utils/normalizing.py     Wed Dec  7 07:28:15 2011
+++ /src/robot/utils/normalizing.py     Mon Feb 20 04:21:11 2012
@@ -19,7 +19,7 @@
 _WHITESPACE_REGEXP = re.compile('\s+')


-def normalize(string, ignore=[], caseless=True, spaceless=True):
+def normalize(string, ignore=(), caseless=True, spaceless=True):
     """Normalizes given string according to given spec.

By default string is turned to lower case and all whitespace is removed.

==============================================================================
Revision: b55b90ce85ed
Author:   Pekka Klärck
Date:     Mon Feb 20 04:32:33 2012
Log: utils: new utility for matching multiple patterns so that, by default, no patterns means match
http://code.google.com/p/robotframework/source/detail?r=b55b90ce85ed

Modified:
 /src/robot/utils/__init__.py
 /src/robot/utils/match.py
 /utest/utils/test_match.py

=======================================
--- /src/robot/utils/__init__.py        Thu Feb 16 12:18:59 2012
+++ /src/robot/utils/__init__.py        Mon Feb 20 04:32:33 2012
@@ -25,7 +25,7 @@
 from .htmlutils import html_format, html_escape, html_attr_escape
 from .htmlwriter import HtmlWriter
 from .importer import Importer
-from .match import eq, matches, matches_any, Matcher
+from .match import eq, matches, matches_any, Matcher, MultiMatcher
 from .misc import plural_or_not, printable_name, seq2str, seq2str2, getdoc
 from .normalizing import normalize, normalize_tags, NormalizedDict
 from .robotenv import get_env_var, set_env_var, del_env_var, get_env_vars
=======================================
--- /src/robot/utils/match.py   Mon Feb 20 04:21:11 2012
+++ /src/robot/utils/match.py   Mon Feb 20 04:32:33 2012
@@ -61,3 +61,17 @@

     def match(self, string):
         return self._regexp.match(self._normalize(string)) is not None
+
+
+class MultiMatcher(object):
+
+ def __init__(self, patterns=None, ignore=(), caseless=True, spaceless=True,
+                 match_if_no_patterns=True):
+        self._matchers = [Matcher(p, ignore, caseless, spaceless)
+                          for p in patterns or []]
+        self._match_if_no_patterns = match_if_no_patterns
+
+    def match(self, string):
+        if not self._matchers and self._match_if_no_patterns:
+            return True
+        return any(m.match(string) for m in self._matchers)
=======================================
--- /utest/utils/test_match.py  Sat Nov  5 16:32:49 2011
+++ /utest/utils/test_match.py  Mon Feb 20 04:32:33 2012
@@ -1,5 +1,4 @@
 import unittest
-import sys

 from robot.utils.match import *

@@ -48,5 +47,23 @@
         assert not matcher.match('foo')


+class TestMultiMatcher(unittest.TestCase):
+
+    def test_match_pattern(self):
+        matcher = MultiMatcher(['xxx', 'f*'], ignore=['.', ':'])
+        assert matcher.match('xxx')
+        assert matcher.match('foo')
+        assert matcher.match('..::FOO::..')
+        assert not matcher.match('bar')
+
+    def test_match_when_no_patterns_by_default(self):
+        matcher = MultiMatcher([])
+        assert matcher.match('xxx')
+
+    def test_configure_no_match_when_no_patterns(self):
+        matcher = MultiMatcher(None, match_if_no_patterns=False)
+        assert not matcher.match('xxx')
+
+
 if __name__ == "__main__":
     unittest.main()

==============================================================================
Revision: a7dce3985705
Author:   Pekka Klärck
Date:     Mon Feb 20 04:39:24 2012
Log: libdoc/console viewer: removed separate search mode and changed list to search as pattern by default

Update issue 1061
Search mode removed.

Implementation is pretty much done now. Next some test enhancements and then documentation. Hopefully also review in between.
http://code.google.com/p/robotframework/source/detail?r=a7dce3985705

Modified:
 /atest/robot/libdoc/console_viewer.txt
 /src/robot/libdocpkg/consoleviewer.py

=======================================
--- /atest/robot/libdoc/console_viewer.txt      Mon Feb 20 00:26:57 2012
+++ /atest/robot/libdoc/console_viewer.txt      Mon Feb 20 04:39:24 2012
@@ -11,7 +11,10 @@
     ...   Pause Execution

 List some keywords
- Run Libdoc And Verify Output ${TESTDATADIR}/resource.txt LIST KW? CURDIR
+    Run Libdoc And Verify Output    ${TESTDATADIR}/resource.txt list o
+    ...   Keyword with some "stuff" to <escape>
+    ...   non ascii doc
+ Run Libdoc And Verify Output ${TESTDATADIR}/resource.txt LIST KW? C*R
     ...   curdir
     ...   kw 3
     ...   kw 4
=======================================
--- /src/robot/libdocpkg/consoleviewer.py       Mon Feb 20 00:26:57 2012
+++ /src/robot/libdocpkg/consoleviewer.py       Mon Feb 20 04:39:24 2012
@@ -16,7 +16,7 @@

 import textwrap

-from robot import utils
+from robot.utils import MultiMatcher, encode_output
 from robot.errors import DataError


@@ -24,6 +24,7 @@

     def __init__(self, libdoc):
         self._libdoc = libdoc
+        self._keywords = KeywordMatcher(libdoc)

     @classmethod
     def handles(cls, method):
@@ -37,27 +38,23 @@
         except TypeError:
raise DataError("Wrong number of arguments to view '%s'." % method)

-    def list(self, *included):
-        for kw in KeywordMatcher(self._libdoc).list(included):
+    def list(self, *patterns):
+        for kw in self._keywords.search('*%s*' % p for p in patterns):
             self._console(kw.name)

-    def show(self, *included):
-        if not included or any(utils.eq('intro', inc) for inc in included):
+    def show(self, *names):
+        if MultiMatcher(names).match('intro'):
             self._show_intro(self._libdoc)
             if self._libdoc.inits:
                 self._show_inits(self._libdoc)
-        for kw in KeywordMatcher(self._libdoc).list(included):
+        for kw in self._keywords.search(names):
             self._show_keyword(kw)

-    def search(self, *patterns):
-        for kw in KeywordMatcher(self._libdoc).search(patterns):
-            self._console(kw.name)
-
     def version(self):
         self._console(self._libdoc.version or 'N/A')

     def _console(self, msg):
-        print utils.encode_output(msg)
+        print encode_output(msg)

     def _show_intro(self, lib):
         self._header(lib.name, underline='=')
@@ -103,16 +100,8 @@
     def __init__(self, libdoc):
         self._keywords = libdoc.keywords

-    def list(self, patterns):
-        for kw in self._keywords:
-            if not patterns or self._matches(kw.name, patterns):
-                yield kw
-
-    def _matches(self, item, patterns):
-        return any(utils.matches(item, p) for p in patterns)
-
     def search(self, patterns):
-        patterns = ['*%s*' % p for p in patterns]
+        matcher = MultiMatcher(patterns)
         for kw in self._keywords:
- if self._matches(kw.name, patterns) or self._matches(kw.doc, patterns):
+            if matcher.match(kw.name):
                 yield kw

Reply via email to