Merge pull request #314 from YunoHost/add-lgtm

Add lgtm
This commit is contained in:
Alexandre Aubin 2021-12-30 18:59:28 +01:00 committed by GitHub
commit c04aac6d98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 6 deletions

View file

@ -4,6 +4,7 @@
![Version](https://img.shields.io/github/v/tag/yunohost/moulinette?label=version&sort=semver)
[![Tests status](https://github.com/YunoHost/moulinette/actions/workflows/tox.yml/badge.svg)](https://github.com/YunoHost/moulinette/actions/workflows/tox.yml)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/YunoHost/moulinette.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/YunoHost/moulinette/context:python)
[![GitHub license](https://img.shields.io/github/license/YunoHost/moulinette)](https://github.com/YunoHost/moulinette/blob/dev/LICENSE)

View file

@ -331,7 +331,7 @@ class ExtendedArgumentParser(argparse.ArgumentParser):
c.execute(namespace, v)
try:
delattr(namespace, CALLBACKS_PROP)
except:
except AttributeError:
pass
def _get_callbacks_queue(self, namespace, create=True):

View file

@ -237,6 +237,7 @@ class Session:
secret = random_ascii()
actionsmap_name = None # This is later set to the actionsmap name
@staticmethod
def set_infos(infos):
assert isinstance(infos, dict)
@ -250,6 +251,7 @@ class Session:
# samesite="strict", # Bottle 0.12 doesn't support samesite, to be added in next versions
)
@staticmethod
def get_infos(raise_if_no_session_exists=True):
try:
@ -673,13 +675,14 @@ class ActionsMapParser(BaseActionsMapParser):
return parser.authentication
def parse_args(self, args, route, **kwargs):
def parse_args(self, args, **kwargs):
"""Parse arguments
Keyword arguments:
- route -- The action route as a 2-tuple (method, path)
"""
route = kwargs["route"]
try:
# Retrieve the parser for the route
_, parser = self._parsers[route]

View file

@ -1,5 +1,4 @@
import os
import logging
# import all constants because other modules try to import them from this
# module because SUCCESS is defined in this module
@ -70,8 +69,11 @@ def configure_logging(logging_config=None):
def getHandlersByClass(classinfo, limit=0):
"""Retrieve registered handlers of a given class."""
from logging import _handlers
handlers = []
for ref in logging._handlers.itervaluerefs():
for ref in _handlers.itervaluerefs():
o = ref()
if o is not None and isinstance(o, classinfo):
if limit == 1:
@ -102,14 +104,17 @@ class MoulinetteLogger(Logger):
def findCaller(self, *args):
"""Override findCaller method to consider this source file."""
f = logging.currentframe()
from logging import currentframe, _srcfile
f = currentframe()
if f is not None:
f = f.f_back
rv = "(unknown file)", 0, "(unknown function)"
while hasattr(f, "f_code"):
co = f.f_code
filename = os.path.normcase(co.co_filename)
if filename == logging._srcfile or filename == __file__:
if filename == _srcfile or filename == __file__:
f = f.f_back
continue
rv = (co.co_filename, f.f_lineno, co.co_name)