File tree 2 files changed +18
-2
lines changed
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 1
1
import base64
2
2
import codecs
3
3
import hashlib
4
+ import io
4
5
import logging
5
6
import re
6
7
import zlib
7
8
from binascii import Error as BinasciiError
8
9
from collections import OrderedDict
9
10
from copy import deepcopy
10
- from io import BytesIO
11
11
12
12
from construct import (
13
13
Adapter ,
@@ -128,6 +128,8 @@ def compute_key_composite(password=None, keyfile=None):
128
128
# hash the keyfile
129
129
if keyfile :
130
130
if hasattr (keyfile , "read" ):
131
+ if hasattr (keyfile , "seekable" ) and keyfile .seekable ():
132
+ keyfile .seek (0 )
131
133
keyfile_bytes = keyfile .read ()
132
134
else :
133
135
with open (keyfile , 'rb' ) as f :
@@ -194,7 +196,7 @@ class XML(Adapter):
194
196
195
197
def _decode (self , data , con , path ):
196
198
parser = etree .XMLParser (remove_blank_text = True )
197
- return etree .parse (BytesIO (data ), parser )
199
+ return etree .parse (io . BytesIO (data ), parser )
198
200
199
201
def _encode (self , tree , con , path ):
200
202
return etree .tostring (tree )
Original file line number Diff line number Diff line change @@ -875,6 +875,20 @@ def test_fields(self):
875
875
876
876
877
877
class PyKeePassTests3 (KDBX3Tests ):
878
+ def test_consecutives_saves_with_stream (self ):
879
+ # https://github.com/libkeepass/pykeepass/pull/388
880
+ self .setUp ()
881
+
882
+ with open (base_dir / self .keyfile_tmp , 'rb' ) as f :
883
+ keyfile = BytesIO (f .read ())
884
+
885
+ for _i in range (5 ):
886
+ with PyKeePass (
887
+ base_dir / self .database_tmp ,
888
+ password = self .password ,
889
+ keyfile = keyfile ,
890
+ ) as kp :
891
+ kp .save ()
878
892
879
893
def test_set_credentials (self ):
880
894
self .kp_tmp .password = 'f00bar'
You can’t perform that action at this time.
0 commit comments