8000 FIX: use b'' when escaping array as strings in ps · matplotlib/matplotlib@97953f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 97953f3

Browse files
committed
FIX: use b'' when escaping array as strings in ps
The function quote_ps_string is used to sanitize the result of np.tostring (which really returns bytes) to make sure no 'special' ps characters make it through. We were trying to use unicode to replace in a byte string We also need to decode bytes to unicode to put the string into the ps file. closes #6226
1 parent 44e7356 commit 97953f3

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,16 @@ def _num_to_str(val):
165165
def _nums_to_str(*args):
166166
return ' '.join(map(_num_to_str,args))
167167

168+
168169
def quote_ps_string(s):
169170
"Quote dangerous characters of S for use in a PostScript string constant."
170-
s=s.replace("\\", "\\\\")
171-
s=s.replace("(", "\\(")
172-
s=s.replace(")", "\\)")
173-
s=s.replace("'", "\\251")
174-
s=s.replace("`", "\\301")
175-
s=re.sub(r"[^ -~\n]", lambda x: r"\%03o"%ord(x.group()), s)
176-
return s
171+
s = s.replace(b"\\", b"\\\\")
172+
s = s.replace(b"(", b"\\(")
173+
s = s.replace(b")", b"\\)")
174+
s = s.replace(b"'", b"\\251")
175+
s = s.replace(b"`", b"\\301")
176+
s = re.sub(br"[^ -~\n]", lambda x: br"\%03o" % ord(x.group()), s)
177+
return s.decode('ascii')
177178

178179

179180
def seq_allequal(seq1, seq2):

0 commit comments

Comments
 (0)
0