Пример #1
0
import json
import sys
import pprint
import re

import cbor2 as cbor
import pygments
import pygments.lexers
import pygments.formatters

from aiocoap.util import linkformat, contenttype

from aiocoap.util.linkformat_pygments import _register

_register()

MEDIATYPE_HEXDUMP = 'text/vnd.aiocoap.hexdump'


def lexer_for_mime(mime):
    """A wrapper around pygments.lexers.get_lexer_for_mimetype that takes
    subtypes into consideration and catches the custom hexdump mime type."""

    if mime == MEDIATYPE_HEXDUMP:
        return pygments.lexers.HexdumpLexer()

    if mime == 'text/plain;charset=utf8':
        # We have fall-throughs in place anwyay, no need to go through a no-op
        # TextLexer
        raise pygments.util.ClassNotFound
Пример #2
0
"""A pretty-printer for known mime types"""

import json
import sys
import pprint
import re

import cbor
import pygments, pygments.lexers, pygments.formatters

from aiocoap.numbers import media_types
from aiocoap.util import linkformat

from aiocoap.util.linkformat_pygments import _register

_register()

MEDIATYPE_HEXDUMP = 'text/vnd.aiocoap.hexdump'

def lexer_for_mime(mime):
    """A wrapper around pygments.lexers.get_lexer_for_mimetype that takes
    subtypes into consideration and catches the custom hexdump mime type."""

    if mime == MEDIATYPE_HEXDUMP:
        return pygments.lexers.HexdumpLexer()

    if mime == 'text/plain;charset=utf8':
        # We have fall-throughs in place anwyay, no need to go through a no-op
        # TextLexer
        raise pygments.util.ClassNotFound