当前位置: 首页>>代码示例>>Python>>正文


Python text_type.__name__方法代码示例

本文整理汇总了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 
开发者ID:lyft,项目名称:toasted-marshmallow,代码行数:19,代码来源:jit.py

示例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') 
开发者ID:lyft,项目名称:toasted-marshmallow,代码行数:41,代码来源:test_jit.py


注:本文中的six.text_type.__name__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。