mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-25 00:34:19 +03:00
Get rid of broken JSON migration support (#1113)
This commit is contained in:
parent
0934f71c02
commit
70b08c4952
|
@ -1,8 +1,5 @@
|
|||
import datetime
|
||||
import json
|
||||
import os
|
||||
from base64 import b64decode
|
||||
from os.path import isfile as file_exists
|
||||
|
||||
from telethon.tl import types
|
||||
from .memory import MemorySession, _SentFileType
|
||||
|
@ -45,10 +42,6 @@ class SQLiteSession(MemorySession):
|
|||
if not self.filename.endswith(EXTENSION):
|
||||
self.filename += EXTENSION
|
||||
|
||||
# Migrating from .json -> SQL
|
||||
# TODO ^ Deprecate
|
||||
entities = self._check_migrate_json()
|
||||
|
||||
self._conn = None
|
||||
c = self._cursor()
|
||||
c.execute("select name from sqlite_master "
|
||||
|
@ -112,12 +105,6 @@ class SQLiteSession(MemorySession):
|
|||
)"""
|
||||
)
|
||||
c.execute("insert into version values (?)", (CURRENT_VERSION,))
|
||||
# Migrating from JSON -> new table and may have entities
|
||||
if entities:
|
||||
c.executemany(
|
||||
'insert or replace into entities values (?,?,?,?,?)',
|
||||
entities
|
||||
)
|
||||
self._update_session_table()
|
||||
c.close()
|
||||
self.save()
|
||||
|
@ -127,29 +114,6 @@ class SQLiteSession(MemorySession):
|
|||
cloned.save_entities = self.save_entities
|
||||
return cloned
|
||||
|
||||
def _check_migrate_json(self):
|
||||
if file_exists(self.filename):
|
||||
try:
|
||||
with open(self.filename, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
self.delete() # Delete JSON file to create database
|
||||
|
||||
self._port = data.get('port', self._port)
|
||||
self._server_address = \
|
||||
data.get('server_address', self._server_address)
|
||||
|
||||
if data.get('auth_key_data', None) is not None:
|
||||
key = b64decode(data['auth_key_data'])
|
||||
self._auth_key = AuthKey(data=key)
|
||||
|
||||
rows = []
|
||||
for p_id, p_hash in data.get('entities', []):
|
||||
if p_hash is not None:
|
||||
rows.append((p_id, p_hash, None, None, None))
|
||||
return rows
|
||||
except UnicodeDecodeError:
|
||||
return [] # No entities
|
||||
|
||||
def _upgrade_database(self, old):
|
||||
c = self._cursor()
|
||||
if old == 1:
|
||||
|
|
Loading…
Reference in New Issue
Block a user