Permalink
Commits on Oct 9, 2012
  1. indenting

    mcdonc committed Oct 9, 2012
Commits on Oct 8, 2012
  1. update

    mcdonc committed Oct 8, 2012
Commits on Oct 7, 2012
  1. Features

    mcdonc committed Oct 7, 2012
    ~~~~~~~~
    
    - Calling ``bind`` on a schema node e.g. ``cloned_node = somenode.bind(a=1,
      b=2)`` on a schema node now results in the cloned node having a
      ``bindings`` attribute of the value ``{'a':1, 'b':2}``.
    
    - It is no longer necessary to pass a ``typ`` argument to a SchemaNode
      constructor if the node class has a ``__schema_type__`` callable as a class
      attribute which, when called with no arguments, returns a schema type.
      This callable will be called to obtain the schema type if a ``typ`` is not
      supplied to the constructor.  The default ``SchemaNode`` object's
      ``__schema_type__`` callable raises a ``NotImplementedError`` when it is
      called.
    
    - SchemaNode now has a ``raise_invalid`` method which accepts a message and
      raises a colander.Invalid exception using ``self`` as the node and the
      message as its message.
    
    - It is now possible and advisable to subclass ``SchemaNode`` in order to
      create a bundle of default node behavior.  The subclass can define the
      following methods and attributes: ``preparer``, ``validator``, ``default``,
      ``missing``, ``name``, ``title``, ``description``, ``widget``, and
      ``after_bind``.  For example, the older, more imperative style that
      looked like this still works::
    
         from colander import SchemaNode
    
         ranged_int = colander.SchemaNode(
             validator=colander.Range(0, 10),
             default = 10,
             title='Ranged Int'
             )
    
      But you can alternately now do something like::
    
         from colander import SchemaNode
    
         class RangedIntSchemaNode(SchemaNode):
             validator = colander.range(0, 10)
             default = 10
             title = 'Ranged Int'
    
         ranged_int = RangedInt()
    
       Values that are expected to be callables can be methods of the schemanode
       subclass instead of plain attributes::
    
         from colander import SchemaNode
    
         class RangedIntSchemaNode(SchemaNode):
             default = 10
             title = 'Ranged Int'
    
             def validator(self, node, cstruct):
                if not 0 < cstruct < 10:
                    raise colander.Invalid(node, 'Must be between 0 and 10')
    
         ranged_int = RangedInt()
    
       When implementing a method value that expects ``node``, ``node`` must be
       provided in the call signature, even though ``node`` will almost always be
       the same as ``self``.  This is because Colander simply treats the method
       as another kind of callable, be it a method, or a function, or an instance
       that has a ``__call__`` method.  It doesn't care that it happens to be a
       method of ``self``, and it needs to support callables that are not
       methods, so it sends ``node`` in regardless.
    
       Normal inheritance rules apply to class attributes and methods defined in
       a schemanode subclass.  If your schemanode subclass inherits from another
       schemanode class, your schemanode subclass' methods and class attributes
       will override the superclass' methods and class attributes.
    
       Method values that need to be deferred for binding cannot currently be
       implemented as ``colander.deferred`` callables.  For example this will
       *not* work::
    
         from colander import SchemaNode
    
         class RangedIntSchemaNode(SchemaNode):
             default = 10
             title = 'Ranged Int'
    
             @colander.deferred
             def validator(self, node, kw):
                request = kw['request']
                def avalidator(node, cstruct):
                    if not 0 < cstruct < 10:
                        if request.user != 'admin':
                            raise colander.Invalid(node, 'Must be between 0 and 10')
                return avalidator
    
         ranged_int = RangedInt()
         bound_ranged_int = ranged_int.bind(request=request)
    
       This will result in::
    
            TypeError: avalidator() takes exactly 3 arguments (2 given)
    
       Instead of trying to defer methods via a decorator, you can instead use
       the ``bindings`` attribute of ``self`` to obtain access to the bind
       parameters within values that are methody::
    
         from colander import SchemaNode
    
         class RangedIntSchemaNode(SchemaNode):
             default = 10
             title = 'Ranged Int'
    
             def validator(self, node, cstruct):
                request = self.bindings['request']
                if not 0 < cstruct < 10:
                    if request.user != 'admin':
                        raise colander.Invalid(node, 'Must be between 0 and 10')
    
         ranged_int = RangedInt()
         bound_range_int = ranged_int.bind(request=request)
    
       You can use ``after_bind`` to set attributes of the schemanode that rely
       on binding variables, such as ``missing`` and ``default``::
    
         from colander import SchemaNode
    
         class RangedIntSchemaNode(SchemaNode):
             default = 10
             title = 'Ranged Int'
    
             def validator(self, node, cstruct):
                request = self.bindings['request']
                if not 0 < cstruct < 10:
                    if request.user != 'admin':
                        raise colander.Invalid(node, 'Must be between 0 and 10')
    
             def after_bind(self, node, kw):
                 self.request = kw['request']
                 self.default = self.request.user.id
    
       Non-method values can still be implemented as ``colander.deferred``
       however::
    
         from colander import SchemaNode
    
         def _missing(node, kw):
             request = kw['request']
             if request.user.name == 'admin':
                 return 10
              return 20
    
         class RangedIntSchemaNode(SchemaNode):
             default = 10
             title = 'Ranged Int'
             missing = colander.deferred(_missing)
    
         ranged_int = RangedInt()
    
       You can override the default values of a schemanode subclass in its
       constructor::
    
         from colander import SchemaNode
    
         class RangedIntSchemaNode(SchemaNode):
             default = 10
             title = 'Ranged Int'
             validator = colander.Range(0, 10)
    
         ranged_int = RangedInt(validator=colander.Range(0, 20))
    
       In the above example, the validation will be done on 0-20, not 0-10.
    
       If your schema node names conflict with schema value attribute names, you
       can work around it with the ``name`` argument to the schema node::
    
         from colander import SchemaNode, Schema
    
         class TitleNode(SchemaNode):
             validator = colander.range(0, 10)
             default = 10
    
         class SomeSchema(Schema):
             title = 'Some Schema'
             thisnamewontmatter = TitleNode(name='title')
    
    Backwards Incompatibilities
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    - Passing non-SchemaNode derivative instances as ``*children`` into a
      SchemaNode constructor is no longer supported.  Symptom: ``AttributeError:
      name`` when constructing a SchemaNode.
Commits on Oct 2, 2012
  1. - Work around a regression in Python 3.3 for ``colander.Decimal`` whe…

    mcdonc committed Oct 2, 2012
    …n it's
    
      used with a ``quant`` argument but without a ``rounding`` argument.
      See #66
    
    - Add Python 3.3 to tox configuration and use newer tox testing regime
      (setup.py dev).
    
    Closes #66
Commits on Sep 24, 2012
  1. prep for 0.9.9

    mcdonc committed Sep 24, 2012
  2. garden

    mcdonc committed Sep 24, 2012
  3. docs

    mcdonc committed Sep 24, 2012
  4. garden

    mcdonc committed Sep 24, 2012
  5. add tests for cstruct_children

    mcdonc committed Sep 24, 2012
  6. fix tuple cstruct_children bug

    mcdonc committed Sep 24, 2012
Commits on Sep 23, 2012
  1. add a warning

    mcdonc committed Sep 23, 2012
Commits on Sep 21, 2012
  1. Merge pull request #57 from rbu/update-german

    kiorky committed Sep 21, 2012
    Update german translation
Commits on Sep 18, 2012
  1. garden

    mcdonc committed Sep 18, 2012
  2. Removed all stray whitespace.

    jayd3e committed Sep 18, 2012
  3. Now check for the existence of an __iter__ function as opposed type(s…

    jayd3e committed Sep 18, 2012
    …elf.preparer) == list, as per mcdonc's request.
Commits on Aug 31, 2012
  1. restore py3 compat

    mcdonc committed Aug 31, 2012
  2. garden

    mcdonc committed Aug 31, 2012
  3. Merge pull request #55 from aatiis/patch-1

    mcdonc committed Aug 31, 2012
    fix typo in `SchemaNode` documentation
  4. Features

    mcdonc committed Aug 31, 2012
    ~~~~~~~~
    
    - Better class-based mapping schema inheritance model.
    
      * A node declared in a subclass of a mapping schema superclass now
        overrides any node with the same name inherited from any superclass.
        Previously, it just repeated and didn't override.
    
      * A ``schema_order`` attribute may be passed to SchemaNode constructor.
        This is an integer which defines the position in a parent node's child
        ordering.
    
      * ``colander.FIRST`` and ``colander.LAST`` constants are available for
        passing in as ``schema_order``.
    
    Backwards Incompatibilities
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    - The inheritance changes required a minor backwards incompatibility: calling
      ``__setitem__`` on a SchemaNode will no longer raise ``KeyError`` when
      attempting to set a subnode into a node that doesn't already have an
      existing subnode by that name.  Instead, the subnode will be appended to
      the child list.
    
    Documentation
    ~~~~~~~~~~~~~
    
    - A "Schema Inheritance" section was added to the Basics chapter
      documentation.
Commits on Aug 30, 2012
Commits on Aug 25, 2012
  1. - Create a ``colander.Money`` type that is a Decimal type with

    mcdonc committed Aug 25, 2012
      two-decimal-point precision rounded-up.
    
    - Allow ``quant`` and ``rounding`` args to ``colander.Decimal`` constructor.
Commits on Aug 15, 2012