Skip to content

Commit

Permalink
add direntry handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Almenon committed Jun 16, 2019
1 parent 7281bdd commit 5e7c117
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion python/custom_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from jsonpickle.handlers import BaseHandler
from types import FrameType
from types import CodeType
from os import DirEntry

NOT_SERIALIZABLE_MESSAGE = "not serializable by arepl"

Expand All @@ -18,6 +19,14 @@ def flatten(self, obj, data):
x = float(obj)
return x

class DirEntryHandler(BaseHandler):
def flatten(self, obj, data):
return {
"py/object": "nt.DirEntry",
"name": obj.name,
"path": obj.path
}

class regexMatchHandler(BaseHandler):
### better represention of datetime, see https://github.com/jsonpickle/jsonpickle/issues/109 ###
def flatten(self, obj, data):
Expand Down Expand Up @@ -76,5 +85,6 @@ def flatten(self, obj, data):
{'type': type(re.search('', '')), 'handler': regexMatchHandler},
{'type': FrameType, 'handler': frameHandler},
{'type': CodeType, 'handler': codeHandler},
{'type': decimal.Decimal, 'handler': DecimalHandler}
{'type': decimal.Decimal, 'handler': DecimalHandler},
{'type': DirEntry, 'handler': DirEntryHandler}
]

1 comment on commit 5e7c117

@Almenon
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #94

Please sign in to comment.