Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_deserialize_null(self):
import colander
typ = self._makeOne()
node = DummySchemaNode(None)
result = typ.deserialize(node, colander.null)
self.assertEqual(result, colander.null)
def deserialize(field, pstruct):
if pstruct is colander.null:
return colander.null
return [item.strip() for item in pstruct.split(",") if item]
def deserialize(self, cstruct=colander.null):
"""Preprocess received data to carefully merge defaults.
"""
if cstruct is not colander.null:
defaults = cstruct.get("defaults")
requests = cstruct.get("requests")
if isinstance(defaults, dict) and isinstance(requests, list):
for request in requests:
if isinstance(request, dict):
merge_dicts(request, defaults)
return super().deserialize(cstruct)
job_impressions=colander.null,
job_media_sheets=colander.null,
job_priority=colander.null,
job_hold_until=colander.null,
multiple_document_handling=colander.null,
copies=colander.null,
finishings=colander.null,
page_ranges=colander.null,
sides=colander.null,
number_up=colander.null,
orientation_requested=colander.null,
printer_resolution=colander.null,
print_quality=colander.null,
auth_info=colander.null,
job_billing=colander.null,
job_sheets=colander.null,
media=colander.null):
kw = {'operation_attributes_tag':
{'printer_uri': printer_uri,
'job_name': job_name,
'ipp_attribute_fidelity': ipp_attribute_fidelity,
'job_k_octets': job_k_octets,
'job_impressions': job_impressions,
'job_media_sheets': job_media_sheets},
'job_attributes_tag':
{'job_priority': job_priority,
'job_hold_until': job_hold_until,
'job_sheets': job_sheets,
'multiple_document_handling': multiple_document_handling,
'copies': copies,
'finishings': finishings,
'page_ranges': page_ranges,
a value, but all accept `colander.null`)
all values for server_default should result in 'drop'
for Colander missing
autoincrement results in drop
"""
if isinstance(column.default, ColumnDefault):
if column.default.is_callable:
kwargs["missing"] = drop
elif column.default.is_clause_element: # SQL expression
kwargs["missing"] = drop
elif column.default.is_scalar:
kwargs["missing"] = column.default.arg
elif column.nullable:
kwargs["missing"] = colander.null
elif isinstance(column.server_default, FetchedValue):
kwargs["missing"] = drop # value generated by SQLA backend
elif (hasattr(column.table, "_autoincrement_column") and id(column.table._autoincrement_column) == id(column)):
# this column is the autoincrement column, so we can drop
# it if it's missing and let the database generate it
kwargs["missing"] = drop
kwargs.update(type_overrides_kwargs)
kwargs.update(typedecorator_overrides)
kwargs.update(declarative_overrides)
kwargs.update(overrides)
return colander.SchemaNode(type_, *children, **kwargs)
@pyipptool_coroutine
def send_document(self,
job_uri=colander.null,
printer_uri=colander.null,
job_id=colander.null,
requesting_user_name=None,
document_name=colander.null,
compression=colander.null,
document_format='application/pdf',
document_natural_language=colander.null,
last_document=True,
document_content=None,
):
"""
:param document_content: Binary Content or Named File
"""
delete = False
filename, delete = _get_filename_for_content(document_content)
kw = {'operation_attributes_tag':
{'job_uri': job_uri,
'printer_uri': printer_uri,
'job_id': job_id,
'requesting_user_name': requesting_user_name,
def get_col_default_value(self, col, obj):
value = None
col_type = self.get_column_type(col)
if obj and hasattr(col, 'instance_name'):
value = getattr(obj, col.instance_name)
elif obj and hasattr(col, 'name'):
try:
value = getattr(obj, col.name, colander.null)
except UnicodeEncodeError:
value = colander.null
if value is None:
value = colander.null
elif col_type == ChoiceType:
value = value[0]
if col_type == sa_types.Boolean:
value = bool(value)
return value
def serialize(self, node, appstruct):
if appstruct is null: # colander.null
return null
appstruct = zip(appstruct['time'].astype(object), appstruct['value'])
return super(DatetimeValue1dArray, self).serialize(node, appstruct)
def deserialize(self, node, cstruct):
if not cstruct:
return colander.null
try:
r = urlparse.urlparse(cstruct)
# require absolute urls
if not r.scheme or not r.netloc or not r.hostname:
raise Exception()
# poke at stuff to make sure the parts are valid:
r.port, r.username, r.password
return r
except Exception, e:
raise colander.Invalid(node,
_('"${val}" is not a URL (${err})',
mapping={'val':cstruct, 'err': e})
)
def widget(self, kw: dict):
widget = DateTimeInputWidget()
schema = widget._pstruct_schema
schema['date_submit'].missing = null # Fix readonly template bug
schema['time_submit'].missing = null
return widget