tests/test_using_api.pyc
tests/test_util.py
tests/test_util.pyc
+tests/__pycache__/string_asserts.cpython-33.pyc
+tests/__pycache__/support.cpython-33.pyc
+tests/__pycache__/test_basic_api.cpython-33.pyc
+tests/__pycache__/test_cfm.cpython-33.pyc
+tests/__pycache__/test_clexer.cpython-33.pyc
+tests/__pycache__/test_cmdline.cpython-33.pyc
+tests/__pycache__/test_examplefiles.cpython-33.pyc
+tests/__pycache__/test_html_formatter.cpython-33.pyc
+tests/__pycache__/test_inherit.cpython-33.pyc
+tests/__pycache__/test_java.cpython-33.pyc
+tests/__pycache__/test_latex_formatter.cpython-33.pyc
+tests/__pycache__/test_lexers_other.cpython-33.pyc
+tests/__pycache__/test_objectiveclexer.cpython-33.pyc
+tests/__pycache__/test_perllexer.cpython-33.pyc
+tests/__pycache__/test_qbasiclexer.cpython-33.pyc
+tests/__pycache__/test_regexlexer.cpython-33.pyc
+tests/__pycache__/test_regexopt.cpython-33.pyc
+tests/__pycache__/test_rtf_formatter.cpython-33.pyc
+tests/__pycache__/test_ruby.cpython-33.pyc
+tests/__pycache__/test_shell.cpython-33.pyc
+tests/__pycache__/test_smarty.cpython-33.pyc
+tests/__pycache__/test_string_asserts.cpython-33.pyc
+tests/__pycache__/test_textfmts.cpython-33.pyc
+tests/__pycache__/test_token.cpython-33.pyc
+tests/__pycache__/test_unistring.cpython-33.pyc
+tests/__pycache__/test_using_api.cpython-33.pyc
+tests/__pycache__/test_util.cpython-33.pyc
tests/dtds/HTML4-f.dtd
tests/dtds/HTML4-s.dtd
tests/dtds/HTML4.dcl
F_opts = _parse_filters(F_opts)
opts.pop('-F', None)
- # select formatter
- outfn = opts.pop('-o', None)
- fmter = opts.pop('-f', None)
- if fmter:
- try:
- fmter = get_formatter_by_name(fmter, **parsed_opts)
- except (OptionError, ClassNotFound) as err:
- print('Error:', err, file=sys.stderr)
- return 1
-
- if outfn:
- if not fmter:
- try:
- fmter = get_formatter_for_filename(outfn, **parsed_opts)
- except (OptionError, ClassNotFound) as err:
- print('Error:', err, file=sys.stderr)
- return 1
- try:
- outfile = open(outfn, 'wb')
- except Exception as err:
- print('Error: cannot open outfile:', err, file=sys.stderr)
- return 1
- else:
- if not fmter:
- fmter = TerminalFormatter(**parsed_opts)
- if sys.version_info > (3,):
- # Python 3: we have to use .buffer to get a binary stream
- outfile = sys.stdout.buffer
- else:
- outfile = sys.stdout
-
- # determine output encoding if not explicitly selected
- if not outencoding:
- if outfn:
- # output file? -> encoding pass-through
- fmter.encoding = inencoding
- else:
- # else use terminal encoding
- fmter.encoding = terminal_encoding(sys.stdout)
-
- # provide coloring under Windows, if possible
- if not outfn and sys.platform in ('win32', 'cygwin') and \
- fmter.name in ('Terminal', 'Terminal256'):
- # unfortunately colorama doesn't support binary streams on Py3
- if sys.version_info > (3,):
- import io
- outfile = io.TextIOWrapper(outfile, encoding=fmter.encoding)
- fmter.encoding = None
- try:
- import colorama.initialise
- except ImportError:
- pass
- else:
- outfile = colorama.initialise.wrap_stream(
- outfile, convert=None, strip=None, autoreset=False, wrap=True)
-
# select lexer
lexer = opts.pop('-l', None)
if lexer:
except ClassNotFound:
lexer = TextLexer(**parsed_opts)
+ # select formatter
+ outfn = opts.pop('-o', None)
+ fmter = opts.pop('-f', None)
+ if fmter:
+ try:
+ fmter = get_formatter_by_name(fmter, **parsed_opts)
+ except (OptionError, ClassNotFound) as err:
+ print('Error:', err, file=sys.stderr)
+ return 1
+
+ if outfn:
+ if not fmter:
+ try:
+ fmter = get_formatter_for_filename(outfn, **parsed_opts)
+ except (OptionError, ClassNotFound) as err:
+ print('Error:', err, file=sys.stderr)
+ return 1
+ try:
+ outfile = open(outfn, 'wb')
+ except Exception as err:
+ print('Error: cannot open outfile:', err, file=sys.stderr)
+ return 1
+ else:
+ if not fmter:
+ fmter = TerminalFormatter(**parsed_opts)
+ if sys.version_info > (3,):
+ # Python 3: we have to use .buffer to get a binary stream
+ outfile = sys.stdout.buffer
+ else:
+ outfile = sys.stdout
+
+ # determine output encoding if not explicitly selected
+ if not outencoding:
+ if outfn:
+ # output file? use lexer encoding for now (can still be None)
+ fmter.encoding = inencoding
+ else:
+ # else use terminal encoding
+ fmter.encoding = terminal_encoding(sys.stdout)
+
+ # provide coloring under Windows, if possible
+ if not outfn and sys.platform in ('win32', 'cygwin') and \
+ fmter.name in ('Terminal', 'Terminal256'):
+ # unfortunately colorama doesn't support binary streams on Py3
+ if sys.version_info > (3,):
+ import io
+ outfile = io.TextIOWrapper(outfile, encoding=fmter.encoding)
+ fmter.encoding = None
+ try:
+ import colorama.initialise
+ except ImportError:
+ pass
+ else:
+ outfile = colorama.initialise.wrap_stream(
+ outfile, convert=None, strip=None, autoreset=False, wrap=True)
+
# When using the LaTeX formatter and the option `escapeinside` is
# specified, we need a special lexer which collects escaped text
# before running the chosen language lexer.
return 0
except Exception:
+ raise
import traceback
info = traceback.format_exception(*sys.exc_info())
msg = info[-1].strip()
from __future__ import print_function
import io
+import os
import sys
+import tempfile
import unittest
from pygments import highlight
self.assertEqual(o, output)
self.assertEqual(e, "")
self.assertEqual(c, 0)
+
+ def test_outfile(self):
+ # test that output file works with and without encoding
+ fd, name = tempfile.mkstemp()
+ os.close(fd)
+ for opts in [['-fhtml', '-o', name, TESTFILE],
+ ['-flatex', '-o', name, TESTFILE],
+ ['-fhtml', '-o', name, '-O', 'encoding=utf-8', TESTFILE]]:
+ try:
+ self.assertEqual(run_cmdline(*opts)[0], 0)
+ finally:
+ os.unlink(name)