Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
voschezang committed Jun 18, 2023
1 parent e291f90 commit e7cf9b6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/examples/rest_client_implicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from json import JSONDecodeError, loads
from urllib.parse import quote_plus, urlparse
from examples.rest_client_explicit import init_client
from mash.io_util import log

from mash.shell import ShellWithFileSystem
from mash.shell.shell import main
Expand Down Expand Up @@ -52,11 +53,14 @@ def get(url):

# query a mock server
data = init_client().get(urlparse(url).path)
if data.status_code != 200:
return f'{data._status} ({data.status_code})'

try:
data = loads(data.data)
except JSONDecodeError as e:
print(e)
log('JSONDecodeError:', e, data.data)
return f'"{data.data.decode()}"'

if isinstance(data, list):
return {k: http_resource for k in data}
Expand Down
1 change: 0 additions & 1 deletion src/mash/filesystem/discoverable.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def snapshot(self, filename=default_snapshot_filename) -> bytes:
f.write(dumps((self.root, self.initial_values, self.home)))

def load(self, filename=default_snapshot_filename):
print('load', filename)
with open(filename, 'rb') as f:
root, self.initial_values, home = loads(f.read())

Expand Down
3 changes: 3 additions & 0 deletions src/mash/filesystem/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ def set(self, k, value: Data, cwd: View = None):
self.cd('-')
self.cd(*path)

def show(self, *path: str):
return self.get(path)

def append(self, k, v):
"""Associate key k with value v and then change the working directory to k
"""
Expand Down
7 changes: 7 additions & 0 deletions src/mash/shell/grammer/parse_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ def to_string(value: Any) -> str:

elif isinstance(value, dict):
result = {}
if isinstance(next(iter(value.values())), dict):
try:
table = pd.DataFrame(value)
return table.T.to_markdown()
except ValueError:
pass

for k, v in value.items():
if isinstance(v, dict):
result[k] = dict_to_string(v)
Expand Down

0 comments on commit e7cf9b6

Please sign in to comment.