|
Lines 149-154
class Sanitizer(object):
Link Here
|
| 149 |
:param bool may_change_value: if the process of sanitizing is allowed |
149 |
:param bool may_change_value: if the process of sanitizing is allowed |
| 150 |
to alter *request.options*. If not, the sanitizer can still be used |
150 |
to alter *request.options*. If not, the sanitizer can still be used |
| 151 |
for validation. Default: *True* |
151 |
for validation. Default: *True* |
|
|
152 |
:param bool allow_none: if None is allowed and not further validated. |
| 153 |
Default: *False* |
| 152 |
''' |
154 |
''' |
| 153 |
|
155 |
|
| 154 |
def __init__(self, **kwargs): |
156 |
def __init__(self, **kwargs): |
|
Lines 156-161
def __init__(self, **kwargs):
Link Here
|
| 156 |
self.required = kwargs.get('required', False) |
158 |
self.required = kwargs.get('required', False) |
| 157 |
self.default = kwargs.get('default', None) |
159 |
self.default = kwargs.get('default', None) |
| 158 |
self.may_change_value = kwargs.get('may_change_value', True) |
160 |
self.may_change_value = kwargs.get('may_change_value', True) |
|
|
161 |
self.allow_none = kwargs.get('allow_none', False) |
| 159 |
|
162 |
|
| 160 |
def sanitize(self, name, options): |
163 |
def sanitize(self, name, options): |
| 161 |
'''Sanitize function. Internally calls _sanitize with the |
164 |
'''Sanitize function. Internally calls _sanitize with the |
|
Lines 173-178
def sanitize(self, name, options):
Link Here
|
| 173 |
else: |
176 |
else: |
| 174 |
return self.default |
177 |
return self.default |
| 175 |
value = options[name] |
178 |
value = options[name] |
|
|
179 |
if value is None and self.allow_none: |
| 180 |
return value |
| 176 |
if self.further_arguments: |
181 |
if self.further_arguments: |
| 177 |
further_arguments = dict([(field, options.get(field)) for field in self.further_arguments]) |
182 |
further_arguments = dict([(field, options.get(field)) for field in self.further_arguments]) |
| 178 |
else: |
183 |
else: |