Bugfix: json parsing error handling

pull/12/head 0.3.1
Cesura 4 years ago
parent d75ade2401
commit 683143d7ad

@ -6,7 +6,7 @@ from os import environ
from distutils.util import strtobool
from threading import Thread
pastey_version = "0.3"
pastey_version = "0.3.1"
loaded_config = {}
loaded_themes = []
@ -45,6 +45,7 @@ if __name__ == "__main__":
print("Pastey version ", pastey_version)
print("USING THE FOLLOWING CONFIGURATION:")
print("=====================================")
loaded_config['pastey_version'] = pastey_version
for option in dir(config):
if not option.startswith("__"):
loaded_config[option] = eval("config.%s" % option)

@ -18,14 +18,21 @@ def get_recent(limit=config.recent_pastes):
recent_pastes = []
i = 0
while i < limit and i < len(paths):
if paths[i].is_file():
with open(paths[i]) as fp:
try:
paste = json.loads(fp.read())
except json.JSONDecodeError:
i += 1
continue
# Set extra metadata
basename = path.basename(paths[i])
paste['unique_id'] = basename[:-8] if basename.endswith(".expires") else basename
paste['content'] = '\n'.join(paste['content'].splitlines()[0:10])
paste['icon'] = common.get_icon(paste['language'])
# Replace preview if encrypted
if paste['encrypted']:
paste['content'] = "[Encrypted]"
@ -40,7 +47,10 @@ def get_paste(unique_id, key=""):
if file_path is not None:
with open(file_path, "r") as fp:
try:
paste = json.loads(fp.read())
except json.JSONDecodeError:
return None
# Check if paste is expired
if common.is_expired(paste):

@ -1,4 +1,4 @@
flask
Flask==1.1.2
Flask-Limiter==1.4
guesslang
cryptography
guesslang==2.0.1
cryptography==3.4.7
Loading…
Cancel
Save