1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Merge pull request #786 from Badiboy/master

Possibility to use alternative serializer
This commit is contained in:
Badiboy 2020-04-11 16:52:53 +03:00 committed by GitHub
commit 36a228da92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -76,7 +76,10 @@ class Saver:
os.makedirs(dirs, exist_ok=True)
with open(filename + ".tmp", file_mode) as file:
pickle.dump(handlers, file)
if (apihelper.CUSTOM_SERIALIZER is None):
pickle.dump(handlers, file)
else:
apihelper.CUSTOM_SERIALIZER.dump(handlers, file)
if os.path.isfile(filename):
os.remove(filename)
@ -87,7 +90,10 @@ class Saver:
def return_load_handlers(filename, del_file_after_loading=True):
if os.path.isfile(filename) and os.path.getsize(filename) > 0:
with open(filename, "rb") as file:
handlers = pickle.load(file)
if (apihelper.CUSTOM_SERIALIZER is None):
handlers = pickle.load(file)
else:
handlers = apihelper.CUSTOM_SERIALIZER.load(file)
if del_file_after_loading:
os.remove(filename)

View File

@ -18,6 +18,7 @@ from telebot import types
from telebot import util
logger = telebot.logger
proxy = None
API_URL = None
@ -26,6 +27,8 @@ FILE_URL = None
CONNECT_TIMEOUT = 3.5
READ_TIMEOUT = 9999
CUSTOM_SERIALIZER = None
ENABLE_MIDDLEWARE = False