summaryrefslogtreecommitdiff
path: root/pygments/formatters
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2017-01-22 19:57:19 +0100
committerGeorg Brandl <georg@python.org>2017-01-22 19:57:19 +0100
commit1f75c51afdbe281e0044ca5c5369e14fc5e0e8e1 (patch)
treec790ff3b447d5c41e2e50cdd5d18b0071772ee9b /pygments/formatters
parent041b80fab1922800ae0618fd4d3d8d78bf7063b4 (diff)
downloadpygments-1f75c51afdbe281e0044ca5c5369e14fc5e0e8e1.tar.gz
-x functionality updates, Python 3 compatibility fix
Diffstat (limited to 'pygments/formatters')
-rw-r--r--pygments/formatters/__init__.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/pygments/formatters/__init__.py b/pygments/formatters/__init__.py
index 4ea79c5a..965c5f1a 100644
--- a/pygments/formatters/__init__.py
+++ b/pygments/formatters/__init__.py
@@ -91,14 +91,16 @@ def load_formatter_from_file(filename, formattername="CustomFormatter",
Users should be very careful with the input, because this method
is equivalent to running eval on the input file.
- Raises ClassNotFound if there are any problems importing the Formatter
+ Raises ClassNotFound if there are any problems importing the Formatter.
+
+ .. versionadded:: 2.2
"""
try:
# This empty dict will contain the namespace for the exec'd file
custom_namespace = {}
- exec(open(filename, 'r'), custom_namespace)
+ exec(open(filename, 'rb').read(), custom_namespace)
# Retrieve the class `formattername` from that namespace
- if not formattername in custom_namespace:
+ if formattername not in custom_namespace:
raise ClassNotFound('no valid %s class found in %s' %
(formattername, filename))
formatter_class = custom_namespace[formattername]
@@ -107,7 +109,7 @@ def load_formatter_from_file(filename, formattername="CustomFormatter",
except IOError as err:
raise ClassNotFound('cannot read %s' % filename)
except ClassNotFound as err:
- raise err
+ raise
except Exception as err:
raise ClassNotFound('error when loading custom formatter: %s' % err)