1+ import io
12import os
23import re
34import shutil
@@ -88,7 +89,7 @@ def _get_cached_dataset_description(did):
8889 did_cache_dir = os .path .join (cache_dir , "datasets" , str (did ))
8990 description_file = os .path .join (did_cache_dir , "description.xml" )
9091 try :
91- with open (description_file ) as fh :
92+ with io . open (description_file , encoding = 'utf8' ) as fh :
9293 dataset_xml = fh .read ()
9394 except (IOError , OSError ):
9495 continue
@@ -106,7 +107,7 @@ def _get_cached_dataset_arff(did):
106107 output_file = os .path .join (did_cache_dir , "dataset.arff" )
107108
108109 try :
109- with open (output_file ):
110+ with io . open (output_file , encoding = 'utf8' ):
110111 pass
111112 return output_file
112113 except (OSError , IOError ):
@@ -298,13 +299,13 @@ def _get_dataset_description(did_cache_dir, did):
298299 return_code , dataset_xml = _perform_api_call (
299300 "data/%d" % did )
300301
301- with open (description_file , "w" ) as fh :
302+ with io . open (description_file , "w" , encoding = 'utf8' ) as fh :
302303 fh .write (dataset_xml )
303304
304305 description = xmltodict .parse (dataset_xml )[
305306 "oml:data_set_description" ]
306307
307- with open (description_file , "w" ) as fh :
308+ with io . open (description_file , "w" , encoding = 'utf8' ) as fh :
308309 fh .write (dataset_xml )
309310
310311 return description
@@ -337,7 +338,7 @@ def _get_dataset_arff(did_cache_dir, description):
337338 # This means the file is still there; whether it is useful is up to
338339 # the user and not checked by the program.
339340 try :
340- with open (output_file_path ):
341+ with io . open (output_file_path , encoding = 'utf8' ):
341342 pass
342343 return output_file_path
343344 except (OSError , IOError ):
@@ -346,7 +347,7 @@ def _get_dataset_arff(did_cache_dir, description):
346347 url = description ['oml:url' ]
347348 return_code , arff_string = _read_url (url )
348349
349- with open (output_file_path , "w" ) as fh :
350+ with io . open (output_file_path , "w" , encoding = 'utf8' ) as fh :
350351 fh .write (arff_string )
351352 del arff_string
352353
@@ -376,13 +377,13 @@ def _get_dataset_features(did_cache_dir, did):
376377
377378 # Dataset features aren't subject to change...
378379 try :
379- with open (features_file ) as fh :
380+ with io . open (features_file , encoding = 'utf8' ) as fh :
380381 features_xml = fh .read ()
381382 except (OSError , IOError ):
382383 return_code , features_xml = _perform_api_call (
383384 "data/features/%d" % did )
384385
385- with open (features_file , "w" ) as fh :
386+ with io . open (features_file , "w" , encoding = 'utf8' ) as fh :
386387 fh .write (features_xml )
387388
388389 features = xmltodict .parse (features_xml )["oml:data_features" ]
@@ -411,13 +412,13 @@ def _get_dataset_qualities(did_cache_dir, did):
411412 # Dataset qualities are subject to change and must be fetched every time
412413 qualities_file = os .path .join (did_cache_dir , "qualities.xml" )
413414 try :
414- with open (qualities_file ) as fh :
415+ with io . open (qualities_file , encoding = 'utf8' ) as fh :
415416 qualities_xml = fh .read ()
416417 except (OSError , IOError ):
417418 return_code , qualities_xml = _perform_api_call (
418419 "data/qualities/%d" % did )
419420
420- with open (qualities_file , "w" ) as fh :
421+ with io . open (qualities_file , "w" , encoding = 'utf8' ) as fh :
421422 fh .write (qualities_xml )
422423
423424 qualities = xmltodict .parse (qualities_xml )['oml:data_qualities' ]
0 commit comments