Beispiel #1
0
        def emit_code(code, c):
            code += "{0}.type_info = ({1})".format(
                c.op_full_name,
                gu.emit_line_return() + emit_type_attribute_info(c))
            code += gu.emit_line_return(2)

            return code
Beispiel #2
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)
Beispiel #3
0
        def emit_code(code, t):
            code += "{0}\'{1}\',{2}".format(
                gu.emit_indent(),
                t.op_name,
                gu.emit_line_return())

            return code
Beispiel #4
0
        def emit_code(code, c):
            code += gu.emit_indent()
            code +=  c.op_full_name
            code += ','
            code += gu.emit_line_return()

            return code
Beispiel #5
0
        def emit_code_2(code, p):
            code += "import {0} as {1}".format(
                pgu.get_package_module_name(p, 'typeset'),
                p.op_name)
            code += gu.emit_line_return()

            return code
Beispiel #6
0
        def emit_code(code, p):
            code += "import {0} as {1}".format(
                pgu.get_package_module_name(p, 'typeset'),
                p.op_name)
            code += gu.emit_line_return()

            return code
Beispiel #7
0
        def emit_code(code, c):
            code += "{0}.type_key = '{1}.{2}.{0}'".format(
                c.op_full_name,
                o.op_name,
                o.op_version)
            code += gu.emit_line_return()

            return code
Beispiel #8
0
        def emit_code(code, t):
            if isinstance(t, ontology.Class):
                code += _emit_snippet_class(t)
            else:
                code += _emit_snippet_enum(t)
            code += gu.emit_line_return(2)

            return code
Beispiel #9
0
    def emit_code(code, p):
        code += "{0}{1}{2}# {3}{4}".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),
            gu.emit_line_return()
        )

        return code
Beispiel #10
0
        def emit_code(code, p):
            code += gu.emit_indent()
            code += "('{0}', {1}, {2}, {3}),".format(
                pgu.get_property_name(p),
                pgu.get_type_functional_name(p.type, True),
                p.is_required,
                p.is_iterative)
            code += gu.emit_line_return()

            return code
Beispiel #11
0
    def emit_code(code, cnt):
        prp = c.get_property(cnt[0])
        if prp is not None:
            code += '{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()
            )

        return code
Beispiel #12
0
def _emit_snippet_decoding_fns(p):
    """Emits set of package class decodings."""
    code = ''
    for cls in p.classes:
        fn = _templates[_TEMPLATE_DECODER_FUNCTION]
        fn = fn.replace('{class-name}', cls.op_name)
        fn = fn.replace('{class-function-name}', pgu.get_class_functional_name(cls))
        fn = fn.replace('{package-name}', cls.package.op_name)
        fn = fn.replace('{class-doc-name}', pgu.get_class_doc_string_name(cls))
        fn = fn.replace('{class-decodings}', _emit_snippet_decodings(cls))
        fn += gu.emit_line_return(3)
        code += fn

    return code
Beispiel #13
0
def _emit_snippet_decoding_fns(p):
    """Emits set of package class decodings."""
    code = ''
    for cls in p.classes:
        fn = _templates[_TEMPLATE_DECODER_FUNCTION]
        fn = fn.replace('{class-name}', cls.op_name)
        fn = fn.replace('{class-function-name}',
                        pgu.get_class_functional_name(cls))
        fn = fn.replace('{package-name}', cls.package.op_name)
        fn = fn.replace('{class-doc-name}', pgu.get_class_doc_string_name(cls))
        fn = fn.replace('{class-decodings}', _emit_snippet_decodings(cls))
        fn += gu.emit_line_return(3)
        code += fn

    return code
Beispiel #14
0
def _emit_snippet_decoding(prp, decoding, type):
    """Emits a class property decoding."""
    def get_decoding_function():
        # ... simple/enum types - return type functional name
        #     (is directly mapped to a convertor function).
        if prp.type.is_simple or prp.type.is_enum:
            return '\'{0}\''.format(pgu.get_type_functional_name(prp.type))
        # ... complex classes - return class functional name.
        elif prp.type.is_class:
            type_name = prp.type.name if type is None else type
            return _get_decoder_function_name(type_name)

    tmpl = '{0}(\'{1}\', {2}, {3}, \'{4}\'),'
    return tmpl.format(gu.emit_line_return() + gu.emit_indent(2), prp.name,
                       prp.is_iterative, get_decoding_function(),
                       '' if decoding is None else decoding)
Beispiel #15
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 ''
Beispiel #16
0
    def emit_imports():
        def emit_code_1(code, p):
            code += "from {0} import *".format(
                pgu.get_package_module_name(p, 'typeset'))
            code += gu.emit_line_return()

            return code

        def emit_code_2(code, p):
            code += "import {0} as {1}".format(
                pgu.get_package_module_name(p, 'typeset'),
                p.op_name)
            code += gu.emit_line_return()

            return code

        return reduce(emit_code_1, o.packages, str()) + \
               reduce(emit_code_2, o.packages, gu.emit_line_return())
Beispiel #17
0
    def emit_imports():
        def emit_code_1(code):
            code += "from v{0} import *".format(
                pgu.get_package_module_name(p, 'typeset'))
            code += gu.emit_line_return()

            return code

        def emit_code_2(code, p):
            code += "import {0} as {1}".format(
                pgu.get_package_module_name(p, 'typeset'),
                p.op_name)
            code += gu.emit_line_return()

            return code

        return reduce(emit_code_1, o.packages, str()) + \
               reduce(emit_code_2, o.packages, gu.emit_line_return())
Beispiel #18
0
def _emit_snippet_decoding(prp, decoding, type):
    """Emits a class property decoding."""
    def get_decoding_function():
        # ... simple/enum types - return type functional name
        #     (is directly mapped to a convertor function).
        if prp.type.is_simple or prp.type.is_enum:
            return '\'{0}\''.format(pgu.get_type_functional_name(prp.type))
        # ... complex classes - return class functional name.
        elif prp.type.is_class:
            type_name = prp.type.name if type is None else type
            return _get_decoder_function_name(type_name)

    tmpl = '{0}(\'{1}\', {2}, {3}, \'{4}\'),'
    return tmpl.format(
        gu.emit_line_return() + gu.emit_indent(2),
        prp.name,
        prp.is_iterative,
        get_decoding_function(),
        '' if decoding is None else decoding)
Beispiel #19
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 ''
Beispiel #20
0
 def emit_code(code, c):
     return code + "from {0} import {1}".format(
         pgu.get_package_module_name(c.package, 'decoder'),
         _get_decoder_function_name(c)) + gu.emit_line_return()
Beispiel #21
0
        def emit_code_1(code, p):
            code += "from {0} import *".format(
                pgu.get_package_module_name(p, 'typeset'))
            code += gu.emit_line_return()

            return code
Beispiel #22
0
 def emit_code(code, c):
     return code + "from {0} import {1}".format(
         pgu.get_package_module_name(c.package, 'decoder'),
         _get_decoder_function_name(c)) + gu.emit_line_return()
Beispiel #23
0
        def emit_code_1(code):
            code += "from v{0} import *".format(
                pgu.get_package_module_name(p, 'typeset'))
            code += gu.emit_line_return()

            return code