11"""
22Functions for figuring out a filetype or MIME type a given
33file path.
4+
5+ Following WMA, we use WMA's custom short name for a mime type.
46"""
57
68import mimetypes
3739# convert these mismatches
3840MIME_SHORTNAME_TO_WMA : Final [Dict [str , str ]] = {"JPG" : "JPEG" , "TXT" : "Text" }
3941
42+ # FIXME: elements of the below dict should be a dataclass.
4043IMPORTERS = {}
4144
4245# TODO: This hard-coded dictionary should be
@@ -254,7 +257,7 @@ def eval_Import_general(
254257
255258 elements = [el .value for el in elements ]
256259
257- # Determine file format
260+ # Determine WMA version of the mime type.
258261 file_format = None
259262 for el in elements .copy ():
260263 if el .upper () in IMPORTERS .keys ():
@@ -270,7 +273,8 @@ def eval_Import_general(
270273 evaluation .predetermined_out = current_predetermined_out
271274 return SymbolFailed
272275
273- # Load the importer
276+ # Extract information about the loader used for this MIME type.
277+ # FIXME: turn into dataclass
274278 conditionals , import_function_symbol , posts , importer_options = IMPORTERS [
275279 file_format
276280 ]
@@ -419,11 +423,11 @@ def eval_Import_general(
419423
420424
421425def eval_Import_Elements (file_format : str , evaluation ):
422- """
423- Basic implementation behind Import[fileformat, Elements].
426+ """Basic implementation behind Import[fileformat, Elements].
427+
424428 This returns the element names that can be used for a specific
425- file_format type. We get this from the AvailableElements field
426- mentioned when registering an importer.
429+ file_format type. We get this from the
430+ AvailableElements field mentioned when registering an importer.
427431 """
428432 filetype = MIME_SHORTNAME_TO_WMA .get (file_format , file_format ).upper ()
429433
@@ -450,14 +454,23 @@ def perform_import(
450454 data : Optional [str ],
451455 elements : Optional [list ] = None ,
452456):
453- """
454- This routine does the data import.
457+ """ This routine does the import. "import" here means reading a \
458+ file or string which has been structured according to a format belonging to a mime type.
459+
455460 "findfile", if not "None", is the path of a file where the unimported data resides.
456- If findfile is empty, then "data" will have the string data for that file, and
461+ If " findfile" is empty, then "data" will have the string data for that file, and
457462 this routine will create a temporary file containing the data. The actual importer
458463 then uses this file.
459464
460- "elements" when given contains the parts or kinds of things that should be extracted.
465+ "elements", when given, contains the parts or kinds of things that should be extracted.
466+ Usually, there are custom routines for retrieving an element.
467+
468+ It is also possible that when a custom element extraction does not
469+ exist, that the caller will do the filtering after retrieving all of the information.
470+
471+ This is not advisable when the information inside an element is small compared
472+ to the information of the entire importable file. For example consider asking
473+ about the member names or contents of tar file compared to the entire tar file.
461474 """
462475 current_predetermined_out = evaluation .predetermined_out
463476 if function_channels == ListExpression (String ("FileNames" )):
0 commit comments