Back to index

moin  1.9.0~rc2
__init__.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 """
00003     pygments.styles
00004     ~~~~~~~~~~~~~~~
00005 
00006     Contains built-in styles.
00007 
00008     :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS.
00009     :license: BSD, see LICENSE for details.
00010 """
00011 
00012 from pygments.plugin import find_plugin_styles
00013 from pygments.util import ClassNotFound
00014 
00015 
00016 #: Maps style names to 'submodule::classname'.
00017 STYLE_MAP = {
00018     'default':  'default::DefaultStyle',
00019     'emacs':    'emacs::EmacsStyle',
00020     'friendly': 'friendly::FriendlyStyle',
00021     'colorful': 'colorful::ColorfulStyle',
00022     'autumn':   'autumn::AutumnStyle',
00023     'murphy':   'murphy::MurphyStyle',
00024     'manni':    'manni::ManniStyle',
00025     'perldoc':  'perldoc::PerldocStyle',
00026     'pastie':   'pastie::PastieStyle',
00027     'borland':  'borland::BorlandStyle',
00028     'trac':     'trac::TracStyle',
00029     'native':   'native::NativeStyle',
00030     'fruity':   'fruity::FruityStyle',
00031     'bw':       'bw::BlackWhiteStyle',
00032     'vs':       'vs::VisualStudioStyle',
00033     'tango':    'tango::TangoStyle',
00034 }
00035 
00036 
00037 def get_style_by_name(name):
00038     if name in STYLE_MAP:
00039         mod, cls = STYLE_MAP[name].split('::')
00040         builtin = "yes"
00041     else:
00042         for found_name, style in find_plugin_styles():
00043             if name == found_name:
00044                 return style
00045         # perhaps it got dropped into our styles package
00046         builtin = ""
00047         mod = name
00048         cls = name.title() + "Style"
00049 
00050     try:
00051         mod = __import__('pygments.styles.' + mod, None, None, [cls])
00052     except ImportError:
00053         raise ClassNotFound("Could not find style module %r" % mod +
00054                          (builtin and ", though it should be builtin") + ".")
00055     try:
00056         return getattr(mod, cls)
00057     except AttributeError:
00058         raise ClassNotFound("Could not find style class %r in style module." % cls)
00059 
00060 
00061 def get_all_styles():
00062     """Return an generator for all styles by name,
00063     both builtin and plugin."""
00064     for name in STYLE_MAP:
00065         yield name
00066     for name, _ in find_plugin_styles():
00067         yield name