Skip to content

Commit

Permalink
Make sure ipv4/ipv6 interface gets loaded back correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicaj committed Oct 30, 2024
1 parent ecc7cce commit 6f98c6d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions truenas_api_client/ejson.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ def default(self, obj):
return {'$time': str(obj)}
elif isinstance(obj, set):
return {'$set': list(obj)}
elif isinstance(obj, (IPv4Interface, IPv6Interface)):
return str(obj)
elif isinstance(obj, IPv4Interface):
return {'$ipv4_interface': str(obj)}
elif isinstance(obj, IPv6Interface):
return {'$ipv6_interface': str(obj)}
return super(JSONEncoder, self).default(obj)


Expand All @@ -69,6 +71,10 @@ def object_hook(obj: dict):
return time(*[int(i) for i in obj['$time'].split(':')[:4]]) # type: ignore
if '$set' in obj:
return set(obj['$set'])
if '$ipv4_interface' in obj:
return IPv4Interface(obj['$ipv4_interface'])
if '$ipv6_interface' in obj:
return IPv6Interface(obj['$ipv6_interface'])
if obj_len == 2 and '$type' in obj and '$value' in obj:
if obj['$type'] == 'date':
return date(*[int(i) for i in obj['$value'].split('-')])
Expand Down

0 comments on commit 6f98c6d

Please sign in to comment.