Skip to content

Commit 1449a43

Browse files
committed
Fixed serialization
Changelog
1 parent 55240fd commit 1449a43

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

docs/source/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Glossary
3737
Releases
3838
---------------------
3939

40+
v4.0.1
41+
====================
42+
- Fixed remote serialization of regex and time.
43+
4044
v4.0.0
4145
===================
4246
- New automatic message responder (DM and guild) - :ref:`Automatic responder`.

src/daf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import warnings
2323

2424

25-
VERSION = "4.0.0"
25+
VERSION = "4.0.1"
2626

2727

2828
if sys.version_info.minor == 12 and sys.version_info.major == 3:

src/daf/convert.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from typing import Union, Any, Mapping
77
from contextlib import suppress
8-
from enum import Enum
8+
from enum import Enum, Flag
99
from inspect import isclass, isfunction, signature, _empty
1010

1111
from daf.logging.tracing import TraceLEVELS, trace
@@ -15,6 +15,7 @@
1515
import copy
1616
import asyncio
1717
import datetime
18+
import re
1819

1920
import _discord as discord
2021

@@ -123,6 +124,10 @@ def import_class(path: str):
123124
"custom_encoder": lambda object: object.total_seconds(),
124125
"custom_decoder": lambda seconds: datetime.timedelta(seconds=seconds)
125126
},
127+
datetime.time: {
128+
"custom_encoder": lambda object: object.isoformat(),
129+
"custom_decoder": lambda string: datetime.time.fromisoformat(string)
130+
},
126131
bytes: {
127132
"custom_encoder": lambda data: data.hex(),
128133
"custom_decoder": lambda hex_str: bytes.fromhex(hex_str)
@@ -146,8 +151,13 @@ def import_class(path: str):
146151
},
147152
discord.VoiceChannel: {
148153
"attrs": ["name", "id"],
154+
},
155+
re.Pattern: {
156+
"custom_encoder": lambda data: {"pattern": convert_object_to_semi_dict(data.pattern), "flags": data.flags},
157+
"custom_decoder": lambda data: re.compile(data["pattern"], data.get("flags", 0))
149158
}
150159
}
160+
151161
"""
152162
This is a custom conversion dictionary.
153163
It's values are datatypes of objects which cannot be normally converted to JSON, so custom rules are required.
@@ -367,7 +377,7 @@ def _convert_json_slots(to_convert):
367377
to_convert = [convert_object_to_semi_dict(value) for value in to_convert]
368378
return to_convert
369379

370-
if isinstance(to_convert, Enum):
380+
if isinstance(to_convert, (Enum, Flag)):
371381
return {"enum_type": f"{object_type.__module__}.{object_type.__name__}", "value": to_convert.value}
372382

373383
# Class itself, not an actual instance. Can also be function as it only imports.

src/daf/logic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def pattern(self):
170170

171171
@property
172172
def flags(self):
173-
return self._compiled.flags
173+
return re.RegexFlag(self._compiled.flags)
174174

175175
@property
176176
def full_match(self):

0 commit comments

Comments
 (0)