Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include README.rst
include CHANGES.rst
include CHANGES.md
include ChangeLog
include COPYING.txt
include FUTURE.rst
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ Mathics3 is released under the GNU General Public License Version 3 (GPL3).
:target: https://badge.fury.io/py/Mathics3
.. |PyPI Installs| image:: https://pepy.tech/badge/Mathics3
.. |Supported Python Versions| image:: https://img.shields.io/pypi/pyversions/Mathics3.svg
.. |Packaging status| image:: https://repology.org/badge/vertical-allrepos/mathics.svg
:target: https://repology.org/project/mathics/versions
.. |Packaging status| image:: https://repology.org/badge/vertical-allrepos/mathics3.svg
:target: https://repology.org/project/mathics3/versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(* ::Package:: *)

Begin["System`Convert`B64Dump`"]

Expand All @@ -21,6 +22,7 @@
FunctionChannels -> {"FileNames"},
Options -> {"CharacterEncoding", "ByteOrderMark"},
DefaultElement -> "Plaintext",
Encoding -> True
BinaryFormat -> False
]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(* ::Package:: *)

Begin["System`Convert`B64Dump`"]


Expand All @@ -21,6 +23,7 @@
FunctionChannels -> {"FileNames"},
AvailableElements -> {"Data"},
DefaultElement -> "Data",
Encoding -> True
Options -> {
"CharacterEncoding"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(* ::Package:: *)

(* CSV Exporter *)

Begin["System`Convert`TableDump`"]
Expand All @@ -8,7 +10,7 @@
};

CSVExport[strm_OutputStream, data_, OptionsPattern[]]:=
Module[{char, wraplist, sep = OptionValue["FieldSeparators"]},
Module[{char, wraplist, sep = OptionValue["FieldSeparators"]},
If[strm === $Failed, Return[$Failed]];
wraplist[x_] := If[Head[x] === List, x, {x}];
char = Map[ToString, wraplist /@ wraplist[data], {2}];
Expand All @@ -21,7 +23,7 @@
System`Convert`TableDump`CSVExport,
FunctionChannels -> {"Streams"},
Options -> {"ByteOrderMark"},
DefaultElement -> "Plaintext",
DefaultElement -> "Data",
BinaryFormat -> False,
Options -> {
"CharacterEncoding",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(* ::Package:: *)

(* CSV Importer *)

Begin["System`Convert`TableDump`"]
Expand All @@ -23,12 +25,13 @@
System`Convert`TableDump`ImportCSV,
{
"Data" :> GetData,
"Grid" :> GetGrid
"Grid" :> GetGrid
},
(* Sources -> ImportExport`DefaultSources["Table"], *)
FunctionChannels -> {"Streams"},
AvailableElements -> {"Data", "Grid"},
DefaultElement -> "Data",
BinaryFormat -> False,
Options -> {
"CharacterEncoding",
"FieldSeparators"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Begin["System`Convert`TextDump`"]


SVGExport[filename_, expr_, opts___] :=
Module[{strm, data, p, q, expr2},
SVGExport[filename_, expr_, opts___] :=
Module[{strm, data, p, q, expr2},
strm = OpenWrite[filename];
If[strm === $Failed, Return[$Failed]];
expr2 = If[Head[expr]=!=System`Graphics, System`Graphics[{System`Inset[ToString[expr]]}], expr];
Expand Down
12 changes: 12 additions & 0 deletions mathics/SystemFiles/Formats/ZIP/Import.wl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(* ZIP compressed file and file archive Importer *)

Begin["System`ZIP`"]
ImportExport`RegisterImport[
"ZIP",
ImportZip,
FunctionChannels -> {"Streams"},
AvailableElements -> {"FileNames", "Summary"},
DefaultElement -> "FileNames"
]

End[]
12 changes: 7 additions & 5 deletions mathics/builtin/files_io/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ class FilePrint(Builtin):
expected_args = (1, 2)
messages = {
"zstr": ("The file name cannot be an empty string."),
"badfile": ("The specified argument, `1`, should be a valid string."),
}

options = {
Expand All @@ -283,6 +282,7 @@ class FilePrint(Builtin):
def eval(self, path, evaluation: Evaluation, options: dict):
"FilePrint[path_, OptionsPattern[FilePrint]]"

# TODO also check for File.
if not isinstance(path, String):
evaluation.message("FilePrint", "badfile", path)
return
Expand Down Expand Up @@ -675,7 +675,7 @@ def eval_input(self, exprs, name, n, evaluation: Evaluation):
stream = stream_manager.lookup_stream(n.get_int_value())

if stream is None or stream.io.closed:
evaluation.message("Put", "openx", get_eval_Expression())
evaluation.message("Put", "openx", evaluation.current_expression)
return

# In Mathics3-server, evaluation.format_output is modified.
Expand Down Expand Up @@ -772,7 +772,7 @@ def eval_input(self, exprs, name, n, evaluation: Evaluation):
stream = stream_manager.lookup_stream(n.get_int_value())

if stream is None or stream.io.closed:
evaluation.message("Put", "openx", get_eval_Expression())
evaluation.message("Put", "openx", evaluation.current_expression)
return

text = [
Expand Down Expand Up @@ -1187,7 +1187,7 @@ def eval_n(self, file, types, n: Integer, evaluation: Evaluation, options: dict)

py_n = n.value
if py_n < 0:
evaluation.message("ReadList", "intnm", get_eval_Expression())
evaluation.message("ReadList", "intnm", evaluation.current_expression)
return

result = []
Expand Down Expand Up @@ -1298,7 +1298,9 @@ def eval_input(self, name, n, m, evaluation):

seekpos = m.to_python()
if not (isinstance(seekpos, int) or seekpos == float("inf")):
evaluation.message("SetStreamPosition", "stmrng", get_eval_Expression(), m)
evaluation.message(
"SetStreamPosition", "stmrng", evaluation.current_expression, m
)
return

try:
Expand Down
44 changes: 19 additions & 25 deletions mathics/builtin/files_io/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pathlib
import re
import shutil
from typing import List
from typing import List, Optional

from mathics.builtin.files_io.files import Mathics3Open
from mathics.core.atoms import Integer, String
Expand All @@ -20,7 +20,7 @@
from mathics.core.convert.regex import to_regex
from mathics.core.evaluation import Evaluation
from mathics.core.expression import Expression
from mathics.core.streams import create_temporary_file, path_search, urlsave_tmp
from mathics.core.streams import create_temporary_file, urlsave_tmp
from mathics.core.symbols import (
Symbol,
SymbolFalse,
Expand All @@ -36,6 +36,7 @@
)
from mathics.eval.directories import DIRECTORY_STACK
from mathics.eval.files_io.files import eval_Get
from mathics.eval.files_io.filesystem import eval_FindFile
from mathics.eval.stackframe import get_eval_Expression


Expand All @@ -62,21 +63,20 @@ def eval(self, name, evaluation):
py_name = name.to_python()

if not isinstance(py_name, str):
evaluation.message("AbsoluteFileName", "fstr", name)
evaluation.message("AbsoluteFileName", "badfile", name)
return

if py_name[0] == py_name[-1] == '"':
py_name = py_name[1:-1]

result, _ = path_search(py_name)

result = eval_FindFile(py_name)
if result is None:
evaluation.message(
"AbsoluteFileName", "nffil", to_expression("AbsoluteFileName", name)
)
return SymbolFailed

return String(osp.abspath(result))
return result


class CopyDirectory(Builtin):
Expand Down Expand Up @@ -173,7 +173,7 @@ def eval(self, source, dest, evaluation):
if py_dest[0] == py_dest[-1] == '"':
py_dest = py_dest[1:-1]

py_source, _ = path_search(py_source)
py_source = eval_FindFile(py_source)

if py_source is None:
evaluation.message("CopyFile", "filex", source)
Expand All @@ -184,7 +184,7 @@ def eval(self, source, dest, evaluation):
return SymbolFailed

try:
shutil.copy(py_source, py_dest)
shutil.copy(py_source.value, py_dest)
except IOError:
evaluation.message("CopyFile", "nffil", get_eval_Expression())
return SymbolFailed
Expand Down Expand Up @@ -300,12 +300,12 @@ def eval(self, filename, evaluation):

if path[0] == path[-1] == '"':
path = path[1:-1]
path, _ = path_search(path)
resolved_path = eval_FindFile(path)

if path is None:
if resolved_path is None:
evaluation.message("DeleteFile", "nffil", get_eval_Expression())
return SymbolFailed
py_paths.append(path)
py_paths.append(resolved_path.value)

for path in py_paths:
try:
Expand Down Expand Up @@ -355,7 +355,6 @@ class DirectoryStack(Builtin):

def eval(self, evaluation):
"DirectoryStack[]"
global DIRECTORY_STACK
return from_python(DIRECTORY_STACK)


Expand Down Expand Up @@ -504,19 +503,16 @@ class FileExistsQ(Builtin):
}
summary_text = "test whether a file exists"

def eval(self, filename, evaluation):
def eval(self, filename, evaluation) -> Optional[Symbol]:
"FileExistsQ[filename_]"
path = filename.to_python()
if not (isinstance(path, str) and path[0] == path[-1] == '"'):
evaluation.message("FileExistsQ", "fstr", filename)
return
path = path[1:-1]

path, is_temporary_file = path_search(path)

if path is None:
return SymbolFalse
return SymbolTrue
resolved_path = eval_FindFile(path)
return SymbolFalse if resolved_path is None else SymbolTrue


class FileExtension(Builtin):
Expand Down Expand Up @@ -606,12 +602,10 @@ def eval(self, name, evaluation):
return
py_name = py_name[1:-1]

result, is_temporary_file = path_search(py_name)

result = eval_FindFile(py_name)
if result is None:
return SymbolFailed

return String(osp.abspath(result))
return result


class FileNames(Builtin):
Expand Down Expand Up @@ -983,9 +977,9 @@ def eval(self, source, dest, evaluation):
py_source = py_source[1:-1]
py_dest = py_dest[1:-1]

py_source, _ = path_search(py_source)
resolved_source = eval_FindFile(py_source)

if py_source is None:
if resolved_source is None:
evaluation.message("RenameFile", "filex", source)
return SymbolFailed

Expand All @@ -994,7 +988,7 @@ def eval(self, source, dest, evaluation):
return SymbolFailed

try:
shutil.move(py_source, py_dest)
shutil.move(resolved_source.value, py_dest)
except IOError:
evaluation.message("RenameFile", "nffil", dest)
return SymbolFailed
Expand Down
Loading
Loading