Ejemplo n.º 1
0
def wrap(codestring):
    """Wrap code created by AsteriskPy to a certain width.

    Define lines to wrap and string to glean indent index from
    in the CODE_WRAP_MARKERS list at the top of this file.

    For many languages, this function may not need to be changed much
    at all.

    In perl, we want to indent at exactly the index of the code marker we use.
    We must append '# ' to the indention, since perl doesn't have multi-line
    comments. Use tabs. Wrap to 70 characters since use of tabs may increase
    visible line length.

    """
    width = 70
    code_lines = codestring.split('\n')
    wrapped_code_lines = []
    for line in code_lines:
        if len(line) < width:
            wrapped_code_lines.append(line)
            continue

        matched = None
        for each in CODE_WRAP_MARKERS:
            match = re.search('^\s+(%s)' % (each[0]), line)
            if match is not None:
                matched = True
                new_line = wrap_line(line,
                                     width,
                                     each[1],
                                     indent_char='\t',
                                     indent_suffix=each[2],
                                     indent_offset=each[3])
                wrapped_code_lines.append(new_line)

        if matched is None:
            wrapped_code_lines.append(line)

    return '\n'.join(wrapped_code_lines)
Ejemplo n.º 2
0
def wrap(codestring):
    """Wrap code created by AsteriskPy to a certain width.

    Define lines to wrap and string to glean indent index from
    in the CODE_WRAP_MARKERS list at the top of this file.

    For many languages, this function may not need to be changed much
    at all.

    In python, we want to indent at one greater than the index
    of the code marker we use.  We don't need to use a suffix since python
    has multi-line comments, and we will use spaces.

    """
    width = 79
    code_lines = codestring.split('\n')
    wrapped_code_lines = []
    for line in code_lines:
        if len(line) < width:
            wrapped_code_lines.append(line)
            continue

        matched = None
        for each in CODE_WRAP_MARKERS:
            match = re.search('^\s+(%s)' % (each[0]), line)
            if match is not None:
                matched = True
                new_line = wrap_line(line,
                                     width,
                                     each[1],
                                     indent_suffix=each[2],
                                     indent_offset=each[3])
                wrapped_code_lines.append(new_line)

        if matched is None:
            wrapped_code_lines.append(line)

    return '\n'.join(wrapped_code_lines)
def wrap(codestring):
    """Wrap code created by AsteriskPy to a certain width.

    Define lines to wrap and string to glean indent index from
    in the CODE_WRAP_MARKERS list at the top of this file.

    For many languages, this function may not need to be changed much
    at all.

    In perl, we want to indent at exactly the index of the code marker we use.
    We must append '# ' to the indention, since perl doesn't have multi-line
    comments. Use tabs. Wrap to 70 characters since use of tabs may increase
    visible line length.

    """
    width = 70
    code_lines = codestring.split('\n')
    wrapped_code_lines = []
    for line in code_lines:
        if len(line) < width:
            wrapped_code_lines.append(line)
            continue

        matched = None
        for each in CODE_WRAP_MARKERS:
            match = re.search('^\s+(%s)' % (each[0]), line)
            if match is not None:
                matched = True
                new_line = wrap_line(line, width, each[1], indent_char='\t',
                                     indent_suffix=each[2],
                                     indent_offset=each[3])
                wrapped_code_lines.append(new_line)

        if matched is None:
            wrapped_code_lines.append(line)

    return '\n'.join(wrapped_code_lines)
Ejemplo n.º 4
0
def wrap(codestring):
    """Wrap code created by AsteriskPy to a certain width.

    Define lines to wrap and string to glean indent index from
    in the CODE_WRAP_MARKERS list at the top of this file.

    For many languages, this function may not need to be changed much
    at all.

    In python, we want to indent at one greater than the index
    of the code marker we use.  We don't need to use a suffix since python
    has multi-line comments, and we will use spaces.

    """
    width = 79
    code_lines = codestring.split('\n')
    wrapped_code_lines = []
    for line in code_lines:
        if len(line) < width:
            wrapped_code_lines.append(line)
            continue

        matched = None
        for each in CODE_WRAP_MARKERS:
            match = re.search('^\s+(%s)' % (each[0]), line)
            if match is not None:
                matched = True
                new_line = wrap_line(line, width, each[1],
                                     indent_suffix=each[2],
                                     indent_offset=each[3])
                wrapped_code_lines.append(new_line)

        if matched is None:
            wrapped_code_lines.append(line)

    return '\n'.join(wrapped_code_lines)