diff options
Diffstat (limited to 'pygments')
-rw-r--r-- | pygments/cmdline.py | 10 | ||||
-rw-r--r-- | pygments/formatter.py | 3 | ||||
-rw-r--r-- | pygments/formatters/terminal.py | 7 | ||||
-rw-r--r-- | pygments/lexer.py | 1 |
4 files changed, 19 insertions, 2 deletions
diff --git a/pygments/cmdline.py b/pygments/cmdline.py index b70d9e6d..002117d4 100644 --- a/pygments/cmdline.py +++ b/pygments/cmdline.py @@ -228,8 +228,14 @@ def main(args): highlight(code, lexer, fmter, outfile) except Exception, err: import traceback - print >>sys.stderr, 'Error while highlighting:' - print >>sys.stderr, traceback.format_exc(0).splitlines()[-1] + info = traceback.format_exception(*sys.exc_info()) + msg = info[-1].strip() + if len(info) >= 3: + # extract relevant file and position info + msg += '\n (f%s)' % info[-2].split('\n')[0].strip()[1:] + print >>sys.stderr + print >>sys.stderr, '*** Error while highlighting:' + print >>sys.stderr, msg return 1 return 0 diff --git a/pygments/formatter.py b/pygments/formatter.py index 41959565..4e07f0f4 100644 --- a/pygments/formatter.py +++ b/pygments/formatter.py @@ -44,6 +44,8 @@ class Formatter(object): output. If it is "" or None, Unicode strings will be written to the output file, which most file-like objects do not support (default: None). + ``outencoding`` + Overrides ``encoding`` if given. """ #: If True, this formatter outputs Unicode strings when no encoding @@ -55,6 +57,7 @@ class Formatter(object): self.full = get_bool_opt(options, 'full', False) self.title = options.get('title', '') self.encoding = options.get('encoding', None) or None + self.encoding = options.get('outencoding', None) or self.encoding self.options = options def get_style_defs(self, arg=''): diff --git a/pygments/formatters/terminal.py b/pygments/formatters/terminal.py index 661031e7..6ac6cd1b 100644 --- a/pygments/formatters/terminal.py +++ b/pygments/formatters/terminal.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for more details. """ +import os + from pygments.formatter import Formatter from pygments.token import Keyword, Name, Comment, String, Error, \ Number, Operator, Generic, Token @@ -77,6 +79,11 @@ class TerminalFormatter(Formatter): def format(self, tokensource, outfile): enc = self.encoding + # hack: if the output is a terminal and has an encoding set, + # use that to avoid unicode encode problems + if not enc and hasattr(outfile, "encoding") and \ + hasattr(outfile, "isatty") and outfile.isatty(): + enc = outfile.encoding for ttype, value in tokensource: if enc: value = value.encode(enc) diff --git a/pygments/lexer.py b/pygments/lexer.py index f984416a..016c60a6 100644 --- a/pygments/lexer.py +++ b/pygments/lexer.py @@ -84,6 +84,7 @@ class Lexer(object): self.stripall = get_bool_opt(options, 'stripall', False) self.tabsize = get_int_opt(options, 'tabsize', 0) self.encoding = options.get('encoding', 'latin1') + # self.encoding = options.get('inencoding', None) or self.encoding self.filters = [] for filter in get_list_opt(options, 'filters', ()): self.add_filter(filter) |