Fixed SonarQube analysis issues

This commit is contained in:
Evgeny Ezhov 2019-11-28 14:50:39 +03:00
parent 1859e43daf
commit 0b9c61e7e7
3 changed files with 12 additions and 14 deletions

View file

@ -2,14 +2,15 @@
import functools import functools
import logging import logging
import lxml.etree as etree
import os import os
import requests
import shutil import shutil
import threading import threading
from io import BytesIO from io import BytesIO
from re import sub from re import sub
import lxml.etree as etree
import requests
from webdav3.connection import * from webdav3.connection import *
from webdav3.exceptions import * from webdav3.exceptions import *
from webdav3.urn import Urn from webdav3.urn import Urn
@ -174,7 +175,7 @@ class Client(object):
if response.status_code == 404: if response.status_code == 404:
raise RemoteResourceNotFound(path=path) raise RemoteResourceNotFound(path=path)
if response.status_code == 405: if response.status_code == 405:
raise MethodNotSupported(name=action, server=hostname) raise MethodNotSupported(name=action, server=self.webdav.hostname)
if response.status_code >= 400: if response.status_code >= 400:
raise ResponseErrorCode(url=self.get_url(path), code=response.status_code, message=response.content) raise ResponseErrorCode(url=self.get_url(path), code=response.status_code, message=response.content)
return response return response
@ -243,9 +244,8 @@ class Client(object):
:return: list of nested file or directory names. :return: list of nested file or directory names.
""" """
directory_urn = Urn(remote_path, directory=True) directory_urn = Urn(remote_path, directory=True)
if directory_urn.path() != Client.root: if directory_urn.path() != Client.root and not self.check(directory_urn.path()):
if not self.check(directory_urn.path()): raise RemoteResourceNotFound(directory_urn.path())
raise RemoteResourceNotFound(directory_urn.path())
response = self.execute_request(action='list', path=directory_urn.quote()) response = self.execute_request(action='list', path=directory_urn.quote())
urns = WebDavXmlUtils.parse_get_list_response(response.content) urns = WebDavXmlUtils.parse_get_list_response(response.content)
@ -817,9 +817,6 @@ class Resource(object):
class WebDavXmlUtils: class WebDavXmlUtils:
def __init__(self):
pass
@staticmethod @staticmethod
def parse_get_list_response(content): def parse_get_list_response(content):
"""Parses of response content XML from WebDAV server and extract file and directory names. """Parses of response content XML from WebDAV server and extract file and directory names.

View file

@ -6,10 +6,13 @@ from webdav3.urn import Urn
class ConnectionSettings: class ConnectionSettings:
def is_valid(self): def is_valid(self):
"""
Method checks is settings are valid
:return: True if settings are valid otherwise False
"""
pass pass
def valid(self): def valid(self):
try: try:
self.is_valid() self.is_valid()
except OptionNotValid: except OptionNotValid:
@ -37,7 +40,6 @@ class WebDAVSettings(ConnectionSettings):
disable_check = False disable_check = False
def __init__(self, options): def __init__(self, options):
self.options = dict() self.options = dict()
for key in self.keys: for key in self.keys:
@ -49,7 +51,6 @@ class WebDAVSettings(ConnectionSettings):
self.root = self.root.rstrip(Urn.separate) self.root = self.root.rstrip(Urn.separate)
def is_valid(self): def is_valid(self):
if not self.hostname: if not self.hostname:
raise OptionNotValid(name="hostname", value=self.hostname, ns=self.ns) raise OptionNotValid(name="hostname", value=self.hostname, ns=self.ns)

View file

@ -96,7 +96,7 @@ class ResponseErrorCode(WebDavException):
class NotEnoughSpace(WebDavException): class NotEnoughSpace(WebDavException):
def __init__(self): def __init__(self):
pass self.message = "Not enough space on the server"
def __str__(self): def __str__(self):
return "Not enough space on the server" return self.message