Switch to unified view

a/Allura/allura/lib/validators.py b/Allura/allura/lib/validators.py
1
import json
1
from bson import ObjectId
2
from bson import ObjectId
2
import formencode as fe
3
import formencode as fe
3
from formencode import validators as fev
4
from formencode import validators as fev
4
from . import helpers as h
5
from . import helpers as h
5
6
...
...
50
            raise fe.Invalid("Please enter a value less than %s bytes long." % self.max, value, state)
51
            raise fe.Invalid("Please enter a value less than %s bytes long." % self.max, value, state)
51
        return value
52
        return value
52
53
53
    def from_python(self, value, state):
54
    def from_python(self, value, state):
54
        return h.really_unicode(value or '')
55
        return h.really_unicode(value or '')
56
57
class JsonValidator(fev.FancyValidator):
58
    def _to_python(self, value, state):
59
        try:
60
            json.loads(value)
61
        except ValueError, e:
62
            raise fe.Invalid('Invalid JSON: ' + str(e), value, state)
63
        return value