list()-ify keys(), values() and items()
where required. At some places it's not. Also, "if foo in some_dict.keys()" is unnecessarily slow. Replaced with "if foo in some_dict". I left "for key in some_dict.keys()" alone; "for key in some_dict" is equivalent but not always obvious.
This commit is contained in:
1 parent
63723baf07
commit
828ba56952
20 files changed
+113
-89
No files matched your search
@@ -263,7 +263,7 @@ class FilebasedGroupManager(GroupManager):
|
||||
|
||||
def add_group(self, key, name, description, permissions, default=False, removable=True,
|
||||
changeable=True, toggleable=True, overwrite=False, notify=True, save=True):
|
||||
if key in self._groups.keys() and not overwrite:
|
||||
if key in self._groups and not overwrite:
|
||||
raise GroupAlreadyExists(key)
|
||||
|
||||
if not permissions:
|
||||
|
||||
@@ -217,7 +217,7 @@ class PermissionsMetaClass(type):
|
||||
return permission
|
||||
|
||||
def all(cls):
|
||||
return cls.permissions.values()
|
||||
return list(cls.permissions.values())
|
||||
|
||||
def filter(cls, cb):
|
||||
return list(filter(cb, cls.all()))
|
||||
|
||||
@@ -439,8 +439,7 @@ class FilebasedUserManager(UserManager):
|
||||
self._customized = True
|
||||
with io.open(self._userfile, 'rt', encoding='utf-8') as f:
|
||||
data = yaml.safe_load(f)
|
||||
for name in data.keys():
|
||||
attributes = data[name]
|
||||
for name, attributes in data.values():
|
||||
permissions = []
|
||||
if "permissions" in attributes:
|
||||
permissions = attributes["permissions"]
|
||||
@@ -485,9 +484,7 @@ class FilebasedUserManager(UserManager):
|
||||
return
|
||||
|
||||
data = {}
|
||||
for name in self._users.keys():
|
||||
user = self._users[name]
|
||||
|
||||
for name, user in self._users.items():
|
||||
if not user or not isinstance(user, User):
|
||||
continue
|
||||
|
||||
@@ -527,7 +524,7 @@ class FilebasedUserManager(UserManager):
|
||||
groups = self._group_manager.default_groups
|
||||
groups = self._to_groups(*groups)
|
||||
|
||||
if username in self._users.keys() and not overwrite:
|
||||
if username in self._users and not overwrite:
|
||||
raise UserAlreadyExists(username)
|
||||
|
||||
self._users[username] = User(username, UserManager.create_password_hash(password), active, permissions, groups, apikey=apikey)
|
||||
@@ -535,7 +532,7 @@ class FilebasedUserManager(UserManager):
|
||||
self._save()
|
||||
|
||||
def change_user_activation(self, username, active):
|
||||
if username not in self._users.keys():
|
||||
if username not in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
if self._users[username].is_active != active:
|
||||
@@ -546,7 +543,7 @@ class FilebasedUserManager(UserManager):
|
||||
self._trigger_on_user_modified(username)
|
||||
|
||||
def change_user_permissions(self, username, permissions):
|
||||
if username not in self._users.keys():
|
||||
if username not in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
user = self._users[username]
|
||||
@@ -569,7 +566,7 @@ class FilebasedUserManager(UserManager):
|
||||
self._trigger_on_user_modified(username)
|
||||
|
||||
def add_permissions_to_user(self, username, permissions):
|
||||
if username not in self._users.keys():
|
||||
if username not in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
if self._users[username].add_permissions_to_user(self._to_permissions(*permissions)):
|
||||
@@ -578,7 +575,7 @@ class FilebasedUserManager(UserManager):
|
||||
self._trigger_on_user_modified(username)
|
||||
|
||||
def remove_permissions_from_user(self, username, permissions):
|
||||
if username not in self._users.keys():
|
||||
if username not in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
if self._users[username].remove_permissions_from_user(self._to_permissions(*permissions)):
|
||||
@@ -588,7 +585,7 @@ class FilebasedUserManager(UserManager):
|
||||
|
||||
def remove_permissions_from_users(self, permissions):
|
||||
modified = []
|
||||
for user in self._users.keys():
|
||||
for user in self._users:
|
||||
dirty = user.remove_permissions_from_user(self._to_permissions(*permissions))
|
||||
if dirty:
|
||||
self._dirty = True
|
||||
@@ -600,7 +597,7 @@ class FilebasedUserManager(UserManager):
|
||||
self._trigger_on_user_modified(username)
|
||||
|
||||
def change_user_groups(self, username, groups):
|
||||
if username not in self._users.keys():
|
||||
if username not in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
user = self._users[username]
|
||||
@@ -620,7 +617,7 @@ class FilebasedUserManager(UserManager):
|
||||
self._trigger_on_user_modified(username)
|
||||
|
||||
def add_groups_to_user(self, username, groups, save=True, notify=True):
|
||||
if username not in self._users.keys():
|
||||
if username not in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
if self._users[username].add_groups_to_user(self._to_groups(*groups)):
|
||||
@@ -633,7 +630,7 @@ class FilebasedUserManager(UserManager):
|
||||
self._trigger_on_user_modified(username)
|
||||
|
||||
def remove_groups_from_user(self, username, groups, save=True, notify=True):
|
||||
if username not in self._users.keys():
|
||||
if username not in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
if self._users[username].remove_groups_from_user(self._to_groups(*groups)):
|
||||
@@ -647,8 +644,8 @@ class FilebasedUserManager(UserManager):
|
||||
|
||||
def remove_groups_from_users(self, groups):
|
||||
modified = []
|
||||
for username in self._users.keys():
|
||||
dirty = self._users[username].remove_groups_from_user(self._to_groups(*groups))
|
||||
for username, user in self._users.items():
|
||||
dirty = user.remove_groups_from_user(self._to_groups(*groups))
|
||||
if dirty:
|
||||
self._dirty = True
|
||||
modified.append(username)
|
||||
@@ -660,7 +657,7 @@ class FilebasedUserManager(UserManager):
|
||||
self._trigger_on_user_modified(username)
|
||||
|
||||
def change_user_password(self, username, password):
|
||||
if not username in self._users.keys():
|
||||
if not username in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
passwordHash = UserManager.create_password_hash(password)
|
||||
@@ -671,7 +668,7 @@ class FilebasedUserManager(UserManager):
|
||||
self._save()
|
||||
|
||||
def change_user_setting(self, username, key, value):
|
||||
if not username in self._users.keys():
|
||||
if not username in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
user = self._users[username]
|
||||
@@ -693,21 +690,21 @@ class FilebasedUserManager(UserManager):
|
||||
self._save()
|
||||
|
||||
def get_all_user_settings(self, username):
|
||||
if not username in self._users.keys():
|
||||
if not username in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
user = self._users[username]
|
||||
return user.get_all_settings()
|
||||
|
||||
def get_user_setting(self, username, key):
|
||||
if not username in self._users.keys():
|
||||
if not username in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
user = self._users[username]
|
||||
return user.get_setting(key)
|
||||
|
||||
def generate_api_key(self, username):
|
||||
if not username in self._users.keys():
|
||||
if not username in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
user = self._users[username]
|
||||
@@ -717,7 +714,7 @@ class FilebasedUserManager(UserManager):
|
||||
return user._apikey
|
||||
|
||||
def delete_api_key(self, username):
|
||||
if not username in self._users.keys():
|
||||
if not username in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
user = self._users[username]
|
||||
@@ -728,7 +725,7 @@ class FilebasedUserManager(UserManager):
|
||||
def remove_user(self, username):
|
||||
UserManager.remove_user(self, username)
|
||||
|
||||
if not username in self._users.keys():
|
||||
if not username in self._users:
|
||||
raise UnknownUser(username)
|
||||
|
||||
del self._users[username]
|
||||
@@ -742,7 +739,7 @@ class FilebasedUserManager(UserManager):
|
||||
return user
|
||||
|
||||
if userid is not None:
|
||||
if userid not in self._users.keys():
|
||||
if userid not in self._users:
|
||||
return None
|
||||
return self._users[userid]
|
||||
|
||||
|
||||
@@ -336,12 +336,12 @@ class CommandTrigger(GenericEventListener):
|
||||
self._logger.info("Invalid subscription definition, not a dictionary: {!r}".format(subscription))
|
||||
continue
|
||||
|
||||
if not "event" in subscription.keys() or not "command" in subscription.keys() \
|
||||
or not "type" in subscription.keys() or not subscription["type"] in ["system", "gcode"]:
|
||||
if not "event" in subscription or not "command" in subscription \
|
||||
or not "type" in subscription or not subscription["type"] in ["system", "gcode"]:
|
||||
self._logger.info("Invalid command trigger, missing either event, type or command or type is invalid: {!r}".format(subscription))
|
||||
continue
|
||||
|
||||
if "enabled" in subscription.keys() and not subscription["enabled"]:
|
||||
if "enabled" in subscription and not subscription["enabled"]:
|
||||
self._logger.info("Disabled command trigger: {!r}".format(subscription))
|
||||
continue
|
||||
|
||||
@@ -350,11 +350,11 @@ class CommandTrigger(GenericEventListener):
|
||||
commandType = subscription["type"]
|
||||
debug = subscription["debug"] if "debug" in subscription else False
|
||||
|
||||
if not event in self._subscriptions.keys():
|
||||
if event not in self._subscriptions:
|
||||
self._subscriptions[event] = []
|
||||
self._subscriptions[event].append((command, commandType, debug))
|
||||
|
||||
if not event in eventsToSubscribe:
|
||||
if event not in eventsToSubscribe:
|
||||
eventsToSubscribe.append(event)
|
||||
|
||||
self.subscribe(eventsToSubscribe)
|
||||
|
||||
@@ -449,7 +449,7 @@ class FileManager(object):
|
||||
|
||||
def list_files(self, destinations=None, path=None, filter=None, recursive=None):
|
||||
if not destinations:
|
||||
destinations = self._storage_managers.keys()
|
||||
destinations = list(self._storage_managers.keys())
|
||||
if isinstance(destinations, basestring):
|
||||
destinations = [destinations]
|
||||
|
||||
|
||||
@@ -80,14 +80,14 @@ class AclSubwizard(object):
|
||||
data = request.values
|
||||
|
||||
if "ac" in data and data["ac"] in valid_boolean_trues and \
|
||||
"user" in data.keys() and "pass1" in data.keys() and \
|
||||
"pass2" in data.keys() and data["pass1"] == data["pass2"]:
|
||||
"user" in data and "pass1" in data and \
|
||||
"pass2" in data and data["pass1"] == data["pass2"]:
|
||||
# configure access control
|
||||
self._settings.global_set_boolean(["accessControl", "enabled"], True)
|
||||
self._user_manager.enable()
|
||||
|
||||
self._user_manager.add_user(data["user"], data["pass1"], True, [], [USER_GROUP, ADMIN_GROUP], overwrite=True)
|
||||
elif "ac" in data.keys() and not data["ac"] in valid_boolean_trues:
|
||||
elif "ac" in data and not data["ac"] in valid_boolean_trues:
|
||||
# disable access control
|
||||
self._settings.global_set_boolean(["accessControl", "enabled"], False)
|
||||
|
||||
|
||||
@@ -663,7 +663,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||
|
||||
checks = self._get_configured_checks()
|
||||
if check_targets is None:
|
||||
check_targets = checks.keys()
|
||||
check_targets = list(checks.keys())
|
||||
|
||||
update_available = False
|
||||
update_possible = False
|
||||
@@ -1209,7 +1209,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||
python_updater=updaters.python_updater,
|
||||
sleep_a_bit=updaters.sleep_a_bit)
|
||||
|
||||
method = self._get_update_method(target, check, valid_methods=mapping.keys())
|
||||
method = self._get_update_method(target, check, valid_methods=list(mapping.keys()))
|
||||
return mapping[method]
|
||||
|
||||
def _get_octoprint_checkout_folder(self, checks=None):
|
||||
|
||||
@@ -374,7 +374,7 @@ class PrinterProfileManager(object):
|
||||
return copy.deepcopy(self.__class__.default)
|
||||
|
||||
def set_default(self, identifier):
|
||||
all_identifiers = self._load_all_identifiers().keys()
|
||||
all_identifiers = self._load_all_identifiers()
|
||||
if identifier is not None and not identifier in all_identifiers:
|
||||
return
|
||||
|
||||
@@ -515,7 +515,7 @@ class PrinterProfileManager(object):
|
||||
def _ensure_valid_profile(self, profile):
|
||||
# ensure all keys are present
|
||||
if not dict_contains_keys(self.default, profile):
|
||||
self._logger.warning("Profile invalid, missing keys. Expected: {expected!r}. Actual: {actual!r}".format(expected=self.default.keys(), actual=profile.keys()))
|
||||
self._logger.warning("Profile invalid, missing keys. Expected: {expected!r}. Actual: {actual!r}".format(expected=list(self.default.keys()), actual=list(profile.keys())))
|
||||
return False
|
||||
|
||||
# conversion helper
|
||||
|
||||
@@ -944,7 +944,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
if "analysis" in fileData:
|
||||
if estimatedPrintTime is None and "estimatedPrintTime" in fileData["analysis"]:
|
||||
estimatedPrintTime = fileData["analysis"]["estimatedPrintTime"]
|
||||
if "filament" in fileData["analysis"].keys():
|
||||
if "filament" in fileData["analysis"]:
|
||||
filament = fileData["analysis"]["filament"]
|
||||
if "statistics" in fileData:
|
||||
printer_profile = self._printerProfileManager.get_current_or_default()["id"]
|
||||
|
||||
@@ -47,23 +47,23 @@ def connectionCommand():
|
||||
port = None
|
||||
baudrate = None
|
||||
printerProfile = None
|
||||
if "port" in data.keys():
|
||||
if "port" in data:
|
||||
port = data["port"]
|
||||
if port not in connection_options["ports"] and port != "AUTO":
|
||||
return make_response("Invalid port: %s" % port, 400)
|
||||
if "baudrate" in data.keys():
|
||||
if "baudrate" in data:
|
||||
baudrate = data["baudrate"]
|
||||
if baudrate not in connection_options["baudrates"] and baudrate != 0:
|
||||
return make_response("Invalid baudrate: %d" % baudrate, 400)
|
||||
if "printerProfile" in data.keys():
|
||||
if "printerProfile" in data:
|
||||
printerProfile = data["printerProfile"]
|
||||
if not printerProfileManager.exists(printerProfile):
|
||||
return make_response("Invalid printer profile: %s" % printerProfile, 400)
|
||||
if "save" in data.keys() and data["save"]:
|
||||
if "save" in data and data["save"]:
|
||||
settings().set(["serial", "port"], port)
|
||||
settings().setInt(["serial", "baudrate"], baudrate)
|
||||
printerProfileManager.set_default(printerProfile)
|
||||
if "autoconnect" in data.keys():
|
||||
if "autoconnect" in data:
|
||||
settings().setBoolean(["serial", "autoconnect"], data["autoconnect"])
|
||||
settings().save()
|
||||
printer.connect(port=port, baudrate=baudrate, profile=printerProfile)
|
||||
|
||||
@@ -187,7 +187,7 @@ def _getFileList(origin, path=None, filter=None, recursive=False, allow_from_cac
|
||||
cache_key = "{}:{}:{}:{}".format(origin, path, recursive, filter)
|
||||
files, lastmodified = _file_cache.get(cache_key, ([], None))
|
||||
if not allow_from_cache or lastmodified is None or lastmodified < fileManager.last_modified(origin, path=path, recursive=recursive):
|
||||
files = fileManager.list_files(origin, path=path, filter=filter_func, recursive=recursive)[origin].values()
|
||||
files = list(fileManager.list_files(origin, path=path, filter=filter_func, recursive=recursive)[origin].values())
|
||||
lastmodified = fileManager.last_modified(origin, path=path, recursive=recursive)
|
||||
_file_cache[cache_key] = (files, lastmodified)
|
||||
|
||||
@@ -296,8 +296,8 @@ def uploadGcodeFile(target):
|
||||
return make_response("SD card support is disabled", 404)
|
||||
|
||||
sd = target == FileDestinations.SDCARD
|
||||
selectAfterUpload = "select" in request.values.keys() and request.values["select"] in valid_boolean_trues and Permissions.FILES_SELECT.can()
|
||||
printAfterSelect = "print" in request.values.keys() and request.values["print"] in valid_boolean_trues and Permissions.PRINT.can()
|
||||
selectAfterUpload = "select" in request.values and request.values["select"] in valid_boolean_trues and Permissions.FILES_SELECT.can()
|
||||
printAfterSelect = "print" in request.values and request.values["print"] in valid_boolean_trues and Permissions.PRINT.can()
|
||||
|
||||
if sd:
|
||||
# validate that all preconditions for SD upload are met before attempting it
|
||||
@@ -519,7 +519,7 @@ def gcodeFileCommand(filename, target):
|
||||
return make_response("Cannot select {filename} for printing, not a machinecode file".format(**locals()), 415)
|
||||
|
||||
printAfterLoading = False
|
||||
if "print" in data.keys() and data["print"] in valid_boolean_trues:
|
||||
if "print" in data and data["print"] in valid_boolean_trues:
|
||||
with Permissions.PRINT.require(403):
|
||||
if not printer.is_operational():
|
||||
return make_response("Printer is not operational, cannot directly start printing", 409)
|
||||
@@ -592,32 +592,32 @@ def gcodeFileCommand(filename, target):
|
||||
if currentFilename == full_path and currentOrigin == target and (printer.is_printing() or printer.is_paused()):
|
||||
make_response("Trying to slice into file that is currently being printed: %s" % full_path, 409)
|
||||
|
||||
if "profile" in data.keys() and data["profile"]:
|
||||
if "profile" in data and data["profile"]:
|
||||
profile = data["profile"]
|
||||
del data["profile"]
|
||||
else:
|
||||
profile = None
|
||||
|
||||
if "printerProfile" in data.keys() and data["printerProfile"]:
|
||||
if "printerProfile" in data and data["printerProfile"]:
|
||||
printerProfile = data["printerProfile"]
|
||||
del data["printerProfile"]
|
||||
else:
|
||||
printerProfile = None
|
||||
|
||||
if "position" in data.keys() and data["position"] and isinstance(data["position"], dict) and "x" in data["position"] and "y" in data["position"]:
|
||||
if "position" in data and data["position"] and isinstance(data["position"], dict) and "x" in data["position"] and "y" in data["position"]:
|
||||
position = data["position"]
|
||||
del data["position"]
|
||||
else:
|
||||
position = None
|
||||
|
||||
select_after_slicing = False
|
||||
if "select" in data.keys() and data["select"] in valid_boolean_trues:
|
||||
if "select" in data and data["select"] in valid_boolean_trues:
|
||||
if not printer.is_operational():
|
||||
return make_response("Printer is not operational, cannot directly select for printing", 409)
|
||||
select_after_slicing = True
|
||||
|
||||
print_after_slicing = False
|
||||
if "print" in data.keys() and data["print"] in valid_boolean_trues:
|
||||
if "print" in data and data["print"] in valid_boolean_trues:
|
||||
if not printer.is_operational():
|
||||
return make_response("Printer is not operational, cannot directly start printing", 409)
|
||||
select_after_slicing = print_after_slicing = True
|
||||
@@ -799,7 +799,7 @@ def deleteGcodeFile(filename, target):
|
||||
|
||||
def _getCurrentFile():
|
||||
currentJob = printer.get_current_job()
|
||||
if currentJob is not None and "file" in currentJob.keys() and "path" in currentJob["file"] and "origin" in currentJob["file"]:
|
||||
if currentJob is not None and "file" in currentJob and "path" in currentJob["file"] and "origin" in currentJob["file"]:
|
||||
return currentJob["file"]["origin"], currentJob["file"]["path"]
|
||||
else:
|
||||
return None, None
|
||||
|
||||
@@ -414,11 +414,11 @@ def _get_temperature_data(preprocessor):
|
||||
|
||||
tempData = printer.get_current_temperatures()
|
||||
|
||||
if "history" in request.values.keys() and request.values["history"] in valid_boolean_trues:
|
||||
if "history" in request.values and request.values["history"] in valid_boolean_trues:
|
||||
tempHistory = printer.get_temperature_history()
|
||||
|
||||
limit = 300
|
||||
if "limit" in request.values.keys() and unicode(request.values["limit"]).isnumeric():
|
||||
if "limit" in request.values and unicode(request.values["limit"]).isnumeric():
|
||||
limit = int(request.values["limit"])
|
||||
|
||||
history = list(tempHistory)
|
||||
|
||||
@@ -361,7 +361,7 @@ def _saveSettings(data):
|
||||
# NOTE: Remember to adjust the docs of the data model on the Settings API if anything
|
||||
# is changed, added or removed here
|
||||
|
||||
if "folder" in data.keys():
|
||||
if "folder" in data:
|
||||
try:
|
||||
if "uploads" in data["folder"]: s.setBaseFolder("uploads", data["folder"]["uploads"])
|
||||
if "timelapse" in data["folder"]: s.setBaseFolder("timelapse", data["folder"]["timelapse"])
|
||||
@@ -371,12 +371,12 @@ def _saveSettings(data):
|
||||
except IOError:
|
||||
return make_response("One of the configured folders is invalid", 400)
|
||||
|
||||
if "api" in data.keys():
|
||||
if "api" in data:
|
||||
if "enabled" in data["api"]: s.setBoolean(["api", "enabled"], data["api"]["enabled"])
|
||||
if "keyEnforced" in data["api"]: s.setBoolean(["api", "keyEnforced"], data["api"]["keyEnforced"])
|
||||
if "allowCrossOrigin" in data["api"]: s.setBoolean(["api", "allowCrossOrigin"], data["api"]["allowCrossOrigin"])
|
||||
|
||||
if "appearance" in data.keys():
|
||||
if "appearance" in data:
|
||||
if "name" in data["appearance"]: s.set(["appearance", "name"], data["appearance"]["name"])
|
||||
if "color" in data["appearance"]: s.set(["appearance", "color"], data["appearance"]["color"])
|
||||
if "colorTransparent" in data["appearance"]: s.setBoolean(["appearance", "colorTransparent"], data["appearance"]["colorTransparent"])
|
||||
@@ -384,10 +384,10 @@ def _saveSettings(data):
|
||||
if "defaultLanguage" in data["appearance"]: s.set(["appearance", "defaultLanguage"], data["appearance"]["defaultLanguage"])
|
||||
if "showFahrenheitAlso" in data["appearance"]: s.setBoolean(["appearance", "showFahrenheitAlso"], data["appearance"]["showFahrenheitAlso"])
|
||||
|
||||
if "printer" in data.keys():
|
||||
if "printer" in data:
|
||||
if "defaultExtrusionLength" in data["printer"]: s.setInt(["printerParameters", "defaultExtrusionLength"], data["printer"]["defaultExtrusionLength"])
|
||||
|
||||
if "webcam" in data.keys():
|
||||
if "webcam" in data:
|
||||
if "webcamEnabled" in data["webcam"]: s.setBoolean(["webcam", "webcamEnabled"], data["webcam"]["webcamEnabled"])
|
||||
if "timelapseEnabled" in data["webcam"]: s.setBoolean(["webcam", "timelapseEnabled"], data["webcam"]["timelapseEnabled"])
|
||||
if "streamUrl" in data["webcam"]: s.set(["webcam", "stream"], data["webcam"]["streamUrl"])
|
||||
@@ -405,7 +405,7 @@ def _saveSettings(data):
|
||||
if "flipV" in data["webcam"]: s.setBoolean(["webcam", "flipV"], data["webcam"]["flipV"])
|
||||
if "rotate90" in data["webcam"]: s.setBoolean(["webcam", "rotate90"], data["webcam"]["rotate90"])
|
||||
|
||||
if "feature" in data.keys():
|
||||
if "feature" in data:
|
||||
if "gcodeViewer" in data["feature"]: s.setBoolean(["gcodeViewer", "enabled"], data["feature"]["gcodeViewer"])
|
||||
if "sizeThreshold" in data["feature"]: s.setInt(["gcodeViewer", "sizeThreshold"], data["feature"]["sizeThreshold"])
|
||||
if "mobileSizeThreshold" in data["feature"]: s.setInt(["gcodeViewer", "mobileSizeThreshold"], data["feature"]["mobileSizeThreshold"])
|
||||
@@ -418,7 +418,7 @@ def _saveSettings(data):
|
||||
if "g90InfluencesExtruder" in data["feature"]: s.setBoolean(["feature", "g90InfluencesExtruder"], data["feature"]["g90InfluencesExtruder"])
|
||||
if "autoUppercaseBlacklist" in data["feature"] and isinstance(data["feature"]["autoUppercaseBlacklist"], (list, tuple)): s.set(["feature", "autoUppercaseBlacklist"], data["feature"]["autoUppercaseBlacklist"])
|
||||
|
||||
if "serial" in data.keys():
|
||||
if "serial" in data:
|
||||
if "autoconnect" in data["serial"]: s.setBoolean(["serial", "autoconnect"], data["serial"]["autoconnect"])
|
||||
if "port" in data["serial"]: s.set(["serial", "port"], data["serial"]["port"])
|
||||
if "baudrate" in data["serial"]: s.setInt(["serial", "baudrate"], data["serial"]["baudrate"])
|
||||
@@ -479,7 +479,7 @@ def _saveSettings(data):
|
||||
logging.getLogger("SERIAL").setLevel(logging.DEBUG)
|
||||
logging.getLogger("SERIAL").debug("Enabling serial logging")
|
||||
|
||||
if "temperature" in data.keys():
|
||||
if "temperature" in data:
|
||||
if "profiles" in data["temperature"]:
|
||||
result = []
|
||||
for profile in data["temperature"]["profiles"]:
|
||||
@@ -500,10 +500,10 @@ def _saveSettings(data):
|
||||
if "sendAutomatically" in data["temperature"]: s.setBoolean(["temperature", "sendAutomatically"], data["temperature"]["sendAutomatically"])
|
||||
if "sendAutomaticallyAfter" in data["temperature"]: s.setInt(["temperature", "sendAutomaticallyAfter"], data["temperature"]["sendAutomaticallyAfter"], min=0, max=30)
|
||||
|
||||
if "terminalFilters" in data.keys():
|
||||
if "terminalFilters" in data:
|
||||
s.set(["terminalFilters"], data["terminalFilters"])
|
||||
|
||||
if "system" in data.keys():
|
||||
if "system" in data:
|
||||
if "actions" in data["system"]: s.set(["system", "actions"], data["system"]["actions"])
|
||||
if "events" in data["system"]: s.set(["system", "events"], data["system"]["events"])
|
||||
|
||||
|
||||
@@ -263,7 +263,7 @@ def get_api_key(request):
|
||||
return request.arguments["apikey"]
|
||||
|
||||
# Check Tornado and Flask headers
|
||||
if "X-Api-Key" in request.headers.keys():
|
||||
if "X-Api-Key" in request.headers:
|
||||
return request.headers.get("X-Api-Key")
|
||||
|
||||
return None
|
||||
|
||||
@@ -1294,7 +1294,7 @@ def get_json_command_from_request(request, valid_commands):
|
||||
data = request.get_json()
|
||||
if data is None:
|
||||
return None, None, make_response("Malformed JSON body or wrong content-type in request", 400)
|
||||
if not "command" in data.keys() or not data["command"] in valid_commands.keys():
|
||||
if not "command" in data or not data["command"] in valid_commands:
|
||||
return None, None, make_response("Expected valid command", 400)
|
||||
|
||||
command = data["command"]
|
||||
|
||||
@@ -532,7 +532,7 @@ def fetch_template_data(refresh=False):
|
||||
|
||||
template_rules["plugin_" + name + "_" + key] = rule
|
||||
template_sorting["plugin_" + name + "_" + key] = order
|
||||
template_types = template_rules.keys()
|
||||
template_types = list(template_rules.keys())
|
||||
|
||||
# navbar
|
||||
|
||||
|
||||
@@ -1070,7 +1070,7 @@ class Settings(object):
|
||||
|
||||
Added in 1.2.0
|
||||
"""
|
||||
if "server" in config.keys() and ("baseUrl" in config["server"] or "scheme" in config["server"]):
|
||||
if "server" in config and ("baseUrl" in config["server"] or "scheme" in config["server"]):
|
||||
prefix = ""
|
||||
if "baseUrl" in config["server"]:
|
||||
prefix = config["server"]["baseUrl"]
|
||||
@@ -1099,7 +1099,7 @@ class Settings(object):
|
||||
|
||||
Added in 1.2.0
|
||||
"""
|
||||
if "events" in config.keys() and ("gcodeCommandTrigger" in config["events"] or "systemCommandTrigger" in config["events"]):
|
||||
if "events" in config and ("gcodeCommandTrigger" in config["events"] or "systemCommandTrigger" in config["events"]):
|
||||
self._logger.info("Migrating config (event subscriptions)...")
|
||||
|
||||
# migrate event hooks to new format
|
||||
@@ -1540,7 +1540,7 @@ class Settings(object):
|
||||
return value is not None
|
||||
|
||||
def getBaseFolder(self, type, create=True, allow_fallback=True, log_error=False, check_writable=True, deep_check_writable=False):
|
||||
if type not in list(default_settings["folder"].keys()) + ["base"]:
|
||||
if type != "base" and type not in default_settings["folder"]:
|
||||
return None
|
||||
|
||||
if type == "base":
|
||||
@@ -1740,12 +1740,12 @@ class Settings(object):
|
||||
self.set(path, False, **kwargs)
|
||||
|
||||
def setBaseFolder(self, type, path, force=False, validate=True):
|
||||
if type not in default_settings["folder"].keys():
|
||||
if type not in default_settings["folder"]:
|
||||
return None
|
||||
|
||||
currentPath = self.getBaseFolder(type)
|
||||
defaultPath = self._get_default_folder(type)
|
||||
if (path is None or path == defaultPath) and "folder" in self._config.keys() and type in self._config["folder"].keys():
|
||||
if (path is None or path == defaultPath) and "folder" in self._config and type in self._config["folder"]:
|
||||
del self._config["folder"][type]
|
||||
if not self._config["folder"]:
|
||||
del self._config["folder"]
|
||||
@@ -1755,7 +1755,7 @@ class Settings(object):
|
||||
if validate:
|
||||
_validate_folder(path, check_writable=True, deep_check_writable=True)
|
||||
|
||||
if not "folder" in self._config.keys():
|
||||
if "folder" not in self._config:
|
||||
self._config["folder"] = {}
|
||||
self._config["folder"][type] = path
|
||||
self._dirty = True
|
||||
|
||||
@@ -760,19 +760,46 @@ class fallback_dict(dict):
|
||||
self.custom[key] = value
|
||||
|
||||
def __delitem__(self, key):
|
||||
# TODO: mark as deleted and leave fallbacks alone?
|
||||
for dictionary in self._all():
|
||||
if key in dictionary:
|
||||
del dictionary[key]
|
||||
|
||||
def __contains__(self, key):
|
||||
return any((key in dictionary)
|
||||
for dictionary in self._all())
|
||||
|
||||
def keys(self):
|
||||
result = set()
|
||||
for dictionary in self._all():
|
||||
result += dictionary.keys()
|
||||
return result
|
||||
for k in dictionary.keys():
|
||||
if k in result:
|
||||
continue
|
||||
result.add(k)
|
||||
yield k
|
||||
|
||||
def values(self):
|
||||
result = set()
|
||||
for dictionary in self._all():
|
||||
for k, v in dictionary.items():
|
||||
if k in result:
|
||||
continue
|
||||
result.add(k)
|
||||
yield k
|
||||
|
||||
def items(self):
|
||||
result = set()
|
||||
for dictionary in self._all():
|
||||
for k, v in dictionary.items():
|
||||
if k in result:
|
||||
continue
|
||||
result.add(k)
|
||||
yield k, v
|
||||
|
||||
def _all(self):
|
||||
return [self.custom] + list(self.fallbacks)
|
||||
|
||||
yield self.custom
|
||||
for d in self.fallbacks:
|
||||
yield d
|
||||
|
||||
|
||||
def dict_filter(dictionary, filter_function):
|
||||
@@ -842,7 +869,7 @@ class DefaultOrderedDict(collections.OrderedDict):
|
||||
args = tuple()
|
||||
else:
|
||||
args = self.default_factory,
|
||||
return type(self), args, None, None, self.items()
|
||||
return type(self), args, None, None, list(self.items())
|
||||
|
||||
def copy(self):
|
||||
return self.__copy__()
|
||||
@@ -853,7 +880,7 @@ class DefaultOrderedDict(collections.OrderedDict):
|
||||
def __deepcopy__(self, memo):
|
||||
import copy
|
||||
return type(self)(self.default_factory,
|
||||
copy.deepcopy(self.items()))
|
||||
copy.deepcopy(list(self.items())))
|
||||
|
||||
# noinspection PyMethodOverriding
|
||||
def __repr__(self):
|
||||
|
||||
@@ -1496,7 +1496,7 @@ class MachineCom(object):
|
||||
except Exception:
|
||||
self._logger.exception("Error while processing temperatures in {}, skipping".format(name))
|
||||
|
||||
if current_tool_key in parsedTemps.keys():
|
||||
if current_tool_key in parsedTemps:
|
||||
shared_nozzle = self._printerProfileManager.get_current_or_default()["extruder"]["sharedNozzle"]
|
||||
for n in range(maxToolNum + 1):
|
||||
tool = "T%d" % n
|
||||
@@ -1510,7 +1510,7 @@ class MachineCom(object):
|
||||
self.last_temperature.set_tool(n, actual=actual, target=target)
|
||||
|
||||
# bed temperature
|
||||
if "B" in parsedTemps.keys():
|
||||
if "B" in parsedTemps:
|
||||
actual, target = parsedTemps["B"]
|
||||
self.last_temperature.set_bed(actual=actual, target=target)
|
||||
|
||||
@@ -2044,11 +2044,11 @@ class MachineCom(object):
|
||||
|
||||
##~~ Parsing for pause triggers
|
||||
if pause_triggers and not self.isStreaming():
|
||||
if "enable" in pause_triggers.keys() and pause_triggers["enable"].search(line) is not None:
|
||||
if "enable" in pause_triggers and pause_triggers["enable"].search(line) is not None:
|
||||
self.setPause(True)
|
||||
elif "disable" in pause_triggers.keys() and pause_triggers["disable"].search(line) is not None:
|
||||
elif "disable" in pause_triggers and pause_triggers["disable"].search(line) is not None:
|
||||
self.setPause(False)
|
||||
elif "toggle" in pause_triggers.keys() and pause_triggers["toggle"].search(line) is not None:
|
||||
elif "toggle" in pause_triggers and pause_triggers["toggle"].search(line) is not None:
|
||||
self.setPause(not self.isPaused())
|
||||
|
||||
### Baudrate detection
|
||||
@@ -2562,7 +2562,7 @@ class MachineCom(object):
|
||||
|
||||
return BufferedReadlineWrapper(serial_obj)
|
||||
|
||||
serial_factories = self._serial_factory_hooks.items() + [("default", default)]
|
||||
serial_factories = list(self._serial_factory_hooks.items()) + [("default", default)]
|
||||
for name, factory in serial_factories:
|
||||
try:
|
||||
serial_obj = factory(self, self._port, self._baudrate, settings().getFloat(["serial", "timeout", "connection"]))
|
||||
|
||||
@@ -146,7 +146,7 @@ class TestSettings(unittest.TestCase):
|
||||
|
||||
# we know there's a 'name' by now, so just ensure we have the regex key
|
||||
temperature_regex_filter = temperature_regex_filters[0]
|
||||
self.assertIn('regex', temperature_regex_filter.keys())
|
||||
self.assertIn('regex', temperature_regex_filter)
|
||||
|
||||
def test_temperature_regex_should_not_match(self):
|
||||
'''random entries that aren't temperature regex entries'''
|
||||
|
||||
Reference in new issue
Block a user