1
1
from contextlib import suppress
2
2
from hashlib import md5
3
- from io import BytesIO
4
- from logging import debug , info
3
+ from logging import debug
5
4
from os import close , remove
6
5
from tempfile import mkstemp
7
6
@@ -15,16 +14,18 @@ def _hash_of_bytes(bytes_):
15
14
hash_ .update (bytes_ )
16
15
return hash_ .hexdigest ()
17
16
18
- class SQLiteUploadDialect (SQLiteDialect_pysqlite ):
17
+ class SQLiteUploadDialect (SQLiteDialect_pysqlite ): # pylint: disable=abstract-method
19
18
20
19
def __init__ (self , * args , ** kw ):
21
20
super ().__init__ (* args , ** kw )
22
21
handle , self ._localPath = mkstemp ()
23
22
close (handle )
24
23
self ._localHash = None
25
24
debug (f"localPath: { self ._localPath } " )
25
+ self ._remoteFilename = None
26
+ self ._fs = None
26
27
27
- def close (self , * args , ** kwargs ):
28
+ def close (self , * args , ** kwargs ): # pylint: disable=unused-argument
28
29
with open (self ._localPath , "rb" ) as f :
29
30
bytes_ = f .read ()
30
31
@@ -40,8 +41,8 @@ def connect(self, *args, **kw):
40
41
self ._load_remote_db (uploadUrl )
41
42
return super ().connect (self ._localPath , ** kw )
42
43
43
- def do_close (self , * args , ** kw ):
44
- out = super ().do_close (* args , ** kw )
44
+ def do_close (self , dbapi_connection ):
45
+ out = super ().do_close (dbapi_connection )
45
46
self .close ()
46
47
return out
47
48
@@ -50,7 +51,7 @@ def _load_remote_db(self, remotePath):
50
51
fsurl = remotePath [:lastSeparator ]
51
52
self ._remoteFilename = remotePath [lastSeparator + 1 :]
52
53
self ._fs = open_fs (fsurl )
53
-
54
+
54
55
try :
55
56
remoteBytes = self ._fs .readbytes (self ._remoteFilename )
56
57
with open (self ._localPath , "wb" ) as localFile : # truncate any existing files
@@ -63,7 +64,8 @@ def _load_remote_db(self, remotePath):
63
64
remove (self ._localPath )
64
65
self ._localHash = None
65
66
66
- urlScheme = "sqliteupload"
67
-
68
67
def RegisterDialect ():
69
- registry .register (urlScheme , "sqliteupload.dialect" , SQLiteUploadDialect .__name__ )
68
+ registry .register (
69
+ name = "sqliteupload" ,
70
+ modulepath = "sqliteupload.dialect" ,
71
+ objname = SQLiteUploadDialect .__name__ )
0 commit comments