changeset 2158:da8b2a06ebec

update subscription validator 1. Use of constants in the error message 2. Check NAMEPREFIX value validity 3. Validate NAMERE pattern 4. Change the 'invalid value' error message
author Ana Balica <ana.balica@gmail.com>
date Sat, 20 Jul 2013 21:20:43 +0300
parents 17e16815dc51
children 246904e49804
files MoinMoin/storage/middleware/validation.py
diffstat 1 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/storage/middleware/validation.py	Sat Jul 20 20:55:52 2013 +0300
+++ b/MoinMoin/storage/middleware/validation.py	Sat Jul 20 21:20:43 2013 +0300
@@ -25,6 +25,7 @@
 from __future__ import absolute_import, division
 
 import time
+import re
 
 from flatland import Dict, List, Unset, Boolean, Integer, String
 
@@ -345,18 +346,25 @@
     else:
         element.add_error(
             "Subscription must start with one of the keywords: "
-            "'itemid', 'name', 'tags', 'namere' or 'nameprefix'.")
+            "'{0}', '{1}', '{2}', '{3}' or '{4}'.".format(keys.ITEMID,
+                                                          keys.NAME, keys.TAGS,
+                                                          keys.NAMERE,
+                                                          keys.NAMEPREFIX))
         return False
 
     value_element = String(value)
     if keyword == keys.TAGS:
         valid = tag_validator(value_element, state)
-    elif keyword == keys.NAME:
+    elif keyword in (keys.NAME, keys.NAMEPREFIX, ):
         valid = name_validator(value_element, state)
-    elif keyword in (keys.NAMERE, keys.NAMEPREFIX):
-        valid = True
+    elif keyword == keys.NAMERE:
+        try:
+            re.compile(value, re.U)
+            valid = True
+        except re.error:
+            valid = False
     if not valid:
-        element.add_error("The value is not valid.")
+        element.add_error("Subscription has invalid value.")
     return valid