Don't check if keys are str

Our type checking should take care of that.
This commit is contained in:
Ghostkeeper 2018-07-05 12:31:42 +02:00
parent 807e8410c0
commit ef2250b889
No known key found for this signature in database
GPG key ID: 5252B696FB5E7C7A

View file

@ -45,35 +45,31 @@ class GcodeStartEndFormatter(Formatter):
# The kwargs dictionary contains a dictionary for each stack (with a string of the extruder_nr as their key), # The kwargs dictionary contains a dictionary for each stack (with a string of the extruder_nr as their key),
# and a default_extruder_nr to use when no extruder_nr is specified # and a default_extruder_nr to use when no extruder_nr is specified
if isinstance(key, str): try:
extruder_nr = int(kwargs["default_extruder_nr"])
except ValueError:
extruder_nr = -1
key_fragments = [fragment.strip() for fragment in key.split(",")]
if len(key_fragments) == 2:
try: try:
extruder_nr = int(kwargs["default_extruder_nr"]) extruder_nr = int(key_fragments[1])
except ValueError: except ValueError:
extruder_nr = -1
key_fragments = [fragment.strip() for fragment in key.split(",")]
if len(key_fragments) == 2:
try: try:
extruder_nr = int(key_fragments[1]) extruder_nr = int(kwargs["-1"][key_fragments[1]]) # get extruder_nr values from the global stack
except ValueError: except (KeyError, ValueError):
try: # either the key does not exist, or the value is not an int
extruder_nr = int(kwargs["-1"][key_fragments[1]]) # get extruder_nr values from the global stack Logger.log("w", "Unable to determine stack nr '%s' for key '%s' in start/end g-code, using global stack", key_fragments[1], key_fragments[0])
except (KeyError, ValueError): elif len(key_fragments) != 1:
# either the key does not exist, or the value is not an int
Logger.log("w", "Unable to determine stack nr '%s' for key '%s' in start/end g-code, using global stack", key_fragments[1], key_fragments[0])
elif len(key_fragments) != 1:
Logger.log("w", "Incorrectly formatted placeholder '%s' in start/end g-code", key)
return "{" + str(key) + "}"
key = key_fragments[0]
try:
return kwargs[str(extruder_nr)][key]
except KeyError:
Logger.log("w", "Unable to replace '%s' placeholder in start/end g-code", key)
return "{" + key + "}"
else:
Logger.log("w", "Incorrectly formatted placeholder '%s' in start/end g-code", key) Logger.log("w", "Incorrectly formatted placeholder '%s' in start/end g-code", key)
return "{" + str(key) + "}" return "{" + key + "}"
key = key_fragments[0]
try:
return kwargs[str(extruder_nr)][key]
except KeyError:
Logger.log("w", "Unable to replace '%s' placeholder in start/end g-code", key)
return "{" + key + "}"
## Job class that builds up the message of scene data to send to CuraEngine. ## Job class that builds up the message of scene data to send to CuraEngine.