Robot Framework
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 robot.errors import DataError
17 from robot.model import TagPatterns
18 from robot.utils import MultiMatcher, is_list_like
19 
20 
22  for opt in options:
23  low = opt.lower()
24  # TODO: Deprecate 'foritem' in RF 6.1!
25  if low == 'foritem':
26  low = 'iteration'
27  if not (low in ('for', 'while', 'iteration') or
28  low.startswith('name:') or
29  low.startswith('tag:')):
30  raise DataError(f"Expected 'FOR', 'WHILE', 'ITERATION', 'TAG:<pattern>' or "
31  f"'NAME:<pattern>', got '{opt}'.")
32 
33 
35 
36  def __init__(self, flatten):
37  if not is_list_like(flatten):
38  flatten = [flatten]
39  flatten = [f.lower() for f in flatten]
40  self.typestypes = set()
41  if 'for' in flatten:
42  self.typestypes.add('for')
43  if 'while' in flatten:
44  self.typestypes.add('while')
45  if 'iteration' in flatten or 'foritem' in flatten:
46  self.typestypes.add('iter')
47 
48  def match(self, tag):
49  return tag in self.typestypes
50 
51  def __bool__(self):
52  return bool(self.typestypes)
53 
54 
56 
57  def __init__(self, flatten):
58  if not is_list_like(flatten):
59  flatten = [flatten]
60  names = [n[5:] for n in flatten if n[:5].lower() == 'name:']
61  self._matcher_matcher = MultiMatcher(names)
62 
63  def match(self, kwname, libname=None):
64  name = '%s.%s' % (libname, kwname) if libname else kwname
65  return self._matcher_matcher.match(name)
66 
67  def __bool__(self):
68  return bool(self._matcher_matcher)
69 
70 
72 
73  def __init__(self, flatten):
74  if not is_list_like(flatten):
75  flatten = [flatten]
76  patterns = [p[4:] for p in flatten if p[:4].lower() == 'tag:']
77  self._matcher_matcher = TagPatterns(patterns)
78 
79  def match(self, kwtags):
80  return self._matcher_matcher.match(kwtags)
81 
82  def __bool__(self):
83  return bool(self._matcher_matcher)
def is_list_like(item)
Definition: robottypes.py:66