Robot Framework Integrated Development Environment (RIDE)
flattenkeywordmatcher.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 from robotide.lib.robot.errors import DataError
17 from robotide.lib.robot.model import TagPatterns
18 from robotide.lib.robot.utils import MultiMatcher, is_list_like, py2to3
19 
20 
22  for opt in options:
23  low = opt.lower()
24  if not (low in ('for', 'foritem') or
25  low.startswith('name:') or
26  low.startswith('tag:')):
27  raise DataError("Expected 'FOR', 'FORITEM', 'TAG:<pattern>', or "
28  "'NAME:<pattern>' but got '%s'." % opt)
29 
30 
31 @py2to3
33 
34  def __init__(self, flatten):
35  if not is_list_like(flatten):
36  flatten = [flatten]
37  flatten = [f.lower() for f in flatten]
38  self._types_types = [f for f in flatten if f in ('for', 'foritem')]
39 
40  def match(self, kwtype):
41  return kwtype in self._types_types
42 
43  def __nonzero__(self):
44  return bool(self._types_types)
45 
46 
47 @py2to3
49 
50  def __init__(self, flatten):
51  if not is_list_like(flatten):
52  flatten = [flatten]
53  names = [n[5:] for n in flatten if n[:5].lower() == 'name:']
54  self._matcher_matcher = MultiMatcher(names)
55 
56  def match(self, kwname, libname=None):
57  name = '%s.%s' % (libname, kwname) if libname else kwname
58  return self._matcher_matcher.match(name)
59 
60  def __nonzero__(self):
61  return bool(self._matcher_matcher)
62 
63 
64 @py2to3
66 
67  def __init__(self, flatten):
68  if not is_list_like(flatten):
69  flatten = [flatten]
70  patterns = [p[4:] for p in flatten if p[:4].lower() == 'tag:']
71  self._matcher_matcher = TagPatterns(patterns)
72 
73  def match(self, kwtags):
74  return self._matcher_matcher.match(kwtags)
75 
76  def __nonzero__(self):
77  return bool(self._matcher_matcher)
Used when variable does not exist.
Definition: errors.py:67