本文整理匯總了Python中six.text_type.__name__方法的典型用法代碼示例。如果您正苦於以下問題:Python text_type.__name__方法的具體用法?Python text_type.__name__怎麽用?Python text_type.__name__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類six.text_type
的用法示例。
在下文中一共展示了text_type.__name__方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: inline
# 需要導入模塊: from six import text_type [as 別名]
# 或者: from six.text_type import __name__ [as 別名]
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
示例2: test_generate_marshall_method_body
# 需要導入模塊: from six import text_type [as 別名]
# 或者: from six.text_type import __name__ [as 別名]
def test_generate_marshall_method_body(schema):
expected_start = '''\
def InstanceSerializer(obj):
res = dict_class()
'''
raz_assignment = ('value = None; '
'value = value() if callable(value) else value; '
'res["raz"] = _field_raz__serialize(value, "raz", obj)')
foo_assignment = (
'if "@#" in obj:\n'
' value = obj["@#"]; '
'value = value() if callable(value) else value; '
'value = int(value) if value is not None else None; '
'res["foo"] = value')
bar_assignment = (
'value = obj.bar; '
'value = value() if callable(value) else value; '
'value = {text_type}(value) if value is not None else None; '
'res["bar"] = value').format(text_type=text_type.__name__)
blargh_assignment = (
'value = obj.blargh; '
'value = value() if callable(value) else value; '
'value = ((value in __blargh_truthy) or '
'(False if value in __blargh_falsy else dict()["error"])) '
'if value is not None else None; '
'res["blargh"] = value')
context = JitContext()
result = str(generate_transform_method_body(schema,
InstanceSerializer(),
context))
assert result.startswith(expected_start)
assert raz_assignment in result
assert foo_assignment in result
assert bar_assignment in result
assert blargh_assignment in result
assert 'meh' not in result
assert result.endswith('return res')