Skip to content

Commit 5dbe72d

Browse files
committed
Revise to fit better inside previous fileformats frameworks.
(I wasn't aware of this work until late on.)
1 parent 98e83bf commit 5dbe72d

16 files changed

Lines changed: 145 additions & 158 deletions

File tree

SYMBOLS_MANIFEST.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Compress`ImportZIP
12
HTML`DataImport
23
HTML`FullDataImport
34
HTML`HyperlinksImport
@@ -12,7 +13,7 @@ ImportExport`RegisterExport
1213
ImportExport`RegisterImport
1314
Internal`RealValuedNumberQ
1415
Internal`RealValuedNumericQ
15-
JSON`Import`JSONImport
16+
JSON`ImportJSON
1617
System`$Aborted
1718
System`$Assumptions
1819
System`$BaseDirectory
@@ -582,9 +583,7 @@ System`ImageTake
582583
System`ImageType
583584
System`Implies
584585
System`Import
585-
System`ImportJSON
586586
System`ImportString
587-
System`ImportZIP
588587
System`In
589588
System`Increment
590589
System`Indeterminate

mathics/SystemFiles/Formats/JSON/Import.wl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
(* ::Package:: *)
22

3+
(* JSON Javascript Object Notation or JSON web service description Importer.
4+
This is used by Import[] and, ImportString[].
5+
*)
6+
37
Begin["System`Convert`JSONDump`"]
48

59
(* JSON legacy element is Data even if Expression would be better. *)
610
$AvailableElements = {"Data", "Dataset"};
711

812
ImportExport`RegisterImport[
9-
"JSON",
10-
ImportJSON,
13+
"JSON", (* WMA mime-type name *)
14+
JSON`ImportJSON, (* Default Function name that handles this. *)
1115
{},
12-
"AvailableElements" -> $AvailableElements,
16+
"AvailableElements" -> $AvailableElements, (* names retuned by "Elements" query *)
1317
"FunctionChannels" -> {"FileNames"},
1418
"DefaultElement" -> "Data"
1519
]

mathics/SystemFiles/Formats/ZIP/Import.wl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(* ::Package:: *)
22

3-
(* ZIP compressed file and file archive Importer.
4-
This is used by Import[].
3+
(* Windows ZIP archive, ZIP compressed file and file archive Importer.
4+
This is used by Import[] and, ImportString[].
55
*)
66

77
Begin["System`Convert`CommonArchiveDump`"]
@@ -21,13 +21,13 @@ GetElements[___] :=
2121
];
2222

2323
ImportExport`RegisterImport[
24-
"ZIP",
25-
ImportZIP,
24+
"ZIP", (* WMA mime-type name *)
25+
Compress`ImportZIP, (* Default Function name that handles this. *)
2626
{}, (* Post importer function(s) *)
2727
FunctionChannels -> {"FileNames"},
2828
(* WMA has this, but I (rocky) am not sure why or what it means:
2929
AvailableElements -> $ZIPAvailableElements, *)
30-
AvailableElements -> {"Filenames", "Summary"},
30+
AvailableElements -> {"Filenames", "Summary"}, (* names retuned by "Elements" query *)
3131
BinaryFormat -> True,
3232
DefaultElement -> "FileNames",
3333
HiddenElements -> $ZIPHiddenElements,
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"""
2-
File Formats
2+
Import/Export File Formats
33
4-
Built-in Importers.
4+
There various file formats can be used by 'Import' and 'Export' and related functions, \
5+
e.g. 'ImportString'.
56
6-
"""
7+
Many Import/Export functions are registered in SystemFiles/Formats/*.wl which is \
8+
autoloaded on startup.
79
8-
# The Built-in Functions are defined in a separate context under the
9-
# System`. For example System`HTML` and System`XML. This is done to not
10-
# pollute the System` namespace.
10+
The Built-in Functions are defined in a separate context.
11+
For example, HTML` or Compress`. This is done to not pollute the System` namespace.
12+
"""
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Compression & Archive Formats
3+
"""
4+
5+
from mathics.core.builtin import Builtin, String
6+
from mathics.core.evaluation import Evaluation
7+
from mathics.eval.fileformats.compression import eval_ImportZIP
8+
9+
# See commit in __init__.py regarding the whacky way this gets called
10+
11+
12+
class ImportZIP(Builtin):
13+
"""
14+
<url>:WMA link:https://reference.wolfram.com/language/ref/format/ZIP.html</url>
15+
16+
<dl>
17+
<dt>'Compress`ImportZIP[path]'
18+
<dd>Run zip for archive file $path$
19+
</dl>
20+
21+
"""
22+
23+
context = "Compress`"
24+
summary_text = "import a ZIP file"
25+
26+
def eval(self, path: String, evaluation: Evaluation):
27+
"Compress`ImportZIP[path_String]"
28+
return eval_ImportZIP(path, evaluation)
29+
30+
def eval_with_elements(self, path: String, elements, evaluation: Evaluation):
31+
"Compress`ImportZIP[path_String, elements_]"
32+
return eval_ImportZIP(path, evaluation, elements)

mathics/builtin/fileformats/htmlformat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
HTML
44
5-
Basic implementation for a HTML importer.
5+
HTML importer.
66
"""
77

88

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
1-
# -*- coding: utf-8 -*-
2-
31
"""
4-
JSON
2+
JSON File Format
53
6-
Basic implementation for an JSON importer.
4+
JSON importer (via Python's "json" module).
75
"""
86

9-
from mathics.core.builtin import Builtin
10-
from mathics.core.expression import Evaluation
11-
from mathics.eval.fileformats.jsonformat import eval_JSONImport
7+
from mathics.core.builtin import Builtin, String
8+
from mathics.core.evaluation import Evaluation
9+
from mathics.eval.fileformats.json import eval_JSONImport
1210

1311

14-
class JSONImport(Builtin):
12+
class ImportJSON(Builtin):
1513
"""
16-
## <url>:native internal:</url>
14+
<url>:WMA link:https://reference.wolfram.com/language/ref/format/JSON.html</url>
1715
1816
<dl>
19-
<dt>'JSON`Import`JSONImport["file"]'
20-
<dd>parses "string" as a JSON file, and returns the data as a nested \
21-
list of rules.
17+
<dt>'JSON`ImportJSON[path]'
18+
<dd>Read $path$ as JSON and convert that to its corresponding Mathics3 equivalent.
2219
</dl>
2320
2421
"""
2522

26-
summary_text = "import elements from json"
27-
context = "JSON`Import`"
23+
context = "JSON`"
2824
messages = {"dec": "Decoding Error at `1`"}
25+
summary_text = "import JSON file"
2926

30-
def eval(self, filename, evaluation: Evaluation):
31-
"""%(name)s[filename_String]"""
32-
return eval_JSONImport(filename.value, evaluation)
27+
def eval(self, path: String, evaluation: Evaluation):
28+
"JSON`ImportJSON[path_String]"
29+
return eval_JSONImport(path, evaluation)

mathics/builtin/fileformats/xmlformat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
22

33
"""
4-
XML
4+
XML File Format
55
6-
Basic implementation for an XML importer.
6+
XML importer (via lxml).
77
"""
88

99

mathics/builtin/import_export/compression.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

mathics/builtin/import_export/json.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)