Esempio n. 1
0
	def __init__(self, params=dict(), meta=dict()):
		if not isinstance(meta, dict):
			raise TypeError("meta: expected a dict")

		for (key, val) in meta.iteritems():
			if val == 'uuid':
				meta[key] = UUID
			elif val == 'decimal':
				meta[key] = validators.Decimal
			elif val == 'bool':
				meta[key] = validators.StringBoolean
			elif val == 'int':
				meta[key] = validators.Int
			elif val == 'float':
				meta[key] = validators.Float


		if not isinstance(params, dict):
			raise TypeError("params: expected a dict")


		for (key, val) in params.iteritems():
			if val == '':
				params[key] = None
				continue
			if key in meta:
				m = meta[key]
				if is_validator(m):
					params[key] = m.to_python(val)
				elif type(m) == TypeType:
					params[key] = m(val)
				else:
					raise TypeError(type(m))
		self._data = params
Esempio n. 2
0
    def __init__(self, name, doc, validator):
        """Initialise a new `ConfigurationOption`.

        :param name: The name for this option. This is the name as which this
            option will be stored in the underlying `Configuration` object.
        :param doc: A description of the option. This is mandatory.
        :param validator: A `formencode.validators.Validator`.
        """
        super(ConfigurationOption, self).__init__()

        assert isinstance(name, str)
        assert isinstance(doc, str)
        assert is_validator(validator)
        assert validator.if_missing is not NoDefault

        self.name = name
        self.__doc__ = doc
        self.validator = validator
 def test_is_validator(self):
     self.assertTrue(is_validator(CustomValidator))
     self.assertTrue(is_validator(CustomValidator()))
 def test_is_validator(self):
     self.assertTrue(is_validator(DeclarativeAllValidator))
     self.assertTrue(is_validator(DeclarativeAllValidator()))
 def test_is_validator(self):
     self.assertTrue(is_validator(AllAndNotOneValidator))
     self.assertTrue(is_validator(self.validator))
 def test_is_validator(self):
     self.assertTrue(is_validator(CustomCompoundValidator))
     self.assertTrue(is_validator(self.validator))
 def test_is_validator(self):
     self.assertTrue(is_validator(NotOneValidator))
     self.assertTrue(is_validator(NotOneValidator()))
     self.assertTrue(is_validator(NotOneValidator(one=2)))
 def test_is_validator(self):
     self.assertTrue(is_validator(DeprecatedCustomValidator))
     self.assertTrue(is_validator(DeprecatedCustomValidator()))
 def test_is_validator(self):
     self.assertTrue(is_validator(CustomValidator))
     self.assertTrue(is_validator(CustomValidator()))
Esempio n. 10
0
 def test_is_validator(self):
     self.assertTrue(is_validator(DeclarativeAllValidator))
     self.assertTrue(is_validator(DeclarativeAllValidator()))
Esempio n. 11
0
 def test_is_validator(self):
     self.assertTrue(is_validator(AllAndNotOneValidator))
     self.assertTrue(is_validator(self.validator))
Esempio n. 12
0
 def test_is_validator(self):
     self.assertTrue(is_validator(CustomCompoundValidator))
     self.assertTrue(is_validator(self.validator))
Esempio n. 13
0
 def test_is_validator(self):
     self.assertTrue(is_validator(NotOneValidator))
     self.assertTrue(is_validator(NotOneValidator()))
     self.assertTrue(is_validator(NotOneValidator(one=2)))
 def test_is_validator(self):
     self.assertTrue(is_validator(DeprecatedCustomValidator))
     self.assertTrue(is_validator(DeprecatedCustomValidator()))