8000 Merge pull request #8021 from tacaswell/fix_nonascii_afm · matplotlib/matplotlib@47eb989 · GitHub
[go: up one dir, main page]

Skip to content

Commit 47eb989

Browse files
authored
Merge pull request #8021 from tacaswell/fix_nonascii_afm
FIX: always decode bytes as utf-8 in AFM headers
2 parents 2b119b6 + b4a8191 commit 47eb989

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

lib/matplotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,7 @@ def tk_window_focus():
14721472

14731473
default_test_modules = [
14741474
'matplotlib.tests.test_agg',
1475+
'matplotlib.tests.test_afm',
14751476
'matplotlib.tests.test_animation',
14761477
'matplotlib.tests.test_arrow_patches',
14771478
'matplotlib.tests.test_artist',

lib/matplotlib/afm.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@
5757
def _to_int(x):
5858
return int(float(x))
5959

60+
6061
_to_float = float
61-
if six.PY3:
62-
def _to_str(x):
63-
return x.decode('utf8')
64-
else:
65-
_to_str = str
62+
63+
64+
def _to_str(x):
65+
return x.decode('utf8')
6666

6767

6868
def _to_list_of_ints(s):

lib/matplotlib/tests/test_afm.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import (absolute_import, division, print_function,
4+
unicode_literals)
5+
6+
import matplotlib.afm as afm
7+
8+
9+
def test_nonascii_str():
10+
# This tests that we also decode bytes as utf-8 properly.
11+
# Else, font files with non ascii characters fail to load.
12+
inp_str = "привет"
13+
byte_str = inp_str.encode("utf8")
14+
15+
ret = afm._to_str(byte_str)
16+
assert ret == inp_str

0 commit comments

Comments
 (0)
0