[avm] Gzip don't support unicode strings. Fixes #4254
This commit is contained in:
parent
9adc632d67
commit
a4bab043b9
|
@ -707,21 +707,26 @@ class Logger:
|
||||||
# get data from table
|
# get data from table
|
||||||
# the data field contains binary object (gzipped data), this is a hack
|
# the data field contains binary object (gzipped data), this is a hack
|
||||||
# to get that data without trying to convert it to unicode
|
# to get that data without trying to convert it to unicode
|
||||||
#tmp, self.con.text_factory = self.con.text_factory, str
|
|
||||||
try:
|
try:
|
||||||
self.cur.execute('SELECT hash_method, hash, data FROM caps_cache;');
|
self.cur.execute('SELECT hash_method, hash, data FROM caps_cache;');
|
||||||
except sqlite.OperationalError:
|
except sqlite.OperationalError:
|
||||||
# might happen when there's no caps_cache table yet
|
# might happen when there's no caps_cache table yet
|
||||||
# -- there's no data to read anyway then
|
# -- there's no data to read anyway then
|
||||||
#self.con.text_factory = tmp
|
|
||||||
return
|
return
|
||||||
#self.con.text_factory = tmp
|
|
||||||
|
# list of corrupted entries that will be removed
|
||||||
|
to_be_removed = []
|
||||||
for hash_method, hash, data in self.cur:
|
for hash_method, hash, data in self.cur:
|
||||||
# for each row: unpack the data field
|
# for each row: unpack the data field
|
||||||
# (format: (category, type, name, category, type, name, ...
|
# (format: (category, type, name, category, type, name, ...
|
||||||
# ..., 'FEAT', feature1, feature2, ...).join(' '))
|
# ..., 'FEAT', feature1, feature2, ...).join(' '))
|
||||||
# NOTE: if there's a need to do more gzip, put that to a function
|
# NOTE: if there's a need to do more gzip, put that to a function
|
||||||
|
try:
|
||||||
data = GzipFile(fileobj=StringIO(str(data))).read().split('\0')
|
data = GzipFile(fileobj=StringIO(str(data))).read().split('\0')
|
||||||
|
except IOError:
|
||||||
|
# This data is corrupted. It probably contains non-ascii chars
|
||||||
|
to_be_removed.append((hash_method, hash))
|
||||||
|
continue
|
||||||
i=0
|
i=0
|
||||||
identities = list()
|
identities = list()
|
||||||
features = list()
|
features = list()
|
||||||
|
@ -740,6 +745,9 @@ class Logger:
|
||||||
|
|
||||||
# yield the row
|
# yield the row
|
||||||
yield hash_method, hash, identities, features
|
yield hash_method, hash, identities, features
|
||||||
|
for hash_method, hash in to_be_removed:
|
||||||
|
sql = 'DELETE FROM caps_cache WHERE hash_method = "%s" AND hash = "%s"' % (hash_method, hash)
|
||||||
|
self.simple_commit(sql)
|
||||||
|
|
||||||
def add_caps_entry(self, hash_method, hash, identities, features):
|
def add_caps_entry(self, hash_method, hash, identities, features):
|
||||||
data=[]
|
data=[]
|
||||||
|
@ -755,6 +763,7 @@ class Logger:
|
||||||
# if there's a need to do more gzip, put that to a function
|
# if there's a need to do more gzip, put that to a function
|
||||||
string = StringIO()
|
string = StringIO()
|
||||||
gzip = GzipFile(fileobj=string, mode='w')
|
gzip = GzipFile(fileobj=string, mode='w')
|
||||||
|
data = str(data) # the gzip module can't handle unicode objects
|
||||||
gzip.write(data)
|
gzip.write(data)
|
||||||
gzip.close()
|
gzip.close()
|
||||||
data = string.getvalue()
|
data = string.getvalue()
|
||||||
|
|
Loading…
Reference in New Issue