コード例 #1
0
def _emit_snippet_class_doc_string(c):
    """Emits class doc string."""
    doc_string = "" if not c.doc_string else c.doc_string

    if doc_string:
        doc_string = "{0}{1}{2}".format(doc_string,
                                        gu.emit_line_return(2),
                                        gu.emit_indent())

    return "{0}{1}{2}".format(gu.emit_line_return(2),
                              gu.emit_indent(),
                              doc_string)
コード例 #2
0
        def get_code(ap):
            return "import {} as {}{}".format(
                pgu.get_package_module_name(ap, 'typeset'),
                ap.op_name,
                gu.emit_line_return())

            return code
コード例 #3
0
        def get_code(t):
            if isinstance(t, core.Class):
                code = _emit_snippet_class(t)
            else:
                code = _emit_snippet_enum(t)
            code += gu.emit_line_return(2)

            return code
コード例 #4
0
 def get_code(p):
     return "{0}{1}{2}# {3} ({4}){5}".format(
         gu.emit_indent(2),
         pgu.get_property_ctor(p),
         ''.ljust(50 - len(pgu.get_property_ctor(p))),
         pgu.get_type_doc_name(p.type),
         p.cardinality,
         gu.emit_line_return()
     )
コード例 #5
0
def _emit_snippet_decoding(prp, decoding, type_):
    """Emits a class property decoding."""
    tmpl = '{0}(\'{1}\', {2}, {3}, \'{4}\'),'
    return tmpl.format(
        gu.emit_line_return() + gu.emit_indent(2),
        prp.name,
        prp.is_collection,
        _get_decoding_function(prp, type_),
        '' if decoding is None else decoding)
コード例 #6
0
 def get_code(cnt):
     prp = c.get_property(cnt[0])
     if prp is not None:
         return '{0}self.{1} = {2}("{3}"){4}'.format(
             gu.emit_indent(2),
             cnt[0],
             pgu.get_type_functional_name(prp.type),
             cnt[1],
             gu.emit_line_return()
         )
コード例 #7
0
    def emit_descriptions():
        def get_code(m):
            code = gu.emit_line_return()
            code += gu.emit_indent(2)
            code += '"{}"'.format(m.doc_string)

            return code

        code = gu.emit(e.members, get_code, joiner=",", sort=False)
        code += gu.emit_line_return()
        code += gu.emit_indent(2)

        return code
コード例 #8
0
    def emit_members():
        def get_code(m):
            code = gu.emit_line_return()
            code += gu.emit_indent(2)
            code += '"{}"'.format(m.name)

            return code

        code = gu.emit(e.members, get_code, joiner=",", sort=False)
        code += gu.emit_line_return()
        code += gu.emit_indent(2)

        return code
コード例 #9
0
def _emit_snippet_decoding_fns(p):
    """Emits set of package class decodings."""
    code = ''
    for c in sorted(p.classes, key=lambda c: c.op_func_name):
        fn = _TEMPLATES[_TEMPLATE_DECODER_FUNCTION]
        fn = fn.replace('{class-name}', c.op_name)
        fn = fn.replace('{class-function-name}', c.op_func_name)
        fn = fn.replace('{package-name}', c.package.op_name)
        fn = fn.replace('{class-doc-name}', c.op_doc_string_name)
        fn = fn.replace('{class-decodings}', _emit_snippet_decodings(c))
        fn += gu.emit_line_return(3)
        code += fn

    return code
コード例 #10
0
def _emit_snippet_decoder_imports(o, p):
    """Emits set of package decoder imports."""
    imports = []

    def append_import(imp):
        if imp not in imports:
            imports.append(imp)

    # Set type decoding imports.
    for type_ in [t for t in p.external_types if t.is_class]:
        imp = 'from {0} import *'.format(
            pgu.get_package_module_name(type_.name_of_package, 'decoder'))
        append_import(imp)

    if len(imports) > 0:
        return reduce(add, map(lambda i : i + gu.emit_line_return(), sorted(imports)))
    else:
        return ''
コード例 #11
0
ファイル: utils.py プロジェクト: ES-DOC/esdoc-py-client
 def emit_import(p):
     return "import {} as {}{}".format(
         get_package_module_name(p, 'typeset'),
         p.op_name,
         gu.emit_line_return())
コード例 #12
0
        def get_code(m):
            code = gu.emit_line_return()
            code += gu.emit_indent(2)
            code += '"{}"'.format(m.doc_string)

            return code
コード例 #13
0
        def get_code(m):
            code = gu.emit_line_return()
            code += gu.emit_indent(2)
            code += '"{}"'.format(m.name)

            return code
コード例 #14
0
 def get_code(c):
     return "from {0} import {1}".format(
         pgu.get_package_module_name(c.package, 'decoder'),
         _get_decoder_function_name(c)) + gu.emit_line_return()