-
Notifications
You must be signed in to change notification settings - Fork 240
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
2 changed files
with
26 additions
and
23 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
modules/scala/almond-scalapy/src/main/resources/format_display_data.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import json | ||
|
||
|
||
def format_display_data(obj, include): | ||
repr_methods = ((t, m) for m, t in include if m in set(dir(obj))) | ||
representations = ((t, getattr(obj, m)()) for t, m in repr_methods) | ||
|
||
display_data = ( | ||
(t, (r[0], r[1]) if isinstance(r, tuple) and len(r) == 2 else (r, None)) | ||
for t, r in representations if r is not None | ||
) | ||
display_data = [(t, m, md) for t, (m, md) in display_data if m is not None] | ||
|
||
data = [ | ||
(t, d if isinstance(d, str) else json.dumps(d)) | ||
for t, d, _ in display_data | ||
] | ||
metadata = [ | ||
(t, md if isinstance(md, str) else json.dumps(md)) | ||
for t, _, md in display_data if md is not None | ||
] | ||
|
||
return data, metadata |
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