@@ -858,7 +858,7 @@ def copy(self):
858
858
return new
859
859
860
860
861
- class JSONEncoder (json .JSONEncoder ):
861
+ class _JSONEncoder (json .JSONEncoder ):
862
862
def default (self , o ):
863
863
if isinstance (o , FontManager ):
864
864
return dict (o .__dict__ , __class__ = 'FontManager' )
@@ -876,6 +876,11 @@ def default(self, o):
876
876
return super ().default (o )
877
877
878
878
879
+ @cbook .deprecated ("3.2" , alternative = "json_dump" )
880
+ class JSONEncoder (_JSONEncoder ):
881
+ pass
882
+
883
+
879
884
def _json_decode (o ):
880
885
cls = o .pop ('__class__' , None )
881
886
if cls is None :
@@ -896,26 +901,32 @@ def _json_decode(o):
896
901
897
902
def json_dump (data , filename ):
898
903
"""
899
- Dumps a data structure as JSON in the named file.
904
+ Dump `FontManager` *data* as JSON to the file named *filename*.
905
+
906
+ Notes
907
+ -----
908
+ File paths that are children of the Matplotlib data path (typically, fonts
909
+ shipped with Matplotlib) are stored relative to that data path (to remain
910
+ valid across virtualenvs).
900
911
901
- Handles FontManager and its fields. File paths that are children of the
902
- Matplotlib data path (typically, fonts shipped with Matplotlib) are stored
903
- relative to that data path (to remain valid across virtualenvs).
912
+ See Also
913
+ --------
914
+ json_load
904
915
"""
905
916
with open (filename , 'w' ) as fh :
906
917
try :
907
- json .dump (data , fh , cls = JSONEncoder , indent = 2 )
918
+ json .dump (data , fh , cls = _JSONEncoder , indent = 2 )
908
919
except OSError as e :
909
920
_log .warning ('Could not save font_manager cache {}' .format (e ))
910
921
911
922
912
923
def json_load (filename ):
913
924
"""
914
- Loads a data structure as JSON from the named file .
925
+ Load a `FontManager` from the JSON file named *filename* .
915
926
916
- Handles FontManager and its fields. Relative file paths are interpreted
917
- as being relative to the Matplotlib data path, and transformed into
918
- absolute paths.
927
+ See Also
928
+ --------
929
+ json_dump
919
930
"""
920
931
with open (filename , 'r' ) as fh :
921
932
return json .load (fh , object_hook = _json_decode )
0 commit comments