Пример #1
0
    def get_all():
        """List all available formatters

        :rtype: list[str]
        """

        return get_all_formatters()
Пример #2
0
    def get_all():
        """List all available formatters

        :rtype: list[str]
        """

        return get_all_formatters()
Пример #3
0
    def get_all():
        """
        List all available formatters.

        RETURNS
            a list of string containing the label of all formaters
        """

        return get_all_formatters()
def _discover_formatters():
    import inspect
    from pygments.formatters import get_all_formatters

    # maps file extension (and names) to (module, classname) tuples
    default_exts = {}
    exts = {}
    # maps formatter 'name' (not the class name) and alias to (module, classname) tuples
    default_names = {}
    names = {}
    formatters = {"exts": exts, "names": names}
    if DEBUG:
        from collections import defaultdict

        duplicates = defaultdict(set)
    for cls in get_all_formatters():
        mod = inspect.getmodule(cls)
        val = (mod.__name__, cls.__name__)
        # add extentions
        for filename in cls.filenames:
            if filename.startswith("*."):
                filename = filename[1:]
            if "*" in filename:
                continue
            if (
                DEBUG
                and filename in exts
                and exts[filename] != val
                and filename not in default_exts
            ):
                duplicates[filename].add(val)
                duplicates[filename].add(exts[filename])
            exts[filename] = val
        # add names and aliases
        names[cls.name] = val
        for alias in cls.aliases:
            if (
                DEBUG
                and alias in names
                and names[alias] != val
                and alias not in default_names
            ):
                duplicates[alias].add(val)
                duplicates[alias].add(names[alias])
            names[alias] = val
    # remove some ambiquity
    exts.update(default_exts)
    names.update(default_names)
    # print dumplicate message
    if DEBUG:
        _print_duplicate_message(duplicates)
    return formatters
Пример #5
0
def _discover_formatters():
    import inspect
    from pygments.formatters import get_all_formatters

    # maps file extension (and names) to (module, classname) tuples
    default_exts = {}
    exts = {}
    # maps formatter 'name' (not the class name) and alias to (module, classname) tuples
    default_names = {}
    names = {}
    formatters = {"exts": exts, "names": names}
    if DEBUG:
        from collections import defaultdict

        duplicates = defaultdict(set)
    for cls in get_all_formatters():
        mod = inspect.getmodule(cls)
        val = (mod.__name__, cls.__name__)
        # add extentions
        for filename in cls.filenames:
            if filename.startswith("*."):
                filename = filename[1:]
            if "*" in filename:
                continue
            if (
                DEBUG
                and filename in exts
                and exts[filename] != val
                and filename not in default_exts
            ):
                duplicates[filename].add(val)
                duplicates[filename].add(exts[filename])
            exts[filename] = val
        # add names and aliases
        names[cls.name] = val
        for alias in cls.aliases:
            if (
                DEBUG
                and alias in names
                and names[alias] != val
                and alias not in default_names
            ):
                duplicates[alias].add(val)
                duplicates[alias].add(names[alias])
            names[alias] = val
    # remove some ambiquity
    exts.update(default_exts)
    names.update(default_names)
    # print dumplicate message
    if DEBUG:
        _print_duplicate_message(duplicates)
    return formatters
Пример #6
0
def _print_list(what):
    if what == "lexer":
        print()
        print("Lexers:")
        print("~~~~~~~")

        info = []
        for fullname, names, exts, _ in get_all_lexers():
            tup = (", ".join(names) + ":", fullname, exts and "(filenames " + ", ".join(exts) + ")" or "")
            info.append(tup)
        info.sort()
        for i in info:
            print(("* %s\n    %s %s") % i)

    elif what == "formatter":
        print()
        print("Formatters:")
        print("~~~~~~~~~~~")

        info = []
        for cls in get_all_formatters():
            doc = docstring_headline(cls)
            tup = (
                ", ".join(cls.aliases) + ":",
                doc,
                cls.filenames and "(filenames " + ", ".join(cls.filenames) + ")" or "",
            )
            info.append(tup)
        info.sort()
        for i in info:
            print(("* %s\n    %s %s") % i)

    elif what == "filter":
        print()
        print("Filters:")
        print("~~~~~~~~")

        for name in get_all_filters():
            cls = find_filter_class(name)
            print("* " + name + ":")
            print("    %s" % docstring_headline(cls))

    elif what == "style":
        print()
        print("Styles:")
        print("~~~~~~~")

        for name in get_all_styles():
            cls = get_style_by_name(name)
            print("* " + name + ":")
            print("    %s" % docstring_headline(cls))
Пример #7
0
def _print_list(what):
    if what == 'lexer':
        print()
        print("Lexers:")
        print("~~~~~~~")

        info = []
        for fullname, names, exts, _ in get_all_lexers():
            tup = (', '.join(names)+':', fullname,
                   exts and '(filenames ' + ', '.join(exts) + ')' or '')
            info.append(tup)
        info.sort()
        for i in info:
            print(('* %s\n    %s %s') % i)

    elif what == 'formatter':
        print()
        print("Formatters:")
        print("~~~~~~~~~~~")

        info = []
        for cls in get_all_formatters():
            doc = docstring_headline(cls)
            tup = (', '.join(cls.aliases) + ':', doc, cls.filenames and
                   '(filenames ' + ', '.join(cls.filenames) + ')' or '')
            info.append(tup)
        info.sort()
        for i in info:
            print(('* %s\n    %s %s') % i)

    elif what == 'filter':
        print()
        print("Filters:")
        print("~~~~~~~~")

        for name in get_all_filters():
            cls = find_filter_class(name)
            print("* " + name + ':')
            print("    %s" % docstring_headline(cls))

    elif what == 'style':
        print()
        print("Styles:")
        print("~~~~~~~")

        for name in get_all_styles():
            cls = get_style_by_name(name)
            print("* " + name + ':')
            print("    %s" % docstring_headline(cls))
Пример #8
0
def _print_list(what):
    if what == 'lexer':
        print()
        print("Lexers:")
        print("~~~~~~~")

        info = []
        for fullname, names, exts, _ in get_all_lexers():
            tup = (', '.join(names) + ':', fullname,
                   exts and '(filenames ' + ', '.join(exts) + ')' or '')
            info.append(tup)
        info.sort()
        for i in info:
            print(('* %s\n    %s %s') % i)

    elif what == 'formatter':
        print()
        print("Formatters:")
        print("~~~~~~~~~~~")

        info = []
        for cls in get_all_formatters():
            doc = docstring_headline(cls)
            tup = (', '.join(cls.aliases) + ':', doc, cls.filenames
                   and '(filenames ' + ', '.join(cls.filenames) + ')' or '')
            info.append(tup)
        info.sort()
        for i in info:
            print(('* %s\n    %s %s') % i)

    elif what == 'filter':
        print()
        print("Filters:")
        print("~~~~~~~~")

        for name in get_all_filters():
            cls = find_filter_class(name)
            print("* " + name + ':')
            print("    %s" % docstring_headline(cls))

    elif what == 'style':
        print()
        print("Styles:")
        print("~~~~~~~")

        for name in get_all_styles():
            cls = get_style_by_name(name)
            print("* " + name + ':')
            print("    %s" % docstring_headline(cls))
Пример #9
0
def _print_list_as_json(requested_items):
    import json
    result = {}
    if 'lexer' in requested_items:
        info = {}
        for fullname, names, filenames, mimetypes in get_all_lexers():
            info[fullname] = {
                'aliases': names,
                'filenames': filenames,
                'mimetypes': mimetypes
            }
        result['lexers'] = info

    if 'formatter' in requested_items:
        info = {}
        for cls in get_all_formatters():
            doc = docstring_headline(cls)
            info[cls.name] = {
                'aliases': cls.aliases,
                'filenames': cls.filenames,
                'doc': doc
            }
        result['formatters'] = info

    if 'filter' in requested_items:
        info = {}
        for name in get_all_filters():
            cls = find_filter_class(name)
            info[name] = {'doc': docstring_headline(cls)}
        result['filters'] = info

    if 'style' in requested_items:
        info = {}
        for name in get_all_styles():
            cls = get_style_by_name(name)
            info[name] = {'doc': docstring_headline(cls)}
        result['styles'] = info

    json.dump(result, sys.stdout)
Пример #10
0
def list_formatters():
    formatters = [i.aliases for i in get_all_formatters()]
    return DictResponse(formatters)
Пример #11
0
def get_formatters():
  formats = sorted(
    formatters.get_all_formatters(), key=lambda i: i.name.lower())
  # exclude img based formatters
  formats = [f for f in formats if not 'img' in f.name]
  return formats
Пример #12
0
import sys
import json
from pygments.lexers import get_all_lexers
from pygments.formatters import get_all_formatters


def lexer_dict(name, aliases, filetypes, mimetypes):
    return {
        '_lexerName': name,
        '_lexerAliases': list(aliases),
        '_lexerFileTypes': list(filetypes),
        '_lexerMimeTypes': list(mimetypes)
    }


def formatter_dict(f):
    return {'_formatterName': f.name, '_formatterAliases': list(f.aliases)}


if len(sys.argv) < 2:
    print('Usage: {} (lexers|formatters)'.format(sys.argv[0]))
    sys.exit(1)

if sys.argv[1] == "lexers":
    lexers = [lexer_dict(*x) for x in get_all_lexers()]
    json.dump(lexers, sys.stdout)

if sys.argv[1] == "formatters":
    formatters = [formatter_dict(x) for x in get_all_formatters()]
    json.dump(formatters, sys.stdout)
Пример #13
0
def list_formatters():
    formatters = '\n'.join(' '.join(i.aliases) for i in get_all_formatters())
    return '{}\n'.format(formatters)
Пример #14
0
#!/usr/bin/env python
import sys
import json
from pygments.lexers import get_all_lexers
from pygments.formatters import get_all_formatters

def lexer_dict(name, aliases, filetypes, mimetypes):
    return { '_lexerName': name
           , '_lexerAliases': list(aliases)
           , '_lexerFileTypes': list(filetypes)
           , '_lexerMimeTypes': list(mimetypes)
           }

def formatter_dict(f):
    return { '_formatterName': f.name
           , '_formatterAliases': list(f.aliases)
           }

if len(sys.argv) < 2:
    print('Usage: {} (lexers|formatters)'.format(sys.argv[0]))
    sys.exit(1)

if sys.argv[1] == "lexers":
    lexers = [lexer_dict(*x) for x in get_all_lexers()]
    json.dump(lexers, sys.stdout)

if sys.argv[1] == "formatters":
    formatters = [formatter_dict(x) for x in get_all_formatters()]
    json.dump(formatters, sys.stdout)
Пример #15
0
 def get_message(self):
     result = ""
     for cur_formater in get_all_formatters():
         result = result + ("".join(cur_formater.filenames))
     return {"text": result.replace("*", ", *")}
Пример #16
0
def list_formatters():
    formatters = '\n'.join(' '.join(i.aliases) for i in get_all_formatters())
    return '{}\n'.format(formatters)