♻️ Py3: Remove past.builtins and future.utils uses
This commit is contained in:
1 parent
292aa99543
commit
e45e97f9ac
24 files changed
+83
-130
No files matched your search
@@ -8,7 +8,6 @@ import os
|
||||
from functools import partial
|
||||
|
||||
import yaml
|
||||
from past.builtins import basestring
|
||||
|
||||
from octoprint.access import ADMIN_GROUP, GUEST_GROUP, READONLY_GROUP, USER_GROUP
|
||||
from octoprint.access.permissions import OctoPrintPermission, Permissions
|
||||
@@ -177,7 +176,7 @@ class GroupManager:
|
||||
# noinspection PyCompatibility
|
||||
if isinstance(group, Group):
|
||||
return group
|
||||
elif isinstance(group, basestring):
|
||||
elif isinstance(group, str):
|
||||
return self.find_group(group)
|
||||
elif isinstance(group, dict):
|
||||
return self.find_group(group.get("key"))
|
||||
|
||||
@@ -7,10 +7,6 @@ from functools import wraps
|
||||
|
||||
from flask import abort, g
|
||||
from flask_babel import gettext
|
||||
from future.utils import with_metaclass
|
||||
|
||||
# noinspection PyCompatibility
|
||||
from past.builtins import basestring
|
||||
|
||||
from octoprint.access import ADMIN_GROUP, READONLY_GROUP, USER_GROUP
|
||||
from octoprint.vendor.flask_principal import Need, Permission, PermissionDenied, RoleNeed
|
||||
@@ -34,7 +30,7 @@ class OctoPrintPermission(Permission):
|
||||
result.append(need)
|
||||
elif isinstance(need, Permission):
|
||||
result += need.needs
|
||||
elif isinstance(need, basestring):
|
||||
elif isinstance(need, str):
|
||||
result.append(RoleNeed(need))
|
||||
return result
|
||||
|
||||
@@ -247,7 +243,7 @@ class PermissionsMetaClass(type):
|
||||
key = p.key
|
||||
elif isinstance(p, dict):
|
||||
key = p.get("key")
|
||||
elif isinstance(p, basestring):
|
||||
elif isinstance(p, str):
|
||||
key = p
|
||||
|
||||
if key is None:
|
||||
@@ -268,7 +264,7 @@ class PermissionsMetaClass(type):
|
||||
return None
|
||||
|
||||
|
||||
class Permissions(with_metaclass(PermissionsMetaClass)):
|
||||
class Permissions(object, metaclass=PermissionsMetaClass):
|
||||
|
||||
# Special permission
|
||||
ADMIN = OctoPrintPermission(
|
||||
|
||||
@@ -13,7 +13,6 @@ from builtins import bytes, range
|
||||
import wrapt
|
||||
import yaml
|
||||
from flask_login import AnonymousUserMixin, UserMixin
|
||||
from past.builtins import basestring
|
||||
from werkzeug.local import LocalProxy
|
||||
|
||||
from octoprint.access.groups import Group, GroupChangeListener
|
||||
@@ -301,7 +300,7 @@ class UserManager(GroupChangeListener):
|
||||
)
|
||||
|
||||
def _trigger_on_user_modified(self, user):
|
||||
if isinstance(user, basestring):
|
||||
if isinstance(user, str):
|
||||
# user id
|
||||
users = []
|
||||
try:
|
||||
|
||||
@@ -5,7 +5,6 @@ import io
|
||||
import json
|
||||
|
||||
import click
|
||||
from past.builtins import unicode
|
||||
|
||||
import octoprint_client
|
||||
from octoprint import FatalStartupError, init_settings
|
||||
@@ -191,10 +190,10 @@ def post_from_file(ctx, path, file_path, json_flag, yaml_flag, timeout):
|
||||
"str_params",
|
||||
multiple=True,
|
||||
nargs=2,
|
||||
type=click.Tuple([unicode, unicode]),
|
||||
type=click.Tuple([str, str]),
|
||||
)
|
||||
@click.option(
|
||||
"--int", "-i", "int_params", multiple=True, nargs=2, type=click.Tuple([unicode, int])
|
||||
"--int", "-i", "int_params", multiple=True, nargs=2, type=click.Tuple([str, int])
|
||||
)
|
||||
@click.option(
|
||||
"--float",
|
||||
@@ -202,7 +201,7 @@ def post_from_file(ctx, path, file_path, json_flag, yaml_flag, timeout):
|
||||
"float_params",
|
||||
multiple=True,
|
||||
nargs=2,
|
||||
type=click.Tuple([unicode, float]),
|
||||
type=click.Tuple([str, float]),
|
||||
)
|
||||
@click.option(
|
||||
"--bool",
|
||||
@@ -210,7 +209,7 @@ def post_from_file(ctx, path, file_path, json_flag, yaml_flag, timeout):
|
||||
"bool_params",
|
||||
multiple=True,
|
||||
nargs=2,
|
||||
type=click.Tuple([unicode, bool]),
|
||||
type=click.Tuple([str, bool]),
|
||||
)
|
||||
@click.option("--timeout", type=float, default=None, help="Request timeout in seconds")
|
||||
@click.pass_context
|
||||
@@ -237,7 +236,7 @@ def command(
|
||||
"params",
|
||||
multiple=True,
|
||||
nargs=2,
|
||||
type=click.Tuple([unicode, unicode]),
|
||||
type=click.Tuple([str, str]),
|
||||
)
|
||||
@click.option("--file-name", type=click.STRING)
|
||||
@click.option("--content-type", type=click.STRING)
|
||||
|
||||
@@ -7,8 +7,6 @@ import click
|
||||
|
||||
click.disable_unicode_literals_warning = True
|
||||
|
||||
from past.builtins import basestring
|
||||
|
||||
|
||||
class OctoPrintDevelCommands(click.MultiCommand):
|
||||
"""
|
||||
@@ -122,7 +120,7 @@ class OctoPrintDevelCommands(click.MultiCommand):
|
||||
if key in options:
|
||||
val = options[key]
|
||||
else:
|
||||
if not isinstance(raw, basestring):
|
||||
if not isinstance(raw, str):
|
||||
raw = str(raw)
|
||||
val = env.from_string(raw).render(cookiecutter=cookiecutter_dict)
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@ import logging
|
||||
import os
|
||||
from collections import namedtuple
|
||||
|
||||
from past.builtins import basestring
|
||||
|
||||
import octoprint.plugin
|
||||
import octoprint.util
|
||||
from octoprint.events import Events, eventManager
|
||||
@@ -676,7 +674,7 @@ class FileManager:
|
||||
):
|
||||
if not destinations:
|
||||
destinations = list(self._storage_managers.keys())
|
||||
if isinstance(destinations, basestring):
|
||||
if isinstance(destinations, str):
|
||||
destinations = [destinations]
|
||||
|
||||
result = {}
|
||||
|
||||
@@ -13,7 +13,6 @@ from os import scandir, walk
|
||||
|
||||
import pylru
|
||||
from emoji import demojize
|
||||
from past.builtins import basestring
|
||||
|
||||
import octoprint.filemanager
|
||||
from octoprint.util import atomic_write, is_hidden_path, time_this, to_bytes, to_unicode
|
||||
@@ -1135,7 +1134,7 @@ class LocalFileStorage(StorageInterface):
|
||||
|
||||
def canonicalize(self, path):
|
||||
name = None
|
||||
if isinstance(path, basestring):
|
||||
if isinstance(path, str):
|
||||
path = to_unicode(path)
|
||||
if path.startswith(self.basefolder):
|
||||
path = path[len(self.basefolder) :]
|
||||
@@ -1234,7 +1233,7 @@ class LocalFileStorage(StorageInterface):
|
||||
def path_in_storage(self, path):
|
||||
if isinstance(path, (tuple, list)):
|
||||
path = self.join_path(*path)
|
||||
if isinstance(path, basestring):
|
||||
if isinstance(path, str):
|
||||
path = to_unicode(path)
|
||||
if path.startswith(self.basefolder):
|
||||
path = path[len(self.basefolder) :]
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from typing import Union
|
||||
|
||||
from past.builtins import basestring, unicode
|
||||
|
||||
from octoprint.logging import handlers # noqa: F401
|
||||
|
||||
|
||||
@@ -128,7 +126,7 @@ def get_divider_line(c, message=None, length=78, indent=3):
|
||||
formatted divider line
|
||||
"""
|
||||
|
||||
assert isinstance(c, basestring), "c is not text"
|
||||
assert isinstance(c, str), "c is not text"
|
||||
assert len(c) == 1, "c is not a single character"
|
||||
assert isinstance(length, int), "length is not an int"
|
||||
assert isinstance(indent, int), "indent is not an int"
|
||||
@@ -136,7 +134,7 @@ def get_divider_line(c, message=None, length=78, indent=3):
|
||||
if message is None:
|
||||
return c * length
|
||||
|
||||
assert isinstance(message, basestring), "message is not text"
|
||||
assert isinstance(message, str), "message is not text"
|
||||
|
||||
space = length - 2 * (indent + 1)
|
||||
if space >= len(message):
|
||||
@@ -146,7 +144,7 @@ def get_divider_line(c, message=None, length=78, indent=3):
|
||||
|
||||
|
||||
def prefix_multilines(text, prefix=": "):
|
||||
# type: (Union[unicode, bytes], unicode) -> unicode
|
||||
# type: (Union[str, bytes], str) -> str
|
||||
from octoprint.util import to_unicode
|
||||
|
||||
lines = text.splitlines()
|
||||
|
||||
@@ -32,7 +32,6 @@ from os import scandir
|
||||
|
||||
import pkg_resources
|
||||
import pkginfo
|
||||
from past.builtins import unicode
|
||||
|
||||
import octoprint.vendor.imp as imp
|
||||
from octoprint.util import sv, time_this, to_unicode
|
||||
@@ -426,7 +425,7 @@ class PluginInfo:
|
||||
else:
|
||||
ret = ""
|
||||
|
||||
ret += unicode(self)
|
||||
ret += str(self)
|
||||
|
||||
if show_bundled:
|
||||
ret += (
|
||||
@@ -2038,7 +2037,7 @@ class PluginManager:
|
||||
show_enabled=show_enabled,
|
||||
enabled_strs=enabled_str,
|
||||
),
|
||||
sorted(self.plugins.values(), key=lambda x: unicode(x).lower()),
|
||||
sorted(self.plugins.values(), key=lambda x: str(x).lower()),
|
||||
)
|
||||
)
|
||||
legend = "Prefix legend: {1} = disabled, {2} = blacklisted, {3} = incompatible".format(
|
||||
|
||||
@@ -21,7 +21,6 @@ import requests
|
||||
import sarge
|
||||
from flask import jsonify, make_response
|
||||
from flask_babel import gettext
|
||||
from past.builtins import basestring
|
||||
|
||||
import octoprint.plugin
|
||||
import octoprint.plugin.core
|
||||
@@ -81,7 +80,7 @@ def map_repository_entry(entry):
|
||||
if (
|
||||
"python" in entry["compatibility"]
|
||||
and entry["compatibility"]["python"] is not None
|
||||
and isinstance(entry["compatibility"]["python"], basestring)
|
||||
and isinstance(entry["compatibility"]["python"], str)
|
||||
):
|
||||
result["is_compatible"]["python"] = is_python_compatible(
|
||||
entry["compatibility"]["python"]
|
||||
@@ -1143,7 +1142,7 @@ class PluginManagerPlugin(
|
||||
result_notifications=True,
|
||||
settings_save=True,
|
||||
):
|
||||
if isinstance(plugin, basestring):
|
||||
if isinstance(plugin, str):
|
||||
key = result_value = plugin
|
||||
else:
|
||||
key = plugin.key
|
||||
@@ -1720,9 +1719,7 @@ class PluginManagerPlugin(
|
||||
try:
|
||||
result = hook()
|
||||
if isinstance(result, (list, tuple)):
|
||||
reconnect_hooks.extend(
|
||||
filter(lambda x: isinstance(x, basestring), result)
|
||||
)
|
||||
reconnect_hooks.extend(filter(lambda x: isinstance(x, str), result))
|
||||
except Exception:
|
||||
self._logger.exception(
|
||||
"Error while retrieving additional hooks for which a "
|
||||
|
||||
@@ -9,8 +9,6 @@ import sys
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from past.builtins import unicode
|
||||
|
||||
# default close_fds settings
|
||||
if sys.platform == "win32" and sys.version_info < (3, 7):
|
||||
CLOSE_FDS = False
|
||||
@@ -53,7 +51,7 @@ def _to_unicode(s_or_u, encoding="utf-8", errors="strict"):
|
||||
|
||||
def _to_bytes(s_or_u, encoding="utf-8", errors="strict"):
|
||||
"""Make sure ``s_or_u`` is a str."""
|
||||
if isinstance(s_or_u, unicode):
|
||||
if isinstance(s_or_u, (str, bytes)):
|
||||
return s_or_u.encode(encoding, errors=errors)
|
||||
else:
|
||||
return s_or_u
|
||||
@@ -202,7 +200,7 @@ def _to_error(*lines):
|
||||
if len(lines) == 1:
|
||||
if isinstance(lines[0], (list, tuple)):
|
||||
lines = lines[0]
|
||||
elif not isinstance(lines[0], (str, unicode)):
|
||||
elif not isinstance(lines[0], (str, bytes)):
|
||||
lines = [
|
||||
repr(lines[0]),
|
||||
]
|
||||
|
||||
@@ -10,16 +10,11 @@ import queue
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
|
||||
try:
|
||||
from os import scandir
|
||||
except ImportError:
|
||||
from scandir import scandir
|
||||
from os import scandir
|
||||
|
||||
# noinspection PyCompatibility
|
||||
from typing import Any
|
||||
|
||||
from past.builtins import basestring
|
||||
from serial import SerialTimeoutException
|
||||
|
||||
from octoprint.plugin import plugin_manager
|
||||
@@ -430,7 +425,7 @@ class VirtualPrinter:
|
||||
if callable(prepared):
|
||||
prepared(linenumber, self.lastN, data)
|
||||
continue
|
||||
elif isinstance(prepared, basestring):
|
||||
elif isinstance(prepared, str):
|
||||
self._send(prepared)
|
||||
continue
|
||||
elif self._rerequest_last:
|
||||
|
||||
@@ -13,7 +13,6 @@ import threading
|
||||
import time
|
||||
|
||||
from frozendict import frozendict
|
||||
from past.builtins import basestring, long
|
||||
|
||||
from octoprint import util as util
|
||||
from octoprint.events import Events, eventManager
|
||||
@@ -430,14 +429,14 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
raise UnknownScript(name)
|
||||
|
||||
def jog(self, axes, relative=True, speed=None, *args, **kwargs):
|
||||
if isinstance(axes, basestring):
|
||||
if isinstance(axes, str):
|
||||
# legacy parameter format, there should be an amount as first anonymous positional arguments too
|
||||
axis = axes
|
||||
|
||||
if not len(args) >= 1:
|
||||
raise ValueError("amount not set")
|
||||
amount = args[0]
|
||||
if not isinstance(amount, (int, long, float)):
|
||||
if not isinstance(amount, (int, float)):
|
||||
raise ValueError(
|
||||
"amount must be a valid number: {amount}".format(amount=amount)
|
||||
)
|
||||
@@ -476,7 +475,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
|
||||
def home(self, axes, *args, **kwargs):
|
||||
if not isinstance(axes, (list, tuple)):
|
||||
if isinstance(axes, basestring):
|
||||
if isinstance(axes, str):
|
||||
axes = [axes]
|
||||
else:
|
||||
raise ValueError(
|
||||
@@ -501,7 +500,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
)
|
||||
|
||||
def extrude(self, amount, speed=None, *args, **kwargs):
|
||||
if not isinstance(amount, (int, long, float)):
|
||||
if not isinstance(amount, (int, float)):
|
||||
raise ValueError(
|
||||
"amount must be a valid number: {amount}".format(amount=amount)
|
||||
)
|
||||
@@ -541,7 +540,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
)
|
||||
)
|
||||
|
||||
if not isinstance(value, (int, long, float)) or value < 0:
|
||||
if not isinstance(value, (int, float)) or value < 0:
|
||||
raise ValueError(
|
||||
"value must be a valid number >= 0: {value}".format(value=value)
|
||||
)
|
||||
@@ -575,7 +574,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
filter(lambda x: PrinterInterface.valid_heater_regex.match(x), offsets.keys())
|
||||
)
|
||||
validated_values = list(
|
||||
filter(lambda x: isinstance(x, (int, long, float)), offsets.values())
|
||||
filter(lambda x: isinstance(x, (int, float)), offsets.values())
|
||||
)
|
||||
|
||||
if len(validated_keys) != len(offsets):
|
||||
@@ -594,7 +593,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
self._setOffsets(self._comm.getOffsets())
|
||||
|
||||
def _convert_rate_value(self, factor, min_val=None, max_val=None):
|
||||
if not isinstance(factor, (int, float, long)):
|
||||
if not isinstance(factor, (int, float)):
|
||||
raise ValueError("factor is not a number")
|
||||
|
||||
if isinstance(factor, float):
|
||||
|
||||
@@ -36,7 +36,6 @@ from flask_login import ( # noqa: F401
|
||||
session_protected,
|
||||
user_logged_out,
|
||||
)
|
||||
from past.builtins import basestring, unicode
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.observers.polling import PollingObserver
|
||||
|
||||
@@ -986,7 +985,7 @@ class Server:
|
||||
for entry in result:
|
||||
if not isinstance(entry, tuple) or not len(entry) == 3:
|
||||
continue
|
||||
if not isinstance(entry[0], basestring):
|
||||
if not isinstance(entry[0], str):
|
||||
continue
|
||||
if not isinstance(entry[2], dict):
|
||||
continue
|
||||
@@ -2364,7 +2363,7 @@ class Server:
|
||||
if content_type:
|
||||
self.send_header("Content-Type", content_type)
|
||||
self.end_headers()
|
||||
if isinstance(data, unicode):
|
||||
if isinstance(data, str):
|
||||
data = data.encode("utf-8")
|
||||
self.wfile.write(data)
|
||||
break
|
||||
@@ -2688,7 +2687,7 @@ class LifecycleManager:
|
||||
lifecycle_callback(name, plugin)
|
||||
|
||||
def add_callback(self, events, callback):
|
||||
if isinstance(events, basestring):
|
||||
if isinstance(events, str):
|
||||
events = [events]
|
||||
|
||||
for event in events:
|
||||
@@ -2700,7 +2699,7 @@ class LifecycleManager:
|
||||
if callback in self._plugin_lifecycle_callbacks[event]:
|
||||
self._plugin_lifecycle_callbacks[event].remove(callback)
|
||||
else:
|
||||
if isinstance(events, basestring):
|
||||
if isinstance(events, str):
|
||||
events = [events]
|
||||
|
||||
for event in events:
|
||||
|
||||
@@ -5,7 +5,6 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
|
||||
import re
|
||||
|
||||
from flask import Response, jsonify, make_response, request
|
||||
from past.builtins import basestring, long, unicode
|
||||
from werkzeug.exceptions import BadRequest
|
||||
|
||||
from octoprint.access.permissions import Permissions
|
||||
@@ -92,7 +91,7 @@ def printerToolCommand():
|
||||
##~~ tool selection
|
||||
if command == "select":
|
||||
tool = data["tool"]
|
||||
if not isinstance(tool, basestring) or re.match(validation_regex, tool) is None:
|
||||
if not isinstance(tool, str) or re.match(validation_regex, tool) is None:
|
||||
return make_response("Invalid tool: %s" % tool, 400)
|
||||
if not tool.startswith("tool"):
|
||||
return make_response("Invalid tool for selection: %s" % tool, 400)
|
||||
@@ -110,7 +109,7 @@ def printerToolCommand():
|
||||
return make_response(
|
||||
"Invalid target for setting temperature: %s" % tool, 400
|
||||
)
|
||||
if not isinstance(value, (int, long, float)):
|
||||
if not isinstance(value, (int, float)):
|
||||
return make_response("Not a number for %s: %r" % (tool, value), 400)
|
||||
validated_values[tool] = value
|
||||
|
||||
@@ -129,7 +128,7 @@ def printerToolCommand():
|
||||
return make_response(
|
||||
"Invalid target for setting temperature: %s" % tool, 400
|
||||
)
|
||||
if not isinstance(value, (int, long, float)):
|
||||
if not isinstance(value, (int, float)):
|
||||
return make_response("Not a number for %s: %r" % (tool, value), 400)
|
||||
if not -50 <= value <= 50:
|
||||
return make_response(
|
||||
@@ -148,13 +147,13 @@ def printerToolCommand():
|
||||
|
||||
amount = data["amount"]
|
||||
speed = data.get("speed", None)
|
||||
if not isinstance(amount, (int, long, float)):
|
||||
if not isinstance(amount, (int, float)):
|
||||
return make_response("Not a number for extrusion amount: %r" % amount, 400)
|
||||
printer.extrude(amount, speed=speed, tags=tags)
|
||||
|
||||
elif command == "flowrate":
|
||||
factor = data["factor"]
|
||||
if not isinstance(factor, (int, long, float)):
|
||||
if not isinstance(factor, (int, float)):
|
||||
return make_response("Not a number for flow rate: %r" % factor, 400)
|
||||
try:
|
||||
printer.flow_rate(factor, tags=tags)
|
||||
@@ -199,7 +198,7 @@ def printerBedCommand():
|
||||
target = data["target"]
|
||||
|
||||
# make sure the target is a number
|
||||
if not isinstance(target, (int, long, float)):
|
||||
if not isinstance(target, (int, float)):
|
||||
return make_response("Not a number: %r" % target, 400)
|
||||
|
||||
# perform the actual temperature command
|
||||
@@ -210,7 +209,7 @@ def printerBedCommand():
|
||||
offset = data["offset"]
|
||||
|
||||
# make sure the offset is valid
|
||||
if not isinstance(offset, (int, long, float)):
|
||||
if not isinstance(offset, (int, float)):
|
||||
return make_response("Not a number: %r" % offset, 400)
|
||||
if not -50 <= offset <= 50:
|
||||
return make_response("Offset not in range [-50, 50]: %f" % offset, 400)
|
||||
@@ -263,7 +262,7 @@ def printerChamberCommand():
|
||||
target = data["target"]
|
||||
|
||||
# make sure the target is a number
|
||||
if not isinstance(target, (int, long, float)):
|
||||
if not isinstance(target, (int, float)):
|
||||
return make_response("Not a number: %r" % target, 400)
|
||||
|
||||
# perform the actual temperature command
|
||||
@@ -274,7 +273,7 @@ def printerChamberCommand():
|
||||
offset = data["offset"]
|
||||
|
||||
# make sure the offset is valid
|
||||
if not isinstance(offset, (int, long, float)):
|
||||
if not isinstance(offset, (int, float)):
|
||||
return make_response("Not a number: %r" % offset, 400)
|
||||
if not -50 <= offset <= 50:
|
||||
return make_response("Offset not in range [-50, 50]: %f" % offset, 400)
|
||||
@@ -328,7 +327,7 @@ def printerPrintheadCommand():
|
||||
for axis in valid_axes:
|
||||
if axis in data:
|
||||
value = data[axis]
|
||||
if not isinstance(value, (int, long, float)):
|
||||
if not isinstance(value, (int, float)):
|
||||
return make_response(
|
||||
"Not a number for axis %s: %r" % (axis, value), 400
|
||||
)
|
||||
@@ -354,7 +353,7 @@ def printerPrintheadCommand():
|
||||
|
||||
elif command == "feedrate":
|
||||
factor = data["factor"]
|
||||
if not isinstance(factor, (int, long, float)):
|
||||
if not isinstance(factor, (int, float)):
|
||||
return make_response("Not a number for feed rate: %r" % factor, 400)
|
||||
try:
|
||||
printer.feed_rate(factor, tags=tags)
|
||||
@@ -489,7 +488,7 @@ def _get_temperature_data(preprocessor):
|
||||
tempHistory = printer.get_temperature_history()
|
||||
|
||||
limit = 300
|
||||
if "limit" in request.values and unicode(request.values["limit"]).isnumeric():
|
||||
if "limit" in request.values and str(request.values["limit"]).isnumeric():
|
||||
limit = int(request.values["limit"])
|
||||
|
||||
history = list(tempHistory)
|
||||
|
||||
@@ -6,7 +6,6 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
|
||||
import copy
|
||||
|
||||
from flask import jsonify, make_response, request, url_for
|
||||
from past.builtins import basestring
|
||||
from werkzeug.exceptions import BadRequest
|
||||
|
||||
from octoprint.access.permissions import Permissions
|
||||
@@ -71,7 +70,7 @@ def printerProfilesAdd():
|
||||
return make_response("No profile included in request", 400)
|
||||
|
||||
base_profile = printerProfileManager.get_default()
|
||||
if "basedOn" in json_data and isinstance(json_data["basedOn"], basestring):
|
||||
if "basedOn" in json_data and isinstance(json_data["basedOn"], str):
|
||||
other_profile = printerProfileManager.get(json_data["basedOn"])
|
||||
if other_profile is not None:
|
||||
base_profile = other_profile
|
||||
|
||||
@@ -22,7 +22,6 @@ import tornado.web
|
||||
import webassets.updater
|
||||
import webassets.utils
|
||||
from cachelib import BaseCache
|
||||
from past.builtins import basestring, long
|
||||
from werkzeug.local import LocalProxy
|
||||
from werkzeug.utils import cached_property
|
||||
|
||||
@@ -1187,7 +1186,7 @@ def lastmodified(date):
|
||||
if callable(result):
|
||||
result = result(rv)
|
||||
|
||||
if not isinstance(result, basestring):
|
||||
if not isinstance(result, str):
|
||||
from werkzeug.http import http_date
|
||||
|
||||
result = http_date(result)
|
||||
@@ -1304,7 +1303,7 @@ def with_revalidation_checking(
|
||||
|
||||
# set last modified header if not already set
|
||||
if lm and response.headers.get("Last-Modified", None) is None:
|
||||
if not isinstance(lm, basestring):
|
||||
if not isinstance(lm, str):
|
||||
from werkzeug.http import http_date
|
||||
|
||||
lm = http_date(lm)
|
||||
@@ -1335,7 +1334,7 @@ def check_lastmodified(lastmodified):
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
if isinstance(lastmodified, (int, long, float)):
|
||||
if isinstance(lastmodified, (int, float)):
|
||||
# max(86400, lastmodified) is workaround for https://bugs.python.org/issue29097,
|
||||
# present in CPython 3.6.x up to 3.7.1.
|
||||
#
|
||||
|
||||
@@ -20,7 +20,6 @@ import tornado.iostream
|
||||
import tornado.tcpserver
|
||||
import tornado.util
|
||||
import tornado.web
|
||||
from past.builtins import unicode
|
||||
|
||||
import octoprint.util
|
||||
|
||||
@@ -757,7 +756,7 @@ class WsgiInputContainer:
|
||||
|
||||
# determine the request_body to supply as wsgi.input
|
||||
if body is not None:
|
||||
if isinstance(body, (bytes, str, unicode)):
|
||||
if isinstance(body, (bytes, str)):
|
||||
request_body = io.BytesIO(tornado.escape.utf8(body))
|
||||
else:
|
||||
request_body = body
|
||||
|
||||
@@ -21,7 +21,6 @@ from flask import (
|
||||
send_from_directory,
|
||||
url_for,
|
||||
)
|
||||
from past.builtins import basestring
|
||||
|
||||
import octoprint.plugin
|
||||
from octoprint.access.permissions import OctoPrintPermission, Permissions
|
||||
@@ -501,7 +500,7 @@ def index():
|
||||
)
|
||||
)
|
||||
|
||||
if lastmodified and not isinstance(lastmodified, basestring):
|
||||
if lastmodified and not isinstance(lastmodified, str):
|
||||
from werkzeug.http import http_date
|
||||
|
||||
lastmodified = http_date(lastmodified)
|
||||
@@ -1564,7 +1563,7 @@ def _compute_etag_for_i18n(locale, domain, files=None, lastmodified=None):
|
||||
files = _get_all_translationfiles(locale, domain)
|
||||
if lastmodified is None:
|
||||
lastmodified = _compute_date(files)
|
||||
if lastmodified and not isinstance(lastmodified, basestring):
|
||||
if lastmodified and not isinstance(lastmodified, str):
|
||||
from werkzeug.http import http_date
|
||||
|
||||
lastmodified = http_date(lastmodified)
|
||||
|
||||
@@ -32,9 +32,6 @@ from collections import ChainMap
|
||||
import yaml
|
||||
import yaml.parser
|
||||
|
||||
# noinspection PyCompatibility
|
||||
from past.builtins import basestring
|
||||
|
||||
try:
|
||||
from collections.abc import KeysView
|
||||
except ImportError:
|
||||
@@ -768,7 +765,7 @@ class Settings:
|
||||
lambda x: key + "/" + x, self._get_templates(scripts[key])
|
||||
)
|
||||
)
|
||||
elif isinstance(scripts[key], basestring):
|
||||
elif isinstance(scripts[key], str):
|
||||
templates.append(key)
|
||||
return templates
|
||||
|
||||
@@ -1011,7 +1008,7 @@ class Settings:
|
||||
self._logger.exception("Error loading overlay from callable")
|
||||
return
|
||||
|
||||
if isinstance(overlay, basestring):
|
||||
if isinstance(overlay, str):
|
||||
if os.path.exists(overlay) and os.path.isfile(overlay):
|
||||
with io.open(overlay, "rt", encoding="utf-8", errors="replace") as f:
|
||||
config = yaml.safe_load(f)
|
||||
@@ -1828,7 +1825,7 @@ class Settings:
|
||||
return value
|
||||
if isinstance(value, (int, float)):
|
||||
return value != 0
|
||||
if isinstance(value, basestring):
|
||||
if isinstance(value, str):
|
||||
return value.lower() in valid_boolean_trues
|
||||
return value is not None
|
||||
|
||||
@@ -2083,7 +2080,7 @@ class Settings:
|
||||
def setBoolean(self, path, value, **kwargs):
|
||||
if value is None or isinstance(value, bool):
|
||||
self.set(path, value, **kwargs)
|
||||
elif isinstance(value, basestring) and value.lower() in valid_boolean_trues:
|
||||
elif isinstance(value, str) and value.lower() in valid_boolean_trues:
|
||||
self.set(path, True, **kwargs)
|
||||
else:
|
||||
self.set(path, False, **kwargs)
|
||||
|
||||
@@ -27,10 +27,6 @@ from time import monotonic as monotonic_time # noqa: F401
|
||||
from typing import Union
|
||||
|
||||
import frozendict
|
||||
import past.builtins
|
||||
|
||||
# noinspection PyCompatibility
|
||||
from past.builtins import basestring, unicode
|
||||
|
||||
from octoprint import UMASK
|
||||
from octoprint.util.connectivity import ConnectivityChecker # noqa: F401
|
||||
@@ -44,7 +40,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def to_bytes(s_or_u, encoding="utf-8", errors="strict"):
|
||||
# type: (Union[unicode, bytes], str, str) -> bytes
|
||||
# type: (Union[str, bytes], str, str) -> Union[bytes, None]
|
||||
"""
|
||||
Make sure ``s_or_u`` is a byte string.
|
||||
|
||||
@@ -58,17 +54,17 @@ def to_bytes(s_or_u, encoding="utf-8", errors="strict"):
|
||||
if s_or_u is None:
|
||||
return s_or_u
|
||||
|
||||
if not isinstance(s_or_u, basestring):
|
||||
if not isinstance(s_or_u, (str, bytes)):
|
||||
s_or_u = str(s_or_u)
|
||||
|
||||
if isinstance(s_or_u, unicode):
|
||||
if isinstance(s_or_u, str):
|
||||
return s_or_u.encode(encoding, errors=errors)
|
||||
else:
|
||||
return s_or_u
|
||||
|
||||
|
||||
def to_unicode(s_or_u, encoding="utf-8", errors="strict"):
|
||||
# type: (Union[unicode, bytes], str, str) -> unicode
|
||||
# type: (Union[str, bytes], str, str) -> Union[str, None]
|
||||
"""
|
||||
Make sure ``s_or_u`` is a unicode string.
|
||||
|
||||
@@ -82,7 +78,7 @@ def to_unicode(s_or_u, encoding="utf-8", errors="strict"):
|
||||
if s_or_u is None:
|
||||
return s_or_u
|
||||
|
||||
if not isinstance(s_or_u, basestring):
|
||||
if not isinstance(s_or_u, (str, bytes)):
|
||||
s_or_u = str(s_or_u)
|
||||
|
||||
if isinstance(s_or_u, bytes):
|
||||
@@ -665,9 +661,9 @@ def silent_remove(file):
|
||||
|
||||
|
||||
def sanitize_ascii(line):
|
||||
if not isinstance(line, basestring):
|
||||
if not isinstance(line, (str, bytes)):
|
||||
raise ValueError(
|
||||
"Expected either str or unicode but got {} instead".format(
|
||||
"Expected either str or bytes but got {} instead".format(
|
||||
line.__class__.__name__ if line is not None else None
|
||||
)
|
||||
)
|
||||
@@ -1099,8 +1095,8 @@ def guess_mime_type(data):
|
||||
def parse_mime_type(mime):
|
||||
import cgi
|
||||
|
||||
if not mime or not isinstance(mime, basestring):
|
||||
raise ValueError("mime must be a non empty str or unicode")
|
||||
if not mime or not isinstance(mime, (str, bytes)):
|
||||
raise ValueError("mime must be a non empty str or bytes")
|
||||
|
||||
mime, params = cgi.parse_header(mime)
|
||||
|
||||
@@ -1761,12 +1757,10 @@ class CaseInsensitiveSet(collections.Set):
|
||||
"""
|
||||
|
||||
def __init__(self, *args):
|
||||
self.data = {
|
||||
x.lower() if isinstance(x, past.builtins.basestring) else x for x in args
|
||||
}
|
||||
self.data = {x.lower() if isinstance(x, str) else x for x in args}
|
||||
|
||||
def __contains__(self, item):
|
||||
if isinstance(item, past.builtins.basestring):
|
||||
if isinstance(item, str):
|
||||
return item.lower() in self.data
|
||||
else:
|
||||
return item in self.data
|
||||
|
||||
@@ -21,7 +21,6 @@ from collections import deque
|
||||
|
||||
import serial
|
||||
import wrapt
|
||||
from past.builtins import basestring
|
||||
|
||||
import octoprint.plugin
|
||||
from octoprint.events import Events, eventManager
|
||||
@@ -1257,7 +1256,7 @@ class MachineCom:
|
||||
continue
|
||||
|
||||
def to_list(data, t):
|
||||
if isinstance(data, basestring):
|
||||
if isinstance(data, str):
|
||||
data = list(s.strip() for s in data.split("\n"))
|
||||
|
||||
if isinstance(data, (list, tuple)):
|
||||
@@ -1292,7 +1291,7 @@ class MachineCom:
|
||||
if (
|
||||
isinstance(line, tuple)
|
||||
and len(line) == 2
|
||||
and isinstance(line[0], basestring)
|
||||
and isinstance(line[0], str)
|
||||
and isinstance(line[1], set)
|
||||
):
|
||||
tags = line[1]
|
||||
@@ -1323,13 +1322,13 @@ class MachineCom:
|
||||
if (
|
||||
isinstance(line, tuple)
|
||||
and len(line) == 2
|
||||
and isinstance(line[0], basestring)
|
||||
and isinstance(line[0], str)
|
||||
and isinstance(line[1], set)
|
||||
):
|
||||
# 2-tuple: line + tags
|
||||
ttu = tags_to_use | line[1]
|
||||
line = line[0]
|
||||
elif isinstance(line, basestring):
|
||||
elif isinstance(line, str):
|
||||
# just a line
|
||||
ttu = tags_to_use
|
||||
else:
|
||||
@@ -1338,9 +1337,7 @@ class MachineCom:
|
||||
|
||||
self.sendCommand(line, part_of_job=part_of_job, tags=ttu)
|
||||
|
||||
return "\n".join(
|
||||
map(lambda x: x if isinstance(x, basestring) else x[0], scriptLines)
|
||||
)
|
||||
return "\n".join(map(lambda x: x if isinstance(x, str) else x[0], scriptLines))
|
||||
|
||||
def startPrint(self, pos=None, tags=None, external_sd=False, user=None):
|
||||
if not self.isOperational() or self.isPrinting():
|
||||
@@ -4736,7 +4733,7 @@ class MachineCom:
|
||||
# noinspection PyCompatibility
|
||||
if isinstance(d, tuple) and len(d) == 2:
|
||||
result.append((d[0], None, d[1]))
|
||||
elif isinstance(d, basestring):
|
||||
elif isinstance(d, str):
|
||||
result.append(d)
|
||||
return result
|
||||
|
||||
@@ -6284,7 +6281,7 @@ def _normalize_command_handler_result(
|
||||
# copy the tags
|
||||
tags = set(tags)
|
||||
|
||||
if isinstance(handler_result, basestring):
|
||||
if isinstance(handler_result, str):
|
||||
# entry is just a string, replace command with it
|
||||
command = handler_result
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import re
|
||||
import time
|
||||
|
||||
import sarge
|
||||
from past.builtins import unicode
|
||||
|
||||
from octoprint.util.platform import CLOSE_FDS
|
||||
|
||||
@@ -31,10 +30,10 @@ def clean_ansi(line):
|
||||
Removes ANSI control codes from ``line``.
|
||||
|
||||
Parameters:
|
||||
line (bytes or unicode): the line to process
|
||||
line (bytes or str): the line to process
|
||||
|
||||
Returns:
|
||||
(bytes or unicode) The line without any ANSI control codes
|
||||
(bytes or str) The line without any ANSI control codes
|
||||
|
||||
Example::
|
||||
|
||||
@@ -45,7 +44,7 @@ def clean_ansi(line):
|
||||
>>> clean_ansi(text) # doctest: +ALLOW_BYTES
|
||||
'We hide the cursor here and then show it again here'
|
||||
"""
|
||||
if isinstance(line, unicode):
|
||||
if isinstance(line, str):
|
||||
return _ANSI_REGEX.sub(b"", line.encode("latin1")).decode("latin1")
|
||||
return _ANSI_REGEX.sub(b"", line)
|
||||
|
||||
|
||||
@@ -60,11 +60,9 @@ def has_requirement(requirement, requirements):
|
||||
if requirement is None or requirements is None:
|
||||
return False
|
||||
|
||||
# from past.builtins import basestring
|
||||
|
||||
# assert isinstance(requirement, basestring)
|
||||
# assert isinstance(requirement, str)
|
||||
# assert isinstance(requirements, (list, tuple))
|
||||
# assert all(list(map(lambda x: x is not None and isinstance(x, basestring), requirements)))
|
||||
# assert all(list(map(lambda x: x is not None and isinstance(x, str), requirements)))
|
||||
|
||||
requirement = requirement.lower()
|
||||
requirements = [r.lower() for r in requirements]
|
||||
|
||||
Reference in new issue
Block a user