summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorChristopher Larson <chris_larson@mentor.com>2012-05-15 20:26:25 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-05-17 21:13:08 +0100
commit0c7720027b5333d96d349a24ba1dfc9967155331 (patch)
treefa66d89a8e7fe4a828f279a19445d9aaa3b56a11 /meta/lib
parentcaee06405f90d44b3476af645e2b3918578ba6b9 (diff)
downloadpoky-0c7720027b5333d96d349a24ba1dfc9967155331.tar.gz
oe.types: give the regex type more sane semantics
Currently, if a variable is unset or has an empty value, the regex type will return a match object which always matches. Not all variable types will necessarily have the same behavior for handling defaults. I believe that returning a match object which matches nothing when a variable is unset is superior to returning one which matches anything, and the user can always explicitly request anything via '.*', if that's what they want. This constructs a null pattern object which will never match, and uses it when encountering an unset or empty variable (currently, these two things are one and the same, as maketype is handling the default. we may well want to shift that logic into the individual types, giving them more control over default behavior, but currently the behavior is at least relatively consistent -- no difference between unset and empty variables). (From OE-Core rev: dc7e4a79d9a1884b4c5705ef3173613958204b50) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/types.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/meta/lib/oe/types.py b/meta/lib/oe/types.py
index ea31cf4219..ea53df9bf2 100644
--- a/meta/lib/oe/types.py
+++ b/meta/lib/oe/types.py
@@ -40,6 +40,31 @@ def choice(value, choices):
40 (value, choices)) 40 (value, choices))
41 return value 41 return value
42 42
43class NoMatch(object):
44 """Stub python regex pattern object which never matches anything"""
45 def findall(self, string, flags=0):
46 return None
47
48 def finditer(self, string, flags=0):
49 return None
50
51 def match(self, flags=0):
52 return None
53
54 def search(self, string, flags=0):
55 return None
56
57 def split(self, string, maxsplit=0):
58 return None
59
60 def sub(pattern, repl, string, count=0):
61 return None
62
63 def subn(pattern, repl, string, count=0):
64 return None
65
66NoMatch = NoMatch()
67
43def regex(value, regexflags=None): 68def regex(value, regexflags=None):
44 """OpenEmbedded 'regex' type 69 """OpenEmbedded 'regex' type
45 70
@@ -59,6 +84,12 @@ def regex(value, regexflags=None):
59 except AttributeError: 84 except AttributeError:
60 raise ValueError("Invalid regex flag '%s'" % flag) 85 raise ValueError("Invalid regex flag '%s'" % flag)
61 86
87 if not value:
88 # Let's ensure that the default behavior for an undefined or empty
89 # variable is to match nothing. If the user explicitly wants to match
90 # anything, they can match '.*' instead.
91 return NoMatch
92
62 try: 93 try:
63 return re.compile(value, flagval) 94 return re.compile(value, flagval)
64 except re.error, exc: 95 except re.error, exc: