mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
Fixing up encoders
This commit is contained in:
parent
a43d6af237
commit
4cf62de3fd
@ -96,9 +96,9 @@ class AutoAttributes(Serializable):
|
|||||||
return
|
return
|
||||||
# We keep original data (maybe incomplete)
|
# We keep original data (maybe incomplete)
|
||||||
try:
|
try:
|
||||||
data = encoders.decode_bz2(data)
|
data = encoders.decode(data, 'bzip2')
|
||||||
except Exception: # With old zip encoding
|
except Exception: # With old zip encoding
|
||||||
data = encoders.decode_zip(data)
|
data = encoders.decode(data, 'zip')
|
||||||
for pair in data.split('\2'):
|
for pair in data.split('\2'):
|
||||||
k, v = pair.split('\1')
|
k, v = pair.split('\1')
|
||||||
self.dict[k] = pickle.loads(str(v))
|
self.dict[k] = pickle.loads(str(v))
|
||||||
|
@ -50,6 +50,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class FileStorage(Storage):
|
class FileStorage(Storage):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self._base_url = getattr(settings, 'FILE_STORAGE', '/files')
|
self._base_url = getattr(settings, 'FILE_STORAGE', '/files')
|
||||||
if self._base_url[-1] != '/':
|
if self._base_url[-1] != '/':
|
||||||
@ -60,6 +61,7 @@ class FileStorage(Storage):
|
|||||||
try:
|
try:
|
||||||
cache = caches[cacheName]
|
cache = caches[cacheName]
|
||||||
except:
|
except:
|
||||||
|
logger.info('No cache for FileStorage configured.')
|
||||||
cache = None
|
cache = None
|
||||||
|
|
||||||
self.cache = cache
|
self.cache = cache
|
||||||
@ -73,7 +75,6 @@ class FileStorage(Storage):
|
|||||||
|
|
||||||
Storage.__init__(self, *args, **kwargs)
|
Storage.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def get_valid_name(self, name):
|
def get_valid_name(self, name):
|
||||||
return name.replace('\\', os.path.sep)
|
return name.replace('\\', os.path.sep)
|
||||||
|
|
||||||
@ -119,7 +120,6 @@ class FileStorage(Storage):
|
|||||||
return
|
return
|
||||||
self.cache.delete(self._getKey(name))
|
self.cache.delete(self._getKey(name))
|
||||||
|
|
||||||
|
|
||||||
def _open(self, name, mode='rb'):
|
def _open(self, name, mode='rb'):
|
||||||
f = six.BytesIO(self._dbFileForReadOnly(name).data)
|
f = six.BytesIO(self._dbFileForReadOnly(name).data)
|
||||||
f.name = name
|
f.name = name
|
||||||
@ -173,7 +173,9 @@ class FileStorage(Storage):
|
|||||||
except DBFile.DoesNotExist:
|
except DBFile.DoesNotExist:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class CompressorFileStorage(FileStorage):
|
class CompressorFileStorage(FileStorage):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
FileStorage.__init__(self, *args, **dict(kwargs, owner='compressor'))
|
FileStorage.__init__(self, *args, **dict(kwargs, owner='compressor'))
|
||||||
|
|
||||||
|
@ -41,14 +41,14 @@ def __toBinary(data):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def encode(data, encoder, asText):
|
def encode(data, encoder, asText=False):
|
||||||
res = codecs.encode(__toBinary(data), encoder)
|
res = codecs.encode(__toBinary(data), encoder)
|
||||||
if asText:
|
if asText:
|
||||||
return res.decode('utf8')
|
return res.decode('utf8')
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def decode(data, encoder, asText):
|
def decode(data, encoder, asText=False):
|
||||||
res = codecs.decode(__toBinary(data), encoder)
|
res = codecs.decode(__toBinary(data), encoder)
|
||||||
if asText:
|
if asText:
|
||||||
return res.decode('utf8')
|
return res.decode('utf8')
|
||||||
|
@ -58,7 +58,16 @@ class DBFile(UUIDModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def data(self):
|
def data(self):
|
||||||
return encoders.decode(encoders.decode(self.content, 'base64'), 'zip')
|
try:
|
||||||
|
return encoders.decode(encoders.decode(self.content, 'base64'), 'zip')
|
||||||
|
except Exception:
|
||||||
|
logger.error('DBFile {} has errors and cannot be used'.format(self.name))
|
||||||
|
try:
|
||||||
|
self.delete() # Autodelete, invalid...
|
||||||
|
except:
|
||||||
|
logger.error('Could not even delete {}!!'.format(self.name))
|
||||||
|
|
||||||
|
return ''
|
||||||
|
|
||||||
@data.setter
|
@data.setter
|
||||||
def data(self, value):
|
def data(self, value):
|
||||||
|
Loading…
Reference in New Issue
Block a user