• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python yutil.indent函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中yutil.indent函数的典型用法代码示例。如果您正苦于以下问题:Python indent函数的具体用法?Python indent怎么用?Python indent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了indent函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _py_method_update

        def _py_method_update(self):
            if len(self.fields) == 0:
                return {}

            doc = indent(" " * 4, "\n".join(field.py_sphinx_doc() for field in self.fields))
            name = self.py_name()
            other_name = decamelize(self.py_name())
            object_updates = "\n".join(
                indent(
                    " " * 8,
                    (
                        "self.%s(%s.%s)" % (field.py_setter_name(), other_name, field.py_getter_call())
                        for field in self.fields
                    ),
                )
            )
            return {
                "update": """\
def update(self, %(other_name)s):
    '''
%(doc)s
    '''

    if isinstance(%(other_name)s, %(name)s):
%(object_updates)s
    elif isinstance(%(other_name)s, dict):
        for key, value in %(other_name)s.iteritems():
            getattr(self, 'set_' + key)(value)
    else:
        raise TypeError(%(other_name)s)
    return self
"""
                % locals()
            }
开发者ID:minorg,项目名称:thryft,代码行数:34,代码来源:_py_compound_type.py


示例2: _py_constructor

    def _py_constructor(self):
        assert len(self.fields) > 0
        doc = indent(" " * 4, "\n".join(field.py_sphinx_doc() for field in self.fields))
        required_parameters = []
        optional_parameters = []
        for field in self.fields:
            parameter = field.py_parameter()
            if "=" in parameter:
                optional_parameters.append(parameter)
            else:
                required_parameters.append(parameter)
        parameters = "\n".join(indent(" " * 4, required_parameters + optional_parameters))
        initializers = "\n\n".join(indent(" " * 4, (field.py_initializer() for field in self.fields)))
        return (
            """\
def __init__(
    self,
%(parameters)s
):
    '''
%(doc)s
    '''

%(initializers)s
"""
            % locals()
        )
开发者ID:minorg,项目名称:thryft,代码行数:27,代码来源:_py_compound_type.py


示例3: __repr__

    def __repr__(self):
        extends = self.java_extends()
        if extends is None:
            extends = ''
        else:
            extends = ' extends ' + extends

        javadoc = self.java_doc()
        name = self.java_name()

        sections = []

        message_types = []
        for function in self.functions:
            message_types.extend(function.java_message_types())
        if len(message_types) > 0:
            message_types = \
                "\n\n".join(indent(' ' * 4,
                    (repr(message_type)
                     for message_type in message_types)
                ))
            sections.append("""\
public static class Messages {
%(message_types)s
}""" % locals())

        sections.append("\n\n".join(repr(function) for function in self.functions))

        sections = lpad("\n", "\n\n".join(indent(' ' * 4, sections)))

        return """\
%(javadoc)spublic interface %(name)s%(extends)s {%(sections)s
}""" % locals()
开发者ID:financeCoding,项目名称:thryft,代码行数:33,代码来源:java_service.py


示例4: js_write_protocol

    def js_write_protocol(self, value, depth=0):
        key_ttype_id = self.key_type.thrift_ttype_id()
        key_write_protocol = \
            indent(' ' * 4,
                self.key_type.js_write_protocol(
                    "__key%(depth)u" % locals(),
                    depth=depth + 1
                )
            )
        value_ttype_id = self.value_type.thrift_ttype_id()
        value_write_protocol = \
            indent(' ' * 4,
                self.value_type.js_write_protocol(
                    "__map%(depth)u[__key%(depth)u]" % locals(),
                    depth=depth + 1
                )
            )
        return """\
var __map%(depth)u = %(value)s;
var __mapSize%(depth)u = 0;
for (var __key%(depth)u in __map%(depth)u) {
    __mapSize%(depth)u++;
}
oprot.writeMapBegin(%(key_ttype_id)u, %(value_ttype_id)u, __mapSize%(depth)u);
for (var __key%(depth)u in __map%(depth)u) {
%(key_write_protocol)s
%(value_write_protocol)s
}
oprot.writeMapEnd();""" % locals()
开发者ID:financeCoding,项目名称:thryft,代码行数:29,代码来源:js_map_type.py


示例5: js_validation

    def js_validation(self):
        try:
            validation = self.annotations['validation'].copy()
        except KeyError:
            validation = {}
        validation['required'] = self.required
        name = self.js_name()
        qname = self.js_qname()
        validation.update(self.type.js_validation(depth=0, value='value', value_name=qname))
        type_validation = validation.pop('type')
        if not self.required:
            type_validation = indent(' ' * 4, type_validation)
            type_validation = """\
if (typeof attr !== "undefined" && attr !== "null") {
%(type_validation)s
}
""" % locals()
        type_validation = indent(' ' * 8, type_validation)
        validation = json.dumps(validation).lstrip('{').rstrip('}')
        return """\
%(name)s: {
    "fn": function(value, attr, computedState) {
%(type_validation)s
    },
    %(validation)s
}""" % locals()
开发者ID:financeCoding,项目名称:thryft,代码行数:26,代码来源:js_field.py


示例6: _java_method_write

    def _java_method_write(self):
        case_ttype_void = 'case VOID:'
        if len(self.fields) == 1:
            field = self.fields[0]
            from thryft.generators.java._java_container_type import _JavaContainerType
            from thryft.generators.java.java_struct_type import JavaStructType
            if isinstance(field.type, _JavaContainerType) or isinstance(field.type, JavaStructType):
                field_value_java_write_protocol = \
                    indent(' ' * 12, field.type.java_write_protocol(field.java_getter_name() + (field.required and '()' or '().get()'), depth=0))
                field_thrift_ttype_name = field.type.thrift_ttype_name()
                case_ttype_void = """\
%(case_ttype_void)s {
%(field_value_java_write_protocol)s
            break;
        }
""" % locals()

        field_count = len(self.fields)

        field_write_protocols = \
            lpad("\n\n", "\n\n".join(indent(' ' * 12,
                (field.java_write_protocol(depth=0, write_field=True)
                 for field in self.fields)
            )))

        field_value_write_protocols = \
            pad("\n\n", "\n\n".join(indent(' ' * 12,
                (field.java_write_protocol(depth=0, write_field=False)
                 for field in self.fields)
            )), "\n")

        name = self.java_name()
        return {'write': """\
@Override
public void write(final org.thryft.protocol.OutputProtocol oprot) throws org.thryft.protocol.OutputProtocolException {
    write(oprot, org.thryft.protocol.Type.STRUCT);
}

public void write(final org.thryft.protocol.OutputProtocol oprot, final org.thryft.protocol.Type writeAsType) throws org.thryft.protocol.OutputProtocolException {
    switch (writeAsType) {
        %(case_ttype_void)s
        case LIST:
            oprot.writeListBegin(org.thryft.protocol.Type.VOID, %(field_count)u);%(field_value_write_protocols)s
            oprot.writeListEnd();
            break;

        case STRUCT:
        default:
            oprot.writeStructBegin(\"%(name)s\");%(field_write_protocols)s

            oprot.writeFieldStop();

            oprot.writeStructEnd();
            break;
    }
}
""" % locals()}
开发者ID:financeCoding,项目名称:thryft,代码行数:57,代码来源:_java_compound_type.py


示例7: __repr__

    def __repr__(self):
        extends = ', '.join(self._py_extends())
        sections = []
        sections.append(indent(' ' * 4, repr(self._PyBuilder(self))))
        sections.append(indent(' ' * 4, "\n".join(self._py_methods())))
        sections = "\n\n".join(sections)
        name = self.py_name()
        return """\
class %(name)s(%(extends)s):
%(sections)s""" % locals()
开发者ID:financeCoding,项目名称:thryft,代码行数:10,代码来源:_py_compound_type.py


示例8: _cpp_method_write

    def _cpp_method_write(self):
        case_ttype_void = 'case ::thryft::protocol::Type::VOID_:'
        if len(self.fields) == 1:
            field = self.fields[0]
            from thryft.generators.cpp._cpp_container_type import _CppContainerType
            from thryft.generators.cpp.cpp_struct_type import CppStructType
            if isinstance(field.type, _CppContainerType) or isinstance(field.type, CppStructType):
                field_value_cpp_write_protocol = \
                    indent(' ' * 4, field.type.cpp_write_protocol(field.cpp_getter_name() + (field.required and '()' or '().get()')))
                case_ttype_void = """\
%(case_ttype_void)s
%(field_value_cpp_write_protocol)s
    break;
""" % locals()

        field_count = len(self.fields)

        field_write_protocols = \
            lpad("\n\n", "\n\n".join(indent(' ' * 4,
                (field.cpp_write_protocol(write_field=True)
                 for field in self.fields)
            )))

        field_value_write_protocols = \
            pad("\n\n", "\n\n".join(indent(' ' * 4,
                (field.cpp_write_protocol(write_field=False)
                 for field in self.fields)
            )), "\n")

        name = self.cpp_name()

        return {'write': """\
void write(::thryft::protocol::OutputProtocol& oprot) const {
  write(oprot, ::thryft::protocol::Type::STRUCT);
}

void write(::thryft::protocol::OutputProtocol& oprot, ::thryft::protocol::Type as_type) const {
  switch (as_type) {
  %(case_ttype_void)s
  case ::thryft::protocol::Type::LIST:
    oprot.write_list_begin(::thryft::protocol::Type::VOID_, %(field_count)u);%(field_value_write_protocols)s
    oprot.write_list_end();
    break;

  case ::thryft::protocol::Type::STRUCT:
  default:
    oprot.write_struct_begin();%(field_write_protocols)s

    oprot.write_field_stop();

    oprot.write_struct_end();
    break;
  }
}
""" % locals()}
开发者ID:financeCoding,项目名称:thryft,代码行数:55,代码来源:_cpp_compound_type.py


示例9: __repr__

        def __repr__(self):
            name = self.java_name()
            methods = self._java_methods()
            sections = []
            sections.append("\n\n".join(indent(' ' * 4,
                self._java_constructors() + [methods[key] for key in sorted(methods.iterkeys())]
            )))
            sections.append("\n".join(indent(' ' * 4, self._java_member_declarations())))
            sections = lpad("\n", "\n\n".join(section for section in sections if len(section) > 0))
            return """\
public static class Builder {%(sections)s
}""" % locals()
开发者ID:financeCoding,项目名称:thryft,代码行数:12,代码来源:_java_compound_type.py


示例10: __repr__

        def __repr__(self):
            annotations = lpad("\n", "\n".join(self.java_annotations()))
            name = self.java_name()
            public_parameters = \
                ', '.join(parameter.java_parameter(final=True) for parameter in self.parameters)
            public_parameter_names = ', '.join(parameter.java_name() for parameter in self.parameters)
            parameter_validations = []
            for parameter in self.parameters:
                parameter_validation = parameter.java_validation()
                if parameter_validation != parameter.java_name():
                    parameter_validations.append(parameter_validation + ';')
            if len(parameter_validations) > 0:
                parameter_validations = \
                    "\n".join(indent(' ' * 4, parameter_validations))
                validate_method_name = '_validate' + upper_camelize(self.name) + 'Parameters'
                validate_method = lpad("\n\n", """\
protected void %(validate_method_name)s(%(public_parameters)s) {
%(parameter_validations)s
}""" % locals())
                validate_method_call = lpad("\n", indent(' ' * 4, "%s(%s);" % (validate_method_name, public_parameter_names)))
            else:
                validate_method = validate_method_call = ''
            protected_parameters = [parameter.java_parameter(final=True)
                                    for parameter in self.parameters]
            protected_parameter_names = [parameter.java_name()
                                         for parameter in self.parameters]
            if self.parent.parent.parent._include_current_user:
                protected_parameters.insert(0, 'org.apache.shiro.subject.Subject currentUser')
                protected_parameter_names.insert(0, 'org.apache.shiro.SecurityUtils.getSubject()')
            protected_delegation = \
                "_%s(%s)" % (name, ', '.join(protected_parameter_names))
            protected_parameters = ', '.join(protected_parameters)
            if self.return_field is not None:
                protected_delegation = 'return ' + self.return_field.java_validation(value=protected_delegation)
                return_type_name = self.return_field.type.java_declaration_name()
            else:
                return_type_name = 'void'
            throws = \
                lpad(
                    ' throws ',
                    ', '.join(field.type.java_declaration_name()
                               for field in self.throws)
                )

            return """\
@Override%(annotations)s
public %(return_type_name)s %(name)s(%(public_parameters)s)%(throws)s {%(validate_method_call)s
    %(protected_delegation)s;
}%(validate_method)s

protected abstract %(return_type_name)s _%(name)s(%(protected_parameters)s)%(throws)s;
""" % locals()
开发者ID:financeCoding,项目名称:thryft,代码行数:52,代码来源:abstract_service_java_generator.py


示例11: java_read_protocol

    def java_read_protocol(self):
        element_read_protocol = self.element_type.java_read_protocol()
        add_element = "sequenceBuilder.add(%(element_read_protocol)s);" % locals()
        element_read_protocol_throws = (
            self.element_type.java_read_protocol_throws_checked()
            + self.element_type.java_read_protocol_throws_unchecked()
        )
        if len(element_read_protocol_throws) > 0:
            add_element = indent(" " * 4, add_element)
            add_element = """\
try {
%s
}%s
""" % (
                add_element,
                "".join(
                    """\
 catch (final %(exception_type_name)s e) {
     throw new org.thryft.protocol.InputProtocolException(e);
}"""
                    % locals()
                    for exception_type_name in element_read_protocol_throws
                ),
            )
        add_element = indent(" " * 16, add_element)

        element_type_name = self.element_type.java_boxed_qname()
        interface_simple_name = self._java_interface_simple_name()

        return (
            """\
(new com.google.common.base.Function<org.thryft.protocol.InputProtocol, com.google.common.collect.Immutable%(interface_simple_name)s<%(element_type_name)s>>() {
    @Override
    public com.google.common.collect.Immutable%(interface_simple_name)s<%(element_type_name)s> apply(final org.thryft.protocol.InputProtocol iprot) {
        try {
            final org.thryft.protocol.%(interface_simple_name)sBegin sequenceBegin = iprot.read%(interface_simple_name)sBegin();
            final com.google.common.collect.Immutable%(interface_simple_name)s.Builder<%(element_type_name)s> sequenceBuilder = com.google.common.collect.Immutable%(interface_simple_name)s.builder();
            for (int elementI = 0; elementI < sequenceBegin.getSize(); elementI++) {
%(add_element)s
            }
            iprot.read%(interface_simple_name)sEnd();
            return sequenceBuilder.build();
        } catch (final org.thryft.protocol.InputProtocolException e) {
            throw new org.thryft.protocol.UncheckedInputProtocolException(e);
        }
    }
}).apply(iprot)"""
            % locals()
        )
开发者ID:minorg,项目名称:thryft,代码行数:49,代码来源:_java_sequence_type.py


示例12: _java_method_do_post

        def _java_method_do_post(self):
            read_http_servlet_request_body = indent(' ' * 4, self._java_read_http_servlet_request_body())
            function_dispatches = []
            if len(self.functions) == 0:
                function_dispatches = """\
__doPostError(httpServletRequest, httpServletResponse, new org.thryft.protocol.JsonRpcErrorResponse(-32601, String.format("the method '%s' does not exist / is not available", messageBegin.getName())), messageBegin.getId());
return;
"""
            else:
                function_dispatches = \
                    indent(' ' * 8, ' else '.join(
                        ["""\
if (messageBegin.getName().equals("%s")) {
    __doPost%s(httpServletRequest, httpServletResponse, iprot, messageBegin.getId());
}""" % (function.name, upper_camelize(function.name))
                                   for function in self.functions
                        ] + ['''\
{
    __doPostError(httpServletRequest, httpServletResponse, new org.thryft.protocol.JsonRpcErrorResponse(-32601, String.format("the method '%s' does not exist / is not available", messageBegin.getName())), messageBegin.getId());
    return;
}''']
                    ))
            return """\
@Override
protected void doPost(final javax.servlet.http.HttpServletRequest httpServletRequest, final javax.servlet.http.HttpServletResponse httpServletResponse) throws java.io.IOException, javax.servlet.ServletException {
%(read_http_servlet_request_body)s

    org.thryft.protocol.MessageBegin messageBegin = null;
    try {
        final org.thryft.protocol.JsonRpcInputProtocol iprot;
        try {
            iprot = new org.thryft.protocol.JsonRpcInputProtocol(new org.thryft.protocol.JacksonJsonInputProtocol(httpServletRequestBody));
            messageBegin = iprot.readMessageBegin();
        } catch (final org.thryft.protocol.JsonRpcInputProtocolException e) {
            throw e;
        } catch (final org.thryft.protocol.InputProtocolException e) {
            throw new org.thryft.protocol.JsonRpcInputProtocolException(e, -32600);
        }
        if (messageBegin.getType() != org.thryft.protocol.MessageType.CALL) {
            throw new org.thryft.protocol.JsonRpcInputProtocolException(-32600, "expected request");
        }
%(function_dispatches)s
    } catch (final org.thryft.protocol.JsonRpcInputProtocolException e) {
        __doPostError(httpServletRequest, httpServletResponse, new org.thryft.protocol.JsonRpcErrorResponse(e), messageBegin != null ? messageBegin.getId() : null);
        return;
    }

}
""" % locals()
开发者ID:financeCoding,项目名称:thryft,代码行数:49,代码来源:json_rpc_servlet_java_generator.py


示例13: js_validation

    def js_validation(self, value, value_name, depth=0):
        if isinstance(self.element_type, _JsCompoundType):
            element_type_qname = self.element_type.js_qname()
            return {'type': """\
if (!(%(value)s instanceof Backbone.Collection)) {
    return "expected %(value_name)s to be a Backbone.Collection";
}
if (%(value)s.model !== %(element_type_qname)s) {
    return "expected %(value_name)s to be a Backbone.Collection with model=%(element_type_qname)s";
}
if (!%(value)s.isValid(true)) {
    return %(value)s.validationError;
}""" % locals()}
        else:
            element_validate = \
                indent(' ' * 4,
                    self.element_type.js_validation(
                        depth=depth + 1,
                        value=value + "[__i%(depth)u]" % locals(),
                        value_name=value_name + "[i]" % locals()
                    )['type']
                )
            return {'type': """\
if (!Array.isArray(%(value)s)) {
    return "expected %(value_name)s to be an Array";
}
for (var __i%(depth)u = 0; __i%(depth)u < %(value)s.length; __i%(depth)u++) {
%(element_validate)s
}""" % locals()}
开发者ID:financeCoding,项目名称:thryft,代码行数:29,代码来源:_js_sequence_type.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python yutil.lpad函数代码示例发布时间:2022-05-26
下一篇:
Python yumexbase._函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap