Skip to content

Commit

Permalink
cleanup / fix typing issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfermigier committed Dec 26, 2018
1 parent 259cf66 commit 3a702d4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion abilian/core/logging.py
Expand Up @@ -54,4 +54,4 @@ def process(self, msg, kwargs):

#: logger for monkey patchs. use like this:
#: patch_logger.info(<func>`patched_func`)
patch_logger = PatchLoggerAdapter(_patch_logger, None)
patch_logger = PatchLoggerAdapter(_patch_logger, {})
12 changes: 5 additions & 7 deletions abilian/services/antivirus/service.py
Expand Up @@ -20,15 +20,14 @@
import clamd

cd = clamd.ClamdUnixSocket()
CLAMD_AVAILABLE = True
except ImportError:
CLAMD_AVAILABLE = False
clamd = None

CLAMD_CONF = {"StreamMaxLength": "25M", "MaxFileSize": "25M"}
CLAMD_STREAMMAXLENGTH = 26214400
CLAMD_MAXFILESIZE = 26214400

if CLAMD_AVAILABLE:
if clamd:
conf_path = pathlib.Path("/etc", "clamav", "clamd.conf")
if conf_path.exists():
conf_lines = [l.strip() for l in conf_path.open("rt").readlines()]
Expand Down Expand Up @@ -75,15 +74,15 @@ def scan(self, file_or_stream):
If `file_or_stream` is a Blob, scan result is stored in
Blob.meta['antivirus'].
"""
if not clamd:
return None

res = self._scan(file_or_stream)
if isinstance(file_or_stream, Blob):
file_or_stream.meta["antivirus"] = res
return res

def _scan(self, file_or_stream):
if not CLAMD_AVAILABLE:
return None

content = file_or_stream
if isinstance(file_or_stream, Blob):
# py3 compat: bytes == py2 str(). Pathlib uses os.fsencode()
Expand Down Expand Up @@ -113,7 +112,6 @@ def _scan(self, file_or_stream):
# use stream scan. When using scan by filename, clamd runnnig user must have
# access to file, which we cannot guarantee
scan = cd.instream
res = None
try:
res = scan(content)
except clamd.ClamdError as e:
Expand Down
3 changes: 1 addition & 2 deletions abilian/services/indexing/service.py
Expand Up @@ -16,6 +16,7 @@
import logging
from inspect import isclass
from pathlib import Path
from typing import Set

import sqlalchemy as sa
import whoosh.query as wq
Expand All @@ -26,7 +27,6 @@
from six import text_type
from sqlalchemy import event
from sqlalchemy.orm.session import Session
from typing import Set
from whoosh.filedb.filestore import FileStorage, RamStorage
from whoosh.index import FileIndex
from whoosh.qparser import DisMaxParser
Expand Down Expand Up @@ -70,7 +70,6 @@ def fqcn(cls):


class IndexServiceState(ServiceState):

def __init__(self, *args, **kwargs):
ServiceState.__init__(self, *args, **kwargs)
self.whoosh_base = None
Expand Down
3 changes: 2 additions & 1 deletion abilian/web/action.py
Expand Up @@ -5,6 +5,7 @@

import logging
import re
from typing import Optional

from flask import current_app, g
from flask.signals import appcontext_pushed
Expand Down Expand Up @@ -82,7 +83,7 @@ def __str__(self):
class NamedIconBase(Icon):
"""Renders markup for named icons set."""

template = None
template = None # type: Optional[Template]

def __init__(self, name=""):
self.name = name
Expand Down
3 changes: 2 additions & 1 deletion abilian/web/setupwizard/__init__.py
Expand Up @@ -22,6 +22,7 @@
url_for,
)
from six import text_type
from typing import Dict, Text

from abilian.core.commands import config as cmd_config
from abilian.core.extensions import csrf, db
Expand All @@ -41,7 +42,7 @@

_dialects = OrderedDict((("sqlite", "SQLite (for demo)"), ("postgresql", "PostgreSQL")))

_dialects_unavailable = OrderedDict()
_dialects_unavailable = OrderedDict() # type: Dict[Text, Text]

for dialect, _label in _dialects.items():
d = sa.dialects.registry.load(dialect)
Expand Down

0 comments on commit 3a702d4

Please sign in to comment.