+def fix_wluri(elem, change, verbose):
+ try:
+ WLURI.strict(elem.text)
+ except ValidationError:
+ correct_field = unicode(WLURI.from_slug(
+ WLURI(elem.text.strip()).slug))
+ try:
+ WLURI.strict(correct_field)
+ except ValidationError:
+ # Can't make a valid WLURI out of it, leave as is.
+ return False
+ if verbose:
+ print "Changing %s from %s to %s" % (
+ elem.tag, elem.text, correct_field
+ )
+ elem.text = correct_field
+ return True
+
+