Daniel Sheffield 1 ano atrás
pai
commit
1b85abb3ba
1 arquivos alterados com 6 adições e 6 exclusões
  1. 6 6
      app/rest/PageCache.py

+ 6 - 6
app/rest/Cache.py → app/rest/PageCache.py

@@ -3,10 +3,11 @@
 # All rights reserved
 #
 # THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
-import cherrypy
+
 import os
 from time import time
 from typing import Dict
+import cherrypy
 
 from .hash_util import blake, bytes_to_hash, hash_to_base32
 from .CachedLoadingPage import STALE, CachedLoadingPage
@@ -18,10 +19,6 @@ def delete_page(name: str, root: str = 'app/rest/static/files'):
     except FileNotFoundError:
         pass
 
-    try:
-        os.rmdir(directory)
-    except FileNotFoundError:
-        pass
 
 def save_page(name: str, content: bytes, tool: str, root='app/rest/static/files') -> str:
     directory = f'{root}/{name}'
@@ -35,6 +32,7 @@ def save_page(name: str, content: bytes, tool: str, root='app/rest/static/files'
     with open(fd, "wb") as f:
         f.write(content)
 
+
 def get_page(name: str, root: str = 'app/rest/static/files') -> str:
     directory = f'{root}/{name}'
 
@@ -60,6 +58,7 @@ def get_page(name: str, root: str = 'app/rest/static/files') -> str:
         page = f.read()
     return page.decode('utf-8')
 
+
 def key_to_hash(key):
 
     if isinstance(key, tuple):
@@ -81,12 +80,13 @@ def key_to_hash(key):
     
     return get_hash(orig) if _hash is None else _hash
 
+
 def get_hash(key):
     _bytes = blake(key.encode('utf-8'), person='grocery'.encode('utf-8'))
     return bytes_to_hash(_bytes)
 
 
-class Cache:
+class PageCache:
     def __init__(self, limit) -> None:
         self._cache: Dict[str, CachedLoadingPage] = dict()
         self._limit = limit