Changeset 4835 for waeup/branches


Ignore:
Timestamp:
17 Jan 2010, 14:14:30 (15 years ago)
Author:
uli
Message:

Update/fix converter docs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-importers/src/waeup/utils/converters.txt

    r4820 r4835  
    1616    >>> import grok
    1717    >>> grok.testing.grok('waeup')
     18
     19Constants
     20=========
     21
     22.. attribute:: NONE_STRING_VALUE
     23
     24   This value determines, which string represents
     25   'non-values'. Current setting is:
     26
     27      >>> from waeup.utils.converters import NONE_STRING_VALUE
     28      >>> NONE_STRING_VALUE
     29      ''
     30
     31   If this value is found during conversion from strings, the value to
     32   set will become ``None``.
     33
    1834
    1935Adapters
     
    3551   :mod:`zope.schema` like :class:`zope.schema.TextLine`,
    3652   `zope.schema.Choice` or similar.
     53
     54   .. method:: provides(waeup.interfaces.ISchemaTypeConverter)
     55
     56   .. method:: _convertValueFromString(string)
     57
     58       Raises :exc:`NotImplementedError`.
     59
     60       Called by :meth:`fromString()` to convert a given string to a
     61       value appropriate for the applied field type. The string might
     62       be ``None`` or ``missing_value`` from field definition.
     63
     64       Override this method in derived classes to get a working
     65       converter.
     66
     67   .. method:: _convertValueToString(value)
     68
     69       Raises :exc:`NotImplementedError`.
     70
     71       Called by :meth:`toString()` to convert a given value to a
     72       string suitable to be stored for instance in CSV files.
     73
     74       Override this method in derived classes to get a working
     75       converter.
    3776
    3877   .. method:: fromString(string[, strict=True])
     
    4685       data.
    4786
     87   .. method:: toString(value[, strict=True])
     88
     89       Generate a string from ``value``, suitable to be stored in CSV
     90       files or similar. This method does preliminary checks, handles
     91       defaults and ``missing_value`` stuff and then calls
     92       :meth:`_convertValueToString(value)` to do the actual
     93       conversion.
     94
     95       Use `strict` to enable/disable validations of transformed
     96       data.
     97       
     98
    4899
    49100:class:`TextConverter`
     
    187238   .. method:: provides(waeup.interfaces.ISchemaTypeConverter)
    188239
    189    .. method:: fromString(string[, strict=True])
     240   .. method:: fromString(string[, strict=False])
    190241
    191242       Compute a value from the given `string`. Be aware that this
     
    200251       data.
    201252
    202 
     253       As an invalid value will result in a `KeyError`, additional
     254       validation checks are disabled with this converter. This speeds
     255       up things as expensive lookups are avoided.
     256
     257   .. method:: toString(value[, strict=False])
     258
     259       Return `value` as string or ``None``.
     260
     261       If `value` is ``None`` (or field's `missing_value`), ``None``
     262       is returned.
     263
     264       If the value is not valid for the applied field (i.e. not an
     265       integer or `missing_value`) an exception
     266       might be raised.
     267
     268       Use `strict` to enable/disable validations of input data.
     269
     270       As an invalid value will result in a `ValueError`, additional
     271       validation checks are disabled with this converter. This speeds
     272       up things as expensive lookups are avoided.
    203273
    204274
     
    521591
    522592Now we can get a converter for this field by explicitly creating a
    523 :class:`TextConverter` instance:
     593:class:`ChoiceConverter` instance:
    524594
    525595    >>> from waeup.utils.converters import ChoiceConverter
Note: See TracChangeset for help on using the changeset viewer.