🔥 Further cleanup of Python 2 leftovers
This commit is contained in:
1 parent
535dcb7109
commit
b75cb55a90
17 files changed
+15
-41
No files matched your search
@@ -170,7 +170,6 @@ class GroupManager:
|
||||
return list(filter(lambda x: x is not None, [self._to_group(g) for g in groups]))
|
||||
|
||||
def _to_group(self, group):
|
||||
# noinspection PyCompatibility
|
||||
if isinstance(group, Group):
|
||||
return group
|
||||
elif isinstance(group, str):
|
||||
|
||||
@@ -7,7 +7,6 @@ from functools import wraps
|
||||
|
||||
from flask import abort, g
|
||||
from flask_babel import gettext
|
||||
from future.utils import with_metaclass
|
||||
|
||||
from octoprint.access import ADMIN_GROUP, READONLY_GROUP, USER_GROUP
|
||||
from octoprint.vendor.flask_principal import Need, Permission, PermissionDenied, RoleNeed
|
||||
@@ -26,7 +25,6 @@ class OctoPrintPermission(Permission):
|
||||
def convert_to_needs(cls, needs):
|
||||
result = []
|
||||
for need in needs:
|
||||
# noinspection PyCompatibility
|
||||
if isinstance(need, Need):
|
||||
result.append(need)
|
||||
elif isinstance(need, Permission):
|
||||
@@ -269,7 +267,7 @@ class PermissionsMetaClass(type):
|
||||
return None
|
||||
|
||||
|
||||
class Permissions(with_metaclass(PermissionsMetaClass)):
|
||||
class Permissions(metaclass=PermissionsMetaClass):
|
||||
|
||||
# Special permission
|
||||
ADMIN = OctoPrintPermission(
|
||||
|
||||
@@ -18,8 +18,6 @@ from octoprint.util import atomic_write, deprecated, generate_api_key
|
||||
from octoprint.util import get_fully_qualified_classname as fqcn
|
||||
from octoprint.util import to_bytes, yaml
|
||||
|
||||
# noinspection PyCompatibility
|
||||
|
||||
|
||||
class UserManager(GroupChangeListener):
|
||||
def __init__(self, group_manager, settings=None):
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# noinspection PyCompatibility
|
||||
import concurrent.futures
|
||||
import logging.handlers
|
||||
import os
|
||||
|
||||
@@ -23,7 +23,7 @@ from octoprint.plugin.core import Plugin, PluginInfo, PluginManager # noqa: F40
|
||||
from octoprint.plugin.types import * # noqa: F401,F403 ## used by multiple other modules
|
||||
from octoprint.plugin.types import OctoPrintPlugin, SettingsPlugin
|
||||
from octoprint.settings import settings as s
|
||||
from octoprint.util import deprecated, to_unicode
|
||||
from octoprint.util import deprecated
|
||||
|
||||
# singleton
|
||||
_instance = None
|
||||
@@ -618,7 +618,7 @@ class PluginSettings:
|
||||
def _func(*args, **kwargs):
|
||||
return orig_func(*args_mapper(args), **kwargs_mapper(kwargs))
|
||||
|
||||
_func.__name__ = to_unicode(item)
|
||||
_func.__name__ = item
|
||||
_func.__doc__ = orig_func.__doc__ if "__doc__" in dir(orig_func) else None
|
||||
|
||||
return _func
|
||||
|
||||
@@ -8,8 +8,6 @@ The SSDP/UPNP implementations has been largely inspired by https://gist.github.c
|
||||
For a spec see http://www.upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.0.pdf
|
||||
"""
|
||||
|
||||
# noinspection PyCompatibility
|
||||
|
||||
import collections
|
||||
import platform
|
||||
import socket
|
||||
|
||||
@@ -12,8 +12,6 @@ import logging.handlers
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
|
||||
# noinspection PyCompatibility
|
||||
from concurrent import futures
|
||||
|
||||
import flask
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
|
||||
__copyright__ = "Copyright (C) 2018 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
# noinspection PyCompatibility
|
||||
import concurrent.futures
|
||||
import hashlib
|
||||
import logging
|
||||
|
||||
@@ -441,7 +441,6 @@ class VirtualPrinter:
|
||||
continue
|
||||
elif len(self._prepared_errors):
|
||||
prepared = self._prepared_errors.pop(0)
|
||||
# noinspection PyCompatibility
|
||||
if callable(prepared):
|
||||
prepared(linenumber, self.lastN, data)
|
||||
continue
|
||||
|
||||
@@ -1428,7 +1428,6 @@ class StaticZipBundleHandler(CorsSupportMixin, tornado.web.RequestHandler):
|
||||
def get_attachment_name(self):
|
||||
return self._attachment_name
|
||||
|
||||
# noinspection PyCompatibility
|
||||
def normalize_files(self, files):
|
||||
result = []
|
||||
for f in files:
|
||||
@@ -1456,7 +1455,6 @@ class StaticZipBundleHandler(CorsSupportMixin, tornado.web.RequestHandler):
|
||||
pass
|
||||
|
||||
for f in self.normalize_files(files):
|
||||
# noinspection PyCompatibility
|
||||
name = f.get("name")
|
||||
path = f.get("path")
|
||||
data = f.get("iter") or f.get("content")
|
||||
|
||||
@@ -29,7 +29,6 @@ import time
|
||||
from collections import ChainMap
|
||||
from collections.abc import KeysView
|
||||
|
||||
# noinspection PyCompatibilitys
|
||||
from yaml import YAMLError
|
||||
|
||||
from octoprint.util import (
|
||||
|
||||
@@ -468,7 +468,7 @@ def get_exception_string(fmt="{type}: '{message}' @ {file}:{function}:{line}"):
|
||||
|
||||
|
||||
def sanitize_ascii(line):
|
||||
if not isinstance(line, str):
|
||||
if not isinstance(line, (str, bytes)):
|
||||
raise ValueError(
|
||||
"Expected str but got {} instead".format(
|
||||
line.__class__.__name__ if line is not None else None
|
||||
@@ -940,7 +940,7 @@ def guess_mime_type(data):
|
||||
def parse_mime_type(mime):
|
||||
import cgi
|
||||
|
||||
if not mime or not isinstance(mime, str):
|
||||
if not mime or not isinstance(mime, (str, bytes)):
|
||||
raise ValueError("mime must be a non empty str")
|
||||
|
||||
mime, params = cgi.parse_header(mime)
|
||||
@@ -1699,9 +1699,7 @@ def time_this(
|
||||
|
||||
|
||||
def generate_api_key():
|
||||
# noinspection PyCompatibility
|
||||
import uuid
|
||||
from builtins import bytes
|
||||
|
||||
return "".join("%02X" % z for z in bytes(uuid.uuid4().bytes))
|
||||
|
||||
|
||||
@@ -1378,7 +1378,6 @@ class MachineCom:
|
||||
f"script:{scriptName}",
|
||||
}
|
||||
for line in scriptLines:
|
||||
# noinspection PyCompatibility
|
||||
if (
|
||||
isinstance(line, tuple)
|
||||
and len(line) == 2
|
||||
@@ -4920,7 +4919,6 @@ class MachineCom:
|
||||
def convert(data):
|
||||
result = []
|
||||
for d in data:
|
||||
# noinspection PyCompatibility
|
||||
if isinstance(d, tuple) and len(d) == 2:
|
||||
result.append((d[0], None, d[1]))
|
||||
elif isinstance(d, str):
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import sys # noqa: F401
|
||||
|
||||
OPEN_SIGNATURE = "builtins.open"
|
||||
@@ -7,8 +7,6 @@ import io
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import _fixups
|
||||
|
||||
import octoprint.filemanager
|
||||
import octoprint.filemanager.util
|
||||
import octoprint.settings
|
||||
@@ -395,7 +393,7 @@ class FileManagerTest(unittest.TestCase):
|
||||
mock_time.return_value = now
|
||||
self.local_storage.path_in_storage.return_value = path
|
||||
|
||||
with mock.patch(_fixups.OPEN_SIGNATURE, mock.mock_open(), create=True):
|
||||
with mock.patch("builtins.open", mock.mock_open(), create=True):
|
||||
self.file_manager.save_recovery_data(
|
||||
octoprint.filemanager.FileDestinations.LOCAL, path, pos
|
||||
)
|
||||
@@ -429,7 +427,7 @@ class FileManagerTest(unittest.TestCase):
|
||||
|
||||
mock_yaml_safe_dump.side_effect = RuntimeError
|
||||
|
||||
with mock.patch(_fixups.OPEN_SIGNATURE, mock.mock_open(), create=True):
|
||||
with mock.patch("builtins.open", mock.mock_open(), create=True):
|
||||
self.file_manager.save_recovery_data(
|
||||
octoprint.filemanager.FileDestinations.LOCAL, path, pos
|
||||
)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from octoprint.printer.estimation import TimeEstimationHelper
|
||||
|
||||
__author__ = "Gina Häußge <osd@foosel.net>"
|
||||
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
|
||||
__copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
@@ -9,6 +7,8 @@ import unittest
|
||||
|
||||
from ddt import data, ddt, unpack
|
||||
|
||||
from octoprint.printer.estimation import TimeEstimationHelper
|
||||
|
||||
|
||||
@ddt
|
||||
class EstimationTestCase(unittest.TestCase):
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import _fixups
|
||||
|
||||
import octoprint.daemon
|
||||
|
||||
|
||||
@@ -104,7 +102,7 @@ class DaemonTest(unittest.TestCase):
|
||||
@mock.patch("sys.stdout")
|
||||
@mock.patch("sys.stderr")
|
||||
@mock.patch("os.devnull")
|
||||
@mock.patch(_fixups.OPEN_SIGNATURE)
|
||||
@mock.patch("builtins.open")
|
||||
@mock.patch("os.dup2")
|
||||
def test_redirect_io(
|
||||
self, mock_dup2, mock_open, mock_devnull, mock_stderr, mock_stdout, mock_stdin
|
||||
@@ -402,7 +400,7 @@ class DaemonTest(unittest.TestCase):
|
||||
|
||||
# test
|
||||
with mock.patch(
|
||||
_fixups.OPEN_SIGNATURE,
|
||||
"builtins.open",
|
||||
mock.mock_open(read_data=f"{pid}\n"),
|
||||
create=True,
|
||||
) as m:
|
||||
@@ -418,7 +416,7 @@ class DaemonTest(unittest.TestCase):
|
||||
handle.__enter__.side_effect = IOError()
|
||||
|
||||
# test
|
||||
with mock.patch(_fixups.OPEN_SIGNATURE, mock.mock_open(), create=True) as m:
|
||||
with mock.patch("builtins.open", mock.mock_open(), create=True) as m:
|
||||
result = self.daemon.get_pid()
|
||||
|
||||
# assert
|
||||
@@ -431,7 +429,7 @@ class DaemonTest(unittest.TestCase):
|
||||
|
||||
# test
|
||||
with mock.patch(
|
||||
_fixups.OPEN_SIGNATURE,
|
||||
"builtins.open",
|
||||
mock.mock_open(read_data=f"{pid}\n"),
|
||||
create=True,
|
||||
) as m:
|
||||
@@ -446,7 +444,7 @@ class DaemonTest(unittest.TestCase):
|
||||
pid = "1234"
|
||||
|
||||
# test
|
||||
with mock.patch(_fixups.OPEN_SIGNATURE, mock.mock_open(), create=True) as m:
|
||||
with mock.patch("builtins.open", mock.mock_open(), create=True) as m:
|
||||
self.daemon.set_pid(pid)
|
||||
|
||||
# assert
|
||||
@@ -459,7 +457,7 @@ class DaemonTest(unittest.TestCase):
|
||||
pid = 1234
|
||||
|
||||
# test
|
||||
with mock.patch(_fixups.OPEN_SIGNATURE, mock.mock_open(), create=True) as m:
|
||||
with mock.patch("builtins.open", mock.mock_open(), create=True) as m:
|
||||
self.daemon.set_pid(pid)
|
||||
|
||||
# assert
|
||||
|
||||
Reference in new issue
Block a user