Changeset 4835 for waeup/branches
- Timestamp:
- 17 Jan 2010, 14:14:30 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-importers/src/waeup/utils/converters.txt
r4820 r4835 16 16 >>> import grok 17 17 >>> grok.testing.grok('waeup') 18 19 Constants 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 18 34 19 35 Adapters … … 35 51 :mod:`zope.schema` like :class:`zope.schema.TextLine`, 36 52 `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. 37 76 38 77 .. method:: fromString(string[, strict=True]) … … 46 85 data. 47 86 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 48 99 49 100 :class:`TextConverter` … … 187 238 .. method:: provides(waeup.interfaces.ISchemaTypeConverter) 188 239 189 .. method:: fromString(string[, strict= True])240 .. method:: fromString(string[, strict=False]) 190 241 191 242 Compute a value from the given `string`. Be aware that this … … 200 251 data. 201 252 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. 203 273 204 274 … … 521 591 522 592 Now we can get a converter for this field by explicitly creating a 523 :class:` TextConverter` instance:593 :class:`ChoiceConverter` instance: 524 594 525 595 >>> from waeup.utils.converters import ChoiceConverter
Note: See TracChangeset for help on using the changeset viewer.