diff options
author | mike <michael.jmontcalm@gmail.com> | 2009-11-19 14:38:39 (GMT) |
---|---|---|
committer | mike <michael.jmontcalm@gmail.com> | 2009-11-19 14:40:25 (GMT) |
commit | 88b3f3099252353e22c536a68e15e2a2f9b10334 (patch) | |
tree | f9c754a9f348e5020687e705f40f426175375353 /tutorius/constraints.py | |
parent | 40f836b057896469bca69772d9fc7168b2f8c644 (diff) |
LP 448319 : Addition of resource properties, insertion of BubbleMessageWImg from Dave, modification of Engine to get action_addresses
Diffstat (limited to 'tutorius/constraints.py')
-rw-r--r-- | tutorius/constraints.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tutorius/constraints.py b/tutorius/constraints.py index 519bce8..cd71167 100644 --- a/tutorius/constraints.py +++ b/tutorius/constraints.py @@ -24,6 +24,8 @@ for some properties. # For the File Constraint import os +# For the Resource Constraint +import re class ConstraintException(Exception): """ @@ -214,3 +216,40 @@ class FileConstraint(Constraint): raise FileConstraintError("Non-existing file : %s"%value) return +class ResourceConstraintError(ConstraintException): + pass + +class ResourceConstraint(Constraint): + """ + Ensures that the value is looking like a resource name, like + <filename>_<GUID>[.<extension>]. We are not validating that this is a + valid resource for the reason that the property does not have any notion + of tutorial guid. + + TODO : Find a way to properly validate resources by looking them up in the + Vault. + """ + + # Regular expression to parse a resource-like name + resource_regexp_text = "(.+)_([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})(\..*)?$" + resource_regexp = re.compile(resource_regexp_text) + + def validate(self, value): + # TODO : Validate that we will not use an empty resource or if we can + # have transitory resource names + if value is None: + raise ResourceConstraintError("Resource not allowed to have a null value!") + + # Special case : We allow the empty resource name for now + if value == "": + return value + + # Attempt to see if the value has a resource name inside it + match = self.resource_regexp.search(value) + + # If there was no match on the reg exp + if not match: + raise ResourceConstraintError("Resource name does not seem to be valid : %s" % value) + + # If the name matched, then the value is _PROBABLY_ good + return value |