Skip to content

Commit 58a47a0

Browse files
committed
fix in ImportString and ExportString
1 parent 13cda03 commit 58a47a0

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

mathics/builtin/importexport.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,9 @@ class ImportString(Import):
841841
rules = {
842842
}
843843

844+
options = {
845+
'$OptionSyntax': 'System`Ignore',
846+
}
844847

845848
def apply(self, data, evaluation, options={}):
846849
'ImportString[data_, OptionsPattern[]]'
@@ -1013,8 +1016,8 @@ class Export(Builtin):
10131016
'$OptionSyntax': 'System`Ignore',
10141017
}
10151018

1016-
def apply(self, filename, expr, evaluation, options={}):
1017-
"Export[filename_, expr_, OptionsPattern[]]"
1019+
def apply(self, filename, expr, evaluation, **options):
1020+
"Export[filename_, expr_, OptionsPattern[Export]]"
10181021

10191022
# Check filename
10201023
if not self._check_filename(filename, evaluation):
@@ -1082,7 +1085,6 @@ def apply_elements(self, filename, expr, elems, evaluation, options={}):
10821085
# Load the exporter
10831086
exporter_symbol, exporter_options = EXPORTERS[format_spec[0]]
10841087
function_channels = exporter_options.get("System`FunctionChannels")
1085-
10861088
stream_options, custom_options = _importer_exporter_options(
10871089
exporter_options.get("System`Options"), options, 'System`Export', evaluation)
10881090

@@ -1147,6 +1149,9 @@ class ExportString(Builtin):
11471149
>> ExportString[Integrate[f[x],{x,0,2}], "SVG"]
11481150
= ...
11491151
"""
1152+
options = {
1153+
'$OptionSyntax': 'System`Ignore',
1154+
}
11501155

11511156
messages = {
11521157
'noelem': "`1` is not a valid set of export elements for the `2` format.",
@@ -1159,15 +1164,14 @@ class ExportString(Builtin):
11591164
}
11601165

11611166

1162-
def apply_element(self, expr, element, evaluation, options={}):
1163-
'ExportString[expr_, element_String, OptionsPattern[]]'
1164-
return self.apply_elements(expr, Expression('List', element), evaluation, options)
1167+
def apply_element(self, expr, element, evaluation, **options):
1168+
'ExportString[expr_, element_String, OptionsPattern[ExportString]]'
1169+
return self.apply_elements(expr, Expression('List', element), evaluation, **options)
11651170

1166-
def apply_elements(self, expr, elems, evaluation, options={}):
1167-
"ExportString[expr_, elems_List?(AllTrue[#, NotOptionQ]&), OptionsPattern[]]"
1168-
# Process elems {comp* format?, elem1*}
1171+
def apply_elements(self, expr, elems, evaluation, **options):
1172+
"ExportString[expr_, elems_List?(AllTrue[#, NotOptionQ]&), OptionsPattern[ExportString]]"
1173+
# Process elems {comp* format?, elem1*}
11691174
leaves = elems.get_leaves()
1170-
11711175
format_spec, elems_spec = [], []
11721176
found_form = False
11731177
for leaf in leaves[::-1]:
@@ -1217,7 +1221,7 @@ def apply_elements(self, expr, elems, evaluation, options={}):
12171221
elif function_channels == Expression('List', String('FileNames')):
12181222
# Generates a temporary file
12191223
import tempfile
1220-
tmpfile = tempfile.NamedTemporaryFile(dir=tempfile.gettempdir())
1224+
tmpfile = tempfile.NamedTemporaryFile(dir=tempfile.gettempdir(),suffix="."+format_spec[0].lower())
12211225
filename = String(tmpfile.name)
12221226
tmpfile.close()
12231227
exporter_function = Expression(

0 commit comments

Comments
 (0)