1313from itertools import chain
1414from urllib .error import HTTPError , URLError
1515
16- from mathics . builtin . import_export . checking import (
17- check_filename ,
18- import_setup_check ,
19- )
16+ # Use this when accessing IMPORTERS to get changes
17+ # since initializiation.
18+ import mathics . eval . import_export . importexport as importexport
19+ from mathics . builtin . import_export . checking import check_filename , import_setup_check
2020from mathics .core .atoms import ByteArray
2121from mathics .core .attributes import A_PROTECTED , A_READ_PROTECTED
2222from mathics .core .builtin import Builtin , Integer , Predefined , String
3636from mathics .eval .files_io .files import eval_Close
3737from mathics .eval .files_io .filesystem import eval_FindFile
3838from mathics .eval .import_export .importexport import (
39- IMPORTERS ,
4039 MIMETYPE_TO_SHORTNAME ,
4140 eval_FileFormat ,
4241 eval_Import_data_only ,
@@ -92,7 +91,9 @@ class ImportFormats(Predefined):
9291 summary_text = "list supported import formats"
9392
9493 def evaluate (self , evaluation : Evaluation ):
95- return to_mathics_list (* sorted (IMPORTERS .keys ()), elements_conversion_fn = String )
94+ return to_mathics_list (
95+ * sorted (importexport .IMPORTERS .keys ()), elements_conversion_fn = String
96+ )
9697
9798
9899class RegisterImport (Builtin ):
@@ -238,7 +239,7 @@ def eval(
238239 # as well.
239240 # By doing this, we accept "text, "Text", "TEXT", and other combinations,
240241 # which what WMA seems to do.
241- IMPORTERS [formatname .value .upper ()] = (
242+ importexport . IMPORTERS [formatname .value .upper ()] = (
242243 conditionals ,
243244 default ,
244245 posts ,
@@ -455,15 +456,16 @@ def eval_source_only(self, source, evaluation, options={}):
455456 def eval_with_element_list (self , source , elements , evaluation , options = {}):
456457 "Import[source_, elements_List?(AllTrue[#, NotOptionQ]&), OptionsPattern[]]"
457458
458- findfile , data = import_setup_check (source , evaluation )
459+ findfile , file_format = import_setup_check (source , evaluation )
459460 if findfile is SymbolFailed :
460461 return SymbolFailed
461462
463+ # FIXME remove the need for determine_filetype
462464 def determine_filetype (data : str ) -> str :
463- return data
465+ return file_format
464466
465467 return eval_Import_general (
466- findfile , determine_filetype , elements , evaluation , options , data
468+ findfile , determine_filetype , elements , evaluation , options
467469 )
468470
469471 # In contrast to Import[source_], we allow an explicit format type
@@ -481,7 +483,7 @@ def eval_with_single_element(self, source, elt: String, evaluation, options={}):
481483 # The code below tests for the first case, and if that fails assumes the
482484 # second case.
483485 file_format = elt .value .upper ()
484- if file_format in IMPORTERS .keys ():
486+ if file_format in importexport . IMPORTERS .keys ():
485487 # A file format was specified: use the custom routine
486488 return eval_Import_source_only (findfile , file_format , evaluation , options )
487489
@@ -563,7 +565,7 @@ def eval_with_single_element(self, data, elt: String, evaluation, options={}):
563565 # The code below tests for the first case, and if that fails assumes the
564566 # second case.
565567 file_format = elt .value .upper ()
566- if file_format in IMPORTERS .keys ():
568+ if file_format in importexport . IMPORTERS .keys ():
567569 # A file format was specified: use the custom routine
568570 return eval_Import_data_only (data .value , file_format , evaluation , options )
569571
0 commit comments