diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-19 15:05:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-19 15:05:49 +0000 |
commit | d395bd510fa4f4376dc5237ab2f8d190a920d35d (patch) | |
tree | 3e3b16b44064938be801aede14381562bae14f6a /deluge/core/authmanager.py | |
parent | Adding upstream version 2.0.3. (diff) | |
download | deluge-d395bd510fa4f4376dc5237ab2f8d190a920d35d.tar.xz deluge-d395bd510fa4f4376dc5237ab2f8d190a920d35d.zip |
Adding upstream version 2.1.1.upstream/2.1.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'deluge/core/authmanager.py')
-rw-r--r-- | deluge/core/authmanager.py | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/deluge/core/authmanager.py b/deluge/core/authmanager.py index 0d997c1..3ff8a3a 100644 --- a/deluge/core/authmanager.py +++ b/deluge/core/authmanager.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me> @@ -8,12 +7,9 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import os import shutil -from io import open import deluge.component as component import deluge.configmanager as configmanager @@ -32,14 +28,14 @@ log = logging.getLogger(__name__) AUTH_LEVELS_MAPPING = { 'NONE': AUTH_LEVEL_NONE, 'READONLY': AUTH_LEVEL_READONLY, - 'DEFAULT': AUTH_LEVEL_NORMAL, - 'NORMAL': AUTH_LEVEL_DEFAULT, + 'DEFAULT': AUTH_LEVEL_DEFAULT, + 'NORMAL': AUTH_LEVEL_NORMAL, 'ADMIN': AUTH_LEVEL_ADMIN, } AUTH_LEVELS_MAPPING_REVERSE = {v: k for k, v in AUTH_LEVELS_MAPPING.items()} -class Account(object): +class Account: __slots__ = ('username', 'password', 'authlevel') def __init__(self, username, password, authlevel): @@ -56,10 +52,10 @@ class Account(object): } def __repr__(self): - return '<Account username="%(username)s" authlevel=%(authlevel)s>' % { - 'username': self.username, - 'authlevel': self.authlevel, - } + return '<Account username="{username}" authlevel={authlevel}>'.format( + username=self.username, + authlevel=self.authlevel, + ) class AuthManager(component.Component): @@ -101,7 +97,7 @@ class AuthManager(component.Component): int: The auth level for this user. Raises: - AuthenticationRequired: If aditional details are required to authenticate. + AuthenticationRequired: If additional details are required to authenticate. BadLoginError: If the username does not exist or password does not match. """ @@ -184,7 +180,7 @@ class AuthManager(component.Component): if os.path.isfile(filepath): log.debug('Creating backup of %s at: %s', filename, filepath_bak) shutil.copy2(filepath, filepath_bak) - except IOError as ex: + except OSError as ex: log.error('Unable to backup %s to %s: %s', filepath, filepath_bak, ex) else: log.info('Saving the %s at: %s', filename, filepath) @@ -198,7 +194,7 @@ class AuthManager(component.Component): _file.flush() os.fsync(_file.fileno()) shutil.move(filepath_tmp, filepath) - except IOError as ex: + except OSError as ex: log.error('Unable to save %s: %s', filename, ex) if os.path.isfile(filepath_bak): log.info('Restoring backup of %s from: %s', filename, filepath_bak) @@ -227,9 +223,9 @@ class AuthManager(component.Component): for _filepath in (auth_file, auth_file_bak): log.info('Opening %s for load: %s', filename, _filepath) try: - with open(_filepath, 'r', encoding='utf8') as _file: + with open(_filepath, encoding='utf8') as _file: file_data = _file.readlines() - except IOError as ex: + except OSError as ex: log.warning('Unable to load %s: %s', _filepath, ex) file_data = [] else: |