示例#1
0
def syntax_highlight(filename="", language=None):
    mako_lexer = MakoLexer()
    python_lexer = Python3Lexer()
    if filename.startswith("memory:") or language == "mako":
        return lambda string: highlight(string, mako_lexer,
                                        pygments_html_formatter)
    return lambda string: highlight(string, python_lexer,
                                    pygments_html_formatter)
示例#2
0
def syntax_highlight(filename='', language=None):
    mako_lexer = MakoLexer()
    if compat.py3k:
        python_lexer = Python3Lexer()
    else:
        python_lexer = PythonLexer()
    if filename.startswith('memory:') or language == 'mako':
        return lambda string: highlight(string, mako_lexer,
                                        pygments_html_formatter)
    return lambda string: highlight(string, python_lexer,
                                    pygments_html_formatter)
示例#3
0
def template_inst_start_callback(lexer, match, ctx):
    """Look ahead to disambiguate a function call for a template instantiation.

    """
    start, stop = match.start(), match.end()
    # If line ends with a colon this is a template instantiation
    line = ctx.text[start:].split('\n', 1)[0]
    if line.rstrip().endswith(':'):

        yield start, Text, match.group(1)
        yield match.start(2), Name.Tag, match.group(2)
        yield match.start(3), Text, match.group(3)
        yield match.start(4), Punctuation, match.group(4)
        ctx.stack.append('templateinst_end')

    # Use a standard Python lexer to lex the function call that may be a builtin
    else:
        it = Python3Lexer().get_tokens_unprocessed(match.string[start:stop])
        for token in it:
            yield token
    ctx.pos = stop
示例#4
0
from indico.core.db import db
from indico.modules.attachments import Attachment
from indico.modules.attachments.models.attachments import AttachmentFile, AttachmentType
from indico.modules.categories import Category
from indico.util.console import cformat, verbose_iterator
from indico.util.string import strip_control_chars

from indico_citadel.models.id_map import CitadelIdMap, get_entry_type
from indico_citadel.schemas import (AttachmentRecordSchema,
                                    ContributionRecordSchema,
                                    EventNoteRecordSchema, EventRecordSchema,
                                    SubContributionRecordSchema)
from indico_citadel.util import parallelize
from indico_livesync import LiveSyncBackendBase, SimpleChange, Uploader

lexer = Python3Lexer()
formatter = Terminal256Formatter(style='native')


def _format_change_str(change):
    return ','.join(flag.name for flag in SimpleChange if change & flag)


def _print_record(record):
    obj_type, obj_id, citadel_id, data, changes = record
    print()  # verbose_iterator during initial exports doesn't end its line
    print(
        f'{_format_change_str(changes)}: {obj_type.name} {obj_id} [{citadel_id}]'
    )
    if data is not None:
        print(highlight(pformat(data), lexer, formatter))