示例#1
0
  def __getattr__(self, attr):  # pylint: disable=invalid-name
    """Support our default set of validators as direct attributes."""
    # Don't provide a back door to validators.py private stuff accidentally.
    if attr.startswith('_') or not validators.has_validator(attr):
      raise AttributeError("'%s' object has no attribute '%s'" % (
          type(self).__name__, attr))

    # Create a wrapper to invoke the attribute from within validators.
    def _with_validator(*args, **kwargs):  # pylint: disable=invalid-name
      return self.with_validator(
          validators.create_validator(attr, *args, **kwargs))
    return _with_validator
示例#2
0
  def __getattr__(self, attr):  # pylint: disable=invalid-name
    """Support our default set of validators as direct attributes."""
    # Don't provide a back door to validators.py private stuff accidentally.
    if attr.startswith('_') or not validators.has_validator(attr):
      raise AttributeError("'%s' object has no attribute '%s'" % (
          type(self).__name__, attr))

    # Create a wrapper to invoke the attribute from within validators.
    def _with_validator(*args, **kwargs):  # pylint: disable=invalid-name
      return self.with_validator(
          validators.create_validator(attr, *args, **kwargs))
    return _with_validator