summaryrefslogtreecommitdiff
path: root/display
diff options
context:
space:
mode:
authorDiego Roversi <diegor@tiscali.it>2019-09-20 11:23:08 +0200
committerDiego Roversi <diegor@tiscali.it>2019-09-20 11:23:08 +0200
commit4f48f9e9a828eba2afbc560f181fb6eb037f67bd (patch)
treeacc35cf08438fae1708420384a6ae9a383ff3c00 /display
parent1410af0b007b2fad99088dbdf3f302bc9985e9f8 (diff)
fix class attribute, convert string to bytearray
Diffstat (limited to 'display')
-rw-r--r--display/caching.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/display/caching.py b/display/caching.py
index bdbfdea..88e752d 100644
--- a/display/caching.py
+++ b/display/caching.py
@@ -1,5 +1,5 @@
-import os, md5, sys
+import os, hashlib, sys
#import common.debug
@@ -73,11 +73,16 @@ class FileBlock:
class Data:
- SafeChars = {}
- for c in ".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789":
- SafeChars[c] = c
- Translate = ''.join([SafeChars.get(chr(c), '_') for c in range(256)])
- del c, SafeChars
+ #SafeChars = {}
+ Translate=b''
+ for c in range(256):
+ if chr(c) in ".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789":
+ Translate = Translate + bytes([c])
+ else:
+ Translate = Translate + b'_'
+ # print(f"Translate={Translate}")
+ # Translate = ''.join([SafeChars.get(chr(c), '_') for c in range(256)])
+ #del SafeChars
Cache = FileCache()
def __init__(self):
@@ -114,9 +119,9 @@ class Data:
expected MD5 checksum. The filename must be Unix-style, and is
looked up both in the directory SOURCEDIR and with a mangled name
in the cache directory CACHEDIR."""
- directname = os.path.join(self.SOURCEDIR, *filename.split('/'))
+ directname = os.path.join(self.SOURCEDIR.encode(), *filename.split(b'/'))
mangledname = filename.translate(Data.Translate)
- cachename = os.path.join(self.CACHEDIR, mangledname)
+ cachename = os.path.join(self.CACHEDIR.encode(), mangledname)
for name, readonly in ((directname, 1), (cachename, 0)):
try:
f = Data.Cache.access(name, position)
@@ -124,7 +129,7 @@ class Data:
except (IOError, OSError):
pass
else:
- if len(data) == length and md5.new(data).digest() == checksum:
+ if len(data) == length and hashlib.md5(data).digest() == checksum:
# correct data
self.store(position, data, name, readonly)
return 1
@@ -142,10 +147,10 @@ class Data:
if self.content is not None:
items = list(self.content.items())
items.sort()
- result = ''
+ result = b''
for position, block in items:
if len(result) < position:
- result += '\x00' * (position-len(result))
+ result += b'\x00' * (position-len(result))
data = block.read()
result = result[:position] + data + result[position+len(data):]
return result
@@ -156,7 +161,7 @@ class Data:
def fopen(self):
if self.content is not None:
from io import StringIO
- return StringIO(self.read())
+ return BytesIO(self.read())
else:
return Data.Cache.access(self.backupfile, 0)