~ubuntu-branches/ubuntu/oneiric/moin/oneiric-security

« back to all changes in this revision

Viewing changes to MoinMoin/support/pygments/styles/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-03-30 12:55:34 UTC
  • mfrom: (0.1.17 sid)
  • Revision ID: james.westby@ubuntu.com-20100330125534-4c2ufc1rok24447l
Tags: 1.9.2-2ubuntu1
* Merge from Debian testing (LP: #521834). Based on work by Stefan Ebner.
  Remaining changes:
 - Remove python-xml from Suggests field, the package isn't anymore in
   sys.path.
 - Demote fckeditor from Recommends to Suggests; the code was previously
   embedded in moin, but it was also disabled, so there's no reason for us
   to pull this in by default currently. Note: This isn't necessary anymore
   but needs a MIR for fckeditor, so postpone dropping this change until
   lucid+1
* debian/rules:
  - Replace hardcoded python2.5 with python* and hardcore python2.6 for ln
* debian/control.in: drop versioned depends on cdbs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
"""
 
3
    pygments.styles
 
4
    ~~~~~~~~~~~~~~~
 
5
 
 
6
    Contains built-in styles.
 
7
 
 
8
    :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
 
9
    :license: BSD, see LICENSE for details.
 
10
"""
 
11
 
 
12
from pygments.plugin import find_plugin_styles
 
13
from pygments.util import ClassNotFound
 
14
 
 
15
 
 
16
#: Maps style names to 'submodule::classname'.
 
17
STYLE_MAP = {
 
18
    'default':  'default::DefaultStyle',
 
19
    'emacs':    'emacs::EmacsStyle',
 
20
    'friendly': 'friendly::FriendlyStyle',
 
21
    'colorful': 'colorful::ColorfulStyle',
 
22
    'autumn':   'autumn::AutumnStyle',
 
23
    'murphy':   'murphy::MurphyStyle',
 
24
    'manni':    'manni::ManniStyle',
 
25
    'monokai':  'monokai::MonokaiStyle',
 
26
    'perldoc':  'perldoc::PerldocStyle',
 
27
    'pastie':   'pastie::PastieStyle',
 
28
    'borland':  'borland::BorlandStyle',
 
29
    'trac':     'trac::TracStyle',
 
30
    'native':   'native::NativeStyle',
 
31
    'fruity':   'fruity::FruityStyle',
 
32
    'bw':       'bw::BlackWhiteStyle',
 
33
    'vs':       'vs::VisualStudioStyle',
 
34
    'tango':    'tango::TangoStyle',
 
35
}
 
36
 
 
37
 
 
38
def get_style_by_name(name):
 
39
    if name in STYLE_MAP:
 
40
        mod, cls = STYLE_MAP[name].split('::')
 
41
        builtin = "yes"
 
42
    else:
 
43
        for found_name, style in find_plugin_styles():
 
44
            if name == found_name:
 
45
                return style
 
46
        # perhaps it got dropped into our styles package
 
47
        builtin = ""
 
48
        mod = name
 
49
        cls = name.title() + "Style"
 
50
 
 
51
    try:
 
52
        mod = __import__('pygments.styles.' + mod, None, None, [cls])
 
53
    except ImportError:
 
54
        raise ClassNotFound("Could not find style module %r" % mod +
 
55
                         (builtin and ", though it should be builtin") + ".")
 
56
    try:
 
57
        return getattr(mod, cls)
 
58
    except AttributeError:
 
59
        raise ClassNotFound("Could not find style class %r in style module." % cls)
 
60
 
 
61
 
 
62
def get_all_styles():
 
63
    """Return an generator for all styles by name,
 
64
    both builtin and plugin."""
 
65
    for name in STYLE_MAP:
 
66
        yield name
 
67
    for name, _ in find_plugin_styles():
 
68
        yield name