upgrade libs and follow linter recommandations
This commit is contained in:
parent
51cfdbe210
commit
542a923cbe
18 changed files with 321 additions and 283 deletions
|
|
@ -1 +1 @@
|
|||
__version__ = '2.0'
|
||||
__version__ = "2.0"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import profig
|
|||
|
||||
|
||||
class ConfigParameter(Enum):
|
||||
DB_URL = "main.db_url"
|
||||
DB_SQLITE_FILE = "main.db_sqlite_file"
|
||||
DB_BACKUP_JSON_FILE = "main.db_backup_json_file"
|
||||
LANG = "main.lang"
|
||||
COMMENT_POLLING = "main.newcomment_polling"
|
||||
|
|
@ -62,4 +62,3 @@ class Config:
|
|||
|
||||
def get_bool(self, key: ConfigParameter):
|
||||
return self._params[key.value].lower() in ("yes", "true")
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,7 @@
|
|||
import logging
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
from stacosys.core import rss
|
||||
from stacosys.core.templater import Templater, Template
|
||||
from stacosys.model.comment import Comment
|
||||
from stacosys.model.email import Email
|
||||
|
|
@ -39,9 +36,8 @@ def _reply_comment_email(lang, mailer, rss, email: Email, site_token):
|
|||
return
|
||||
|
||||
# retrieve site and comment rows
|
||||
try:
|
||||
comment = Comment.get_by_id(comment_id)
|
||||
except:
|
||||
comment = Comment.get_by_id(comment_id)
|
||||
if not comment:
|
||||
logger.warn("unknown comment %d" % comment_id)
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import json
|
||||
from peewee import DatabaseProxy, Model
|
||||
from playhouse.db_url import connect, SqliteDatabase
|
||||
from peewee import Model
|
||||
from playhouse.db_url import SqliteDatabase
|
||||
from playhouse.shortcuts import model_to_dict
|
||||
from tinydb import TinyDB
|
||||
|
||||
|
|
@ -46,4 +46,3 @@ def _backup_db(db_file, Comment):
|
|||
for comment in Comment.select():
|
||||
cc = _tojson_model(comment)
|
||||
table.insert(cc)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import email
|
|||
import imaplib
|
||||
import logging
|
||||
import re
|
||||
from email.message import Message
|
||||
|
||||
from stacosys.model.email import Attachment, Email, Part
|
||||
|
||||
|
|
@ -50,7 +51,7 @@ class Mailbox(object):
|
|||
|
||||
parts = []
|
||||
attachments = []
|
||||
plain_text_content: 'no plain-text part'
|
||||
plain_text_content = "no plain-text part"
|
||||
for part in raw_msg.walk():
|
||||
if part.is_multipart():
|
||||
continue
|
||||
|
|
@ -73,18 +74,10 @@ class Mailbox(object):
|
|||
)
|
||||
)
|
||||
else:
|
||||
part_item = {}
|
||||
content = part.get_payload(decode=True)
|
||||
try:
|
||||
charset = part.get_param("charset", None)
|
||||
if charset:
|
||||
content = to_utf8(content, charset)
|
||||
elif type(content) == bytes:
|
||||
content = content.decode("utf8")
|
||||
except:
|
||||
self.logger.exception()
|
||||
# RFC 3676: remove automatic word-wrapping
|
||||
content = content.replace(" \r\n", " ")
|
||||
content = to_plain_text_content(part)
|
||||
except Exception:
|
||||
logging.exception("cannot extract content from mail part")
|
||||
|
||||
parts.append(
|
||||
Part(content=content, content_type=part.get_content_type())
|
||||
|
|
@ -102,7 +95,7 @@ class Mailbox(object):
|
|||
subject=email_nonascii_to_uft8(raw_msg["Subject"]),
|
||||
parts=parts,
|
||||
attachments=attachments,
|
||||
plain_text_content = plain_text_content
|
||||
plain_text_content=plain_text_content,
|
||||
)
|
||||
|
||||
def delete_message(self, num):
|
||||
|
|
@ -156,3 +149,14 @@ def email_nonascii_to_uft8(string):
|
|||
else:
|
||||
subject = subject + to_utf8(v, charset)
|
||||
return subject
|
||||
|
||||
|
||||
def to_plain_text_content(part: Message) -> str:
|
||||
content = part.get_payload(decode=True)
|
||||
charset = part.get_param("charset", None)
|
||||
if charset:
|
||||
content = to_utf8(content, charset)
|
||||
elif type(content) == bytes:
|
||||
content = content.decode("utf8")
|
||||
# RFC 3676: remove automatic word-wrapping
|
||||
return content.replace(" \r\n", " ")
|
||||
|
|
|
|||
|
|
@ -1,16 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
import logging
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
import requests
|
||||
|
||||
from stacosys.conf import config
|
||||
from stacosys.core import imap
|
||||
from stacosys.model.email import Email
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -56,7 +51,7 @@ class Mailer:
|
|||
count = mbox.get_count()
|
||||
for num in range(count):
|
||||
msgs.append(mbox.fetch_message(num + 1))
|
||||
except:
|
||||
except Exception:
|
||||
logger.exception("fetch mail exception")
|
||||
return msgs
|
||||
|
||||
|
|
@ -76,7 +71,7 @@ class Mailer:
|
|||
s.login(self._smtp_login, self._smtp_password)
|
||||
s.send_message(msg)
|
||||
s.quit()
|
||||
except:
|
||||
except Exception:
|
||||
logger.exception("send mail exception")
|
||||
success = False
|
||||
return success
|
||||
|
|
@ -85,5 +80,5 @@ class Mailer:
|
|||
try:
|
||||
with self._open_mailbox() as mbox:
|
||||
mbox.delete_message(id)
|
||||
except:
|
||||
except Exception:
|
||||
logger.exception("delete mail exception")
|
||||
|
|
|
|||
|
|
@ -7,14 +7,18 @@ from datetime import datetime
|
|||
import markdown
|
||||
import PyRSS2Gen
|
||||
|
||||
import stacosys.conf.config as config
|
||||
from stacosys.core.templater import Templater, Template
|
||||
from stacosys.model.comment import Comment
|
||||
|
||||
|
||||
class Rss:
|
||||
def __init__(
|
||||
self, lang, rss_file, rss_proto, site_name, site_url,
|
||||
self,
|
||||
lang,
|
||||
rss_file,
|
||||
rss_proto,
|
||||
site_name,
|
||||
site_url,
|
||||
):
|
||||
self._lang = lang
|
||||
self._rss_file = rss_file
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ def query_comments():
|
|||
comments.append(d)
|
||||
r = jsonify({"data": comments})
|
||||
r.status_code = 200
|
||||
except:
|
||||
except Exception:
|
||||
logger.warn("bad request")
|
||||
r = jsonify({"data": []})
|
||||
r.status_code = 400
|
||||
|
|
@ -66,7 +66,7 @@ def get_comments_count():
|
|||
)
|
||||
r = jsonify({"count": count})
|
||||
r.status_code = 200
|
||||
except:
|
||||
except Exception:
|
||||
r = jsonify({"count": 0})
|
||||
r.status_code = 200
|
||||
return r
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ def new_form_comment():
|
|||
)
|
||||
comment.save()
|
||||
|
||||
except:
|
||||
except Exception:
|
||||
logger.exception("new comment failure")
|
||||
abort(400)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
from peewee import Model
|
||||
from peewee import CharField
|
||||
from peewee import TextField
|
||||
from peewee import DateTimeField
|
||||
from peewee import ForeignKeyField
|
||||
from datetime import datetime
|
||||
from stacosys.core.database import BaseModel
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue