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