forked from dafny-lang/dafny
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 35 additions & 3 deletions
38
Source/DafnyStandardLibraries/src/DafnyStdLibs_FileIOInternalExterns.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,37 @@ | ||
# Module: DafnyStdLibs_FileIOInternalExterns | ||
|
||
@staticmethod | ||
def INTERNAL_ReadBytesFromFile(i): | ||
return i * i | ||
import traceback | ||
import os | ||
import os.path | ||
import _dafny | ||
|
||
class default__: | ||
@staticmethod | ||
def INTERNAL__ReadBytesFromFile(path): | ||
path_str = path.VerbatimString(False) | ||
try: | ||
with open(path_str, mode="rb") as file: | ||
contents = file.read() | ||
contents_seq = _dafny.Seq(contents) | ||
return (False, contents_seq, None) | ||
except: | ||
exc_str = traceback.format_exc() | ||
exc_seq = _dafny.Seq(exc_str) | ||
return (True, None, exc_seq) | ||
|
||
@staticmethod | ||
def INTERNAL__WriteBytesToFile(path, contents): | ||
path_str = path.VerbatimString(False) | ||
contents_bytes = bytes(contents) | ||
|
||
try: | ||
os.makedirs(os.path.basename(path_str), exist_ok=True) | ||
|
||
with open(path_str, mode="wb") as file: | ||
contents = file.write(contents_bytes) | ||
return (False, None) | ||
except: | ||
exc_str = traceback.format_exc() | ||
exc_seq = _dafny.Seq(exc_str) | ||
return (True, exc_seq) | ||
|