Skip to content

Commit 6902f58

Browse files
committed
Deprecate functions in backends
1 parent 9caa261 commit 6902f58

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Deprecation of helper functions in backends
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The following functions are considered private and deprecated.
5+
Vendor the code of the similarly named private functions.
6+
7+
* ``backend_pdf.fill``
8+
* ``backend_ps.quote_ps_string``
9+
* ``backend_svg.escape_attrib``
10+
* ``backend_svg.escape_cdata``
11+
* ``backend_svg.escape_comment``
12+
* ``backend_svg.short_float_fmt``

lib/matplotlib/backends/backend_pdf.py

+5
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@
9393
# * draw_quad_mesh
9494

9595

96+
@_api.deprecated("3.6", alternative="Vendor the code")
9697
def fill(strings, linelen=75):
98+
return _fill(strings, linelen=linelen)
99+
100+
101+
def _fill(strings, linelen=75):
97102
"""
98103
Make one string from sequence of strings, with whitespace in between.
99104

lib/matplotlib/backends/backend_ps.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ def _nums_to_str(*args):
8989
return " ".join(f"{arg:1.3f}".rstrip("0").rstrip(".") for arg in args)
9090

9191

92+
@_api.deprecated("3.6", "Vendor the code")
9293
def quote_ps_string(s):
94+
return _quote_ps_string(s)
95+
96+
97+
def _quote_ps_string(s):
9398
"""
9499
Quote dangerous characters of S for use in a PostScript string constant.
95100
"""
@@ -738,7 +743,7 @@ def draw_gouraud_triangles(self, gc, points, colors, trans):
738743
streamarr['flags'] = 0
739744
streamarr['points'] = (flat_points - points_min) * factor
740745
streamarr['colors'] = flat_colors[:, :3] * 255.0
741-
stream = quote_ps_string(streamarr.tobytes())
746+
stream = _quote_ps_string(streamarr.tobytes())
742747

743748
self._pswriter.write(f"""\
744749
gsave

lib/matplotlib/backends/backend_svg.py

+29-9
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@
6666
# --------------------------------------------------------------------
6767

6868

69+
@_api.deprecated("3.6", alternative="Vendor the code")
6970
def escape_cdata(s):
71+
return _escape_cdata(s)
72+
73+
74+
def _escape_cdata(s):
7075
s = s.replace("&", "&")
7176
s = s.replace("<", "&lt;")
7277
s = s.replace(">", "&gt;")
@@ -76,12 +81,22 @@ def escape_cdata(s):
7681
_escape_xml_comment = re.compile(r'-(?=-)')
7782

7883

84+
@_api.deprecated("3.6", alternative="Vendor the code")
7985
def escape_comment(s):
80-
s = escape_cdata(s)
86+
return _escape_comment.sub(s)
87+
88+
89+
def _escape_comment(s):
90+
s = _escape_cdata(s)
8191
return _escape_xml_comment.sub('- ', s)
8292

8393

94+
@_api.deprecated("3.6", alternative="Vendor the code")
8495
def escape_attrib(s):
96+
return _escape_attrib(s)
97+
98+
99+
def _escape_attrib(s):
85100
s = s.replace("&", "&amp;")
86101
s = s.replace("'", "&apos;")
87102
s = s.replace('"', "&quot;")
@@ -91,12 +106,17 @@ def escape_attrib(s):
91106

92107

93108
def _quote_escape_attrib(s):
94-
return ('"' + escape_cdata(s) + '"' if '"' not in s else
95-
"'" + escape_cdata(s) + "'" if "'" not in s else
96-
'"' + escape_attrib(s) + '"')
109+
return ('"' + _escape_cdata(s) + '"' if '"' not in s else
110+
"'" + _escape_cdata(s) + "'" if "'" not in s else
111+
'"' + _escape_attrib(s) + '"')
97112

98113

114+
@_api.deprecated("3.6", alternative="Vendor the code")
99115
def short_float_fmt(x):
116+
return _short_float_fmt(x)
117+
118+
119+
def _short_float_fmt(x):
100120
"""
101121
Create a short string representation of a float, which is %f
102122
formatting with trailing zeros and the decimal point removed.
@@ -130,7 +150,7 @@ def __flush(self, indent=True):
130150
self.__open = 0
131151
if self.__data:
132152
data = ''.join(self.__data)
133-
self.__write(escape_cdata(data))
153+
self.__write(_escape_cdata(data))
134154
self.__data = []
135155

136156
def start(self, tag, attrib={}, **extra):
@@ -153,14 +173,14 @@ def start(self, tag, attrib={}, **extra):
153173
An element identifier.
154174
"""
155175
self.__flush()
156-
tag = escape_cdata(tag)
176+
tag = _escape_cdata(tag)
157177
self.__data = []
158178
self.__tags.append(tag)
159179
self.__write(self.__indentation[:len(self.__tags) - 1])
160180
self.__write("<%s" % tag)
161181
for k, v in {**attrib, **extra}.items():
162182
if v:
163-
k = escape_cdata(k)
183+
k = _escape_cdata(k)
164184
v = _quote_escape_attrib(v)
165185
self.__write(' %s=%s' % (k, v))
166186
self.__open = 1
@@ -177,7 +197,7 @@ def comment(self, comment):
177197
"""
178198
self.__flush()
179199
self.__write(self.__indentation[:len(self.__tags)])
180-
self.__write("<!-- %s -->\n" % escape_comment(comment))
200+
self.__write("<!-- %s -->\n" % _escape_comment(comment))
181201

182202
def data(self, text):
183203
"""
@@ -203,7 +223,7 @@ def end(self, tag=None, indent=True):
203223
"""
204224
if tag:
205225
assert self.__tags, "unbalanced end(%s)" % tag
206-
assert escape_cdata(tag) == self.__tags[-1], \
226+
assert _escape_cdata(tag) == self.__tags[-1], \
207227
"expected end(%s), got %s" % (self.__tags[-1], tag)
208228
else:
209229
assert self.__tags, "unbalanced end()"

0 commit comments

Comments
 (0)