UsageΒΆ
Extras and utilities for Marshmallow.
Currently, this library contains a couple of extra fields that helps with sanitizing data as shown in the following example:
>>> from marshmallow_utils import fields
>>> from marshmallow import Schema
>>> class MySchema(Schema):
... trim = fields.TrimmedString()
... html = fields.SanitizedHTML()
... text = fields.SanitizedUnicode()
... isodate = fields.ISODateString()
...
>>> data = MySchema().load({
... 'trim': ' whitespace ',
... 'html': '<script>evil()</script>',
... 'text': 'PDF copy/paste\u200b\u000b\u001b\u0018 ',
... 'isodate': '1999-10-27',
... })
>>> data['trim']
'whitespace'
>>> data['html']
'evil()'
>>> data['text']
'PDF copy/paste'
>>> data['isodate']
'1999-10-27'
Fields:
SanitizedUnicode
: Integrates the ftfy for fixing broken unicode text.SanitizedHTML
: Integrates the bleach for HTML sanitization.ISODateString
: Integrates the arrow for date parsing.