Robot Framework Integrated Development Environment (RIDE)
namepatterns.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.utils import MultiMatcher, py2to3
17 
18 
19 @py2to3
20 class _NamePatterns():
21 
22  def __init__(self, patterns=None):
23  self._matcher_matcher = MultiMatcher(patterns, ignore='_')
24 
25  def match(self, name, longname=None):
26  return self._match_match(name) or longname and self._match_longname_match_longname(longname)
27 
28  def _match(self, name):
29  return self._matcher_matcher.match(name)
30 
31  def _match_longname(self, name):
32  raise NotImplementedError
33 
34  def __nonzero__(self):
35  return bool(self._matcher_matcher)
36 
37  def __iter__(self):
38  return iter(self._matcher_matcher)
39 
40 
42 
43  def _match_longname(self, name):
44  while '.' in name:
45  if self._match_match(name):
46  return True
47  name = name.split('.', 1)[1]
48  return False
49 
50 
52 
53  def _match_longname(self, name):
54  return self._match_match(name)