def inline(self, field, context):
# type: (fields.Field, JitContext) -> Optional[str]
"""Generates a template for inlining string serialization.
For example, generates "unicode(value) if value is not None else None"
to serialize a string in Python 2.7
"""
if is_overridden(field._serialize, fields.String._serialize):
return None
result = text_type.__name__ + '({0})'
result += ' if {0} is not None else None'
if not context.is_serializing:
string_type_strings = ','.join([x.__name__ for x in string_types])
result = ('(' + result + ') if '
'(isinstance({0}, (' + string_type_strings +
')) or {0} is None) else dict()["error"]')
return result
评论列表
文章目录