~ubuntu-branches/ubuntu/raring/wxwidgets2.8/raring

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/extern/pygments/formatters/other.py

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-07 13:59:25 UTC
  • mfrom: (1.1.9) (5.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120107135925-2601miy9ullcon9j
Tags: 2.8.12.1-6ubuntu1
* Resync from Debian, changes that were kept:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control: Build-dep on libxt-dev for mediactrl.
  - Patches
    + fix-bashism-in-example
* Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to python-wxversion
  to guarantee upgrade ordering when moving from pycentral to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
    Other formatters: NullFormatter, RawTokenFormatter.
7
7
 
8
 
    :copyright: 2006-2007 by Georg Brandl, Armin Ronacher.
9
 
    :license: BSD, see LICENSE for more details.
 
8
    :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
 
9
    :license: BSD, see LICENSE for details.
10
10
"""
11
11
 
12
12
from pygments.formatter import Formatter
13
 
from pygments.util import get_choice_opt
 
13
from pygments.util import OptionError, get_choice_opt, b
14
14
from pygments.token import Token
15
15
from pygments.console import colorize
16
16
 
42
42
    be converted to a token stream with the `RawTokenLexer`, described in the
43
43
    `lexer list <lexers.txt>`_.
44
44
 
45
 
    Only one option is accepted:
 
45
    Only two options are accepted:
46
46
 
47
47
    `compress`
48
48
        If set to ``'gz'`` or ``'bz2'``, compress the output with the given
61
61
 
62
62
    def __init__(self, **options):
63
63
        Formatter.__init__(self, **options)
 
64
        if self.encoding:
 
65
            raise OptionError('the raw formatter does not support the '
 
66
                              'encoding option')
 
67
        self.encoding = 'ascii'  # let pygments.format() do the right thing
64
68
        self.compress = get_choice_opt(options, 'compress',
65
69
                                       ['', 'none', 'gz', 'bz2'], '')
66
70
        self.error_color = options.get('error_color', None)
74
78
                                 self.error_color)
75
79
 
76
80
    def format(self, tokensource, outfile):
 
81
        try:
 
82
            outfile.write(b(''))
 
83
        except TypeError:
 
84
            raise TypeError('The raw tokens formatter needs a binary '
 
85
                            'output file')
77
86
        if self.compress == 'gz':
78
87
            import gzip
79
88
            outfile = gzip.GzipFile('', 'wb', 9, outfile)
80
 
            write = outfile.write
 
89
            def write(text):
 
90
                outfile.write(text.encode())
81
91
            flush = outfile.flush
82
92
        elif self.compress == 'bz2':
83
93
            import bz2
84
94
            compressor = bz2.BZ2Compressor(9)
85
95
            def write(text):
86
 
                outfile.write(compressor.compress(text))
 
96
                outfile.write(compressor.compress(text.encode()))
87
97
            def flush():
88
98
                outfile.write(compressor.flush())
89
99
                outfile.flush()
90
100
        else:
91
 
            write = outfile.write
 
101
            def write(text):
 
102
                outfile.write(text.encode())
92
103
            flush = outfile.flush
93
104
 
94
105
        lasttype = None