Merge pull request #9076 from Pesc0/removesix

remove functions leftover from using six
This commit is contained in:
Chris Hennes
2023-03-28 10:00:58 -05:00
committed by GitHub
11 changed files with 18 additions and 46 deletions

View File

@@ -22,7 +22,6 @@
import FreeCAD
import Path
import Path.Base.Util as PathUtil
import PathGui
import importlib
@@ -109,7 +108,7 @@ def Attach(vobj, name):
Path.Log.track(vobj.Object.Label, name)
global _factory
for key, value in PathUtil.keyValueIter(_factory):
for key, value in _factory.items():
if key == name:
return value(vobj, name)
Path.Log.track(vobj.Object.Label, name, "PathIconViewProvider")

View File

@@ -224,7 +224,7 @@ class OpsDefaultEditor:
self.ops = sorted(
[
OpTaskPanel(self.obj, name, op)
for name, op in PathUtil.keyValueIter(PathSetupSheet._RegisteredOps)
for name, op in PathSetupSheet._RegisteredOps.items()
],
key=lambda op: op.name,
)

View File

@@ -74,14 +74,14 @@ class Template:
def _traverseTemplateAttributes(attrs, codec):
Path.Log.debug(attrs)
coded = {}
for key, value in PathUtil.keyValueIter(attrs):
for key, value in attrs.items():
if type(value) == dict:
Path.Log.debug("%s is a dict" % key)
coded[key] = _traverseTemplateAttributes(value, codec)
elif type(value) == list:
Path.Log.debug("%s is a list" % key)
coded[key] = [_traverseTemplateAttributes(attr, codec) for attr in value]
elif PathUtil.isString(value):
elif isinstance(value, str):
Path.Log.debug("%s is a string" % key)
coded[key] = codec(value)
else:
@@ -276,7 +276,7 @@ class SetupSheet:
if attrs.get(name) is not None:
setattr(self.obj, name, attrs[name])
for opName, op in PathUtil.keyValueIter(_RegisteredOps):
for opName, op in _RegisteredOps.items():
opSetting = attrs.get(opName)
if opSetting is not None:
prototype = op.prototype(opName)
@@ -364,13 +364,13 @@ class SetupSheet:
def encodeAttributeString(self, attr):
"""encodeAttributeString(attr) ... return the encoded string of a template attribute."""
return PathUtil.toUnicode(
return str(
attr.replace(self.expressionReference(), self.TemplateReference)
)
def decodeAttributeString(self, attr):
"""decodeAttributeString(attr) ... return the decoded string of a template attribute."""
return PathUtil.toUnicode(
return str(
attr.replace(self.TemplateReference, self.expressionReference())
)
@@ -385,7 +385,7 @@ class SetupSheet:
def operationsWithSettings(self):
"""operationsWithSettings() ... returns a list of operations which currently have some settings defined."""
ops = []
for name, value in PathUtil.keyValueIter(_RegisteredOps):
for name, value in _RegisteredOps.items():
for prop in value.registeredPropertyNames(name):
if hasattr(self.obj, prop):
ops.append(name)

View File

@@ -159,17 +159,3 @@ def clearExpressionEngine(obj):
obj.setExpression(attr, None)
#TODO remove functions below, leftover from using six
def toUnicode(string):
"""toUnicode(string) ... returns a unicode version of string regardless of the python version."""
return str(string)
def isString(string):
"""isString(string) ... return True if string is a string, regardless of string type and python version."""
return isinstance(string, str)
def keyValueIter(dictionary):
"""keyValueIter(dict) ... return iterable object over dictionary's (key,value) tuples."""
return dictionary.items()

View File

@@ -25,7 +25,6 @@ from PySide import QtCore
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD
import Path
import Path.Base.Util as PathUtil
import Path.Dressup.Utils as PathDressup
import PathScripts.PathUtils as PathUtils
import math
@@ -1168,9 +1167,7 @@ class TaskPanel(object):
def updateBoneList(self):
itemList = []
for loc, (enabled, inaccessible, ids, zs) in PathUtil.keyValueIter(
self.obj.Proxy.boneStateList(self.obj)
):
for loc, (enabled, inaccessible, ids, zs) in self.obj.Proxy.boneStateList(self.obj).items():
lbl = "(%.2f, %.2f): %s" % (loc[0], loc[1], ",".join(str(id) for id in ids))
item = QtGui.QListWidgetItem(lbl)
if enabled:

View File

@@ -25,7 +25,6 @@ from PathScripts.PathUtils import waiting_effects
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD
import Path
import Path.Base.Util as PathUtil
import Path.Dressup.Utils as PathDressup
import PathScripts.PathUtils as PathUtils
import copy
@@ -792,7 +791,7 @@ class PathData:
tags = []
for (i, count) in PathUtil.keyValueIter(edgeDict):
for (i, count) in edgeDict.items():
edge = self.baseWire.Edges[i]
Path.Log.debug(" %d: %d" % (i, count))
# debugMarker(edge.Vertexes[0].Point, 'base', (1.0, 0.0, 0.0), 0.2)

View File

@@ -886,14 +886,10 @@ class TaskPanel:
self.form.operationsList.addItem(item)
self.form.jobModel.clear()
for name, count in PathUtil.keyValueIter(
Counter(
[
for name, count in Counter([
self.obj.Proxy.baseObject(self.obj, o).Label
for o in self.obj.Model.Group
]
)
):
]).items():
if count == 1:
self.form.jobModel.addItem(name)
else:
@@ -1412,7 +1408,7 @@ class TaskPanel:
additions = want - have
# first remove all obsolete base models
for model, count in PathUtil.keyValueIter(obsolete):
for model, count in obsolete.items():
for i in range(count):
# it seems natural to remove the last of all the base objects for a given model
base = [
@@ -1425,7 +1421,7 @@ class TaskPanel:
# do not access any of the retired objects after this point, they don't exist anymore
# then add all rookie base models
for model, count in PathUtil.keyValueIter(additions):
for model, count in additions.items():
for i in range(count):
base = PathJob.createModelResourceClone(obj, model)
obj.Model.addObject(base)

View File

@@ -25,7 +25,6 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD
import FreeCADGui
import Path
import Path.Base.Util as PathUtil
import Path.Main.Gui.JobDlg as PathJobDlg
import Path.Main.Job as PathJob
import Path.Main.Stock as PathStock
@@ -192,7 +191,7 @@ class CommandJobTemplateExport:
encoded = job.Proxy.setupSheet.encodeTemplateAttributes(attrs)
# write template
with open(PathUtil.toUnicode(path), "w") as fp:
with open(str(path), "w") as fp:
json.dump(encoded, fp, sort_keys=True, indent=2)

View File

@@ -32,7 +32,6 @@ from PySide import QtCore, QtGui
import FreeCAD
import FreeCADGui
import Path
import Path.Base.Util as PathUtil
import PathScripts
from collections import Counter
from datetime import datetime
@@ -508,9 +507,7 @@ class CommandPathSanity:
data = {"baseimage": "", "bases": ""}
try:
bases = {}
for name, count in PathUtil.keyValueIter(
Counter([obj.Proxy.baseObject(obj, o).Label for o in obj.Model.Group])
):
for name, count in Counter([obj.Proxy.baseObject(obj, o).Label for o in obj.Model.Group]).items():
bases[name] = str(count)
data["baseimage"] = self.__makePicture(obj.Model, "baseimage")

View File

@@ -577,7 +577,7 @@ class ObjectJob:
This will also create any TCs stored in the template."""
tcs = []
if template:
with open(PathUtil.toUnicode(template), "rb") as fp:
with open(str(template), "rb") as fp:
attrs = json.load(fp)
if attrs.get(JobTemplate.Version) and 1 == int(attrs[JobTemplate.Version]):

View File

@@ -50,7 +50,6 @@ Many other OpenSBP commands not handled
import FreeCAD
import Path
import Path.Base.Util as PathUtil
import os
import Path
@@ -186,7 +185,7 @@ def parse(inputstring):
last[words[0][1]] = words[1]
output += s
for key, val in PathUtil.keyValueIter(last):
for key, val in last.items():
if val is not None:
output += key + str(val) + " F" + speed + "\n"