Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 97953f3

Browse filesBrowse 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
Copy full SHA for 97953f3

File tree

Expand file treeCollapse file tree

1 file changed

+8
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-7
lines changed

‎lib/matplotlib/backends/backend_ps.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_ps.py
+8-7Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.