From 444e0eb0887206056b2711151dd713de76ad6dd9 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Mon, 29 Dec 2025 16:24:43 +0200 Subject: [PATCH 1/6] Add utils with mk_str / mk_uni functions --- InitGui.py | 29 +------------ kicadStepUpCMD.py | 106 +++------------------------------------------- utils.py | 29 +++++++++++++ 3 files changed, 38 insertions(+), 126 deletions(-) create mode 100644 utils.py diff --git a/InitGui.py b/InitGui.py index 85efb33..2daae61 100644 --- a/InitGui.py +++ b/InitGui.py @@ -34,6 +34,8 @@ import ksu_locator from kicadStepUpCMD import * +from utils import mk_str, mk_uni + ksuWBpath = os.path.dirname(ksu_locator.__file__) #sys.path.append(ksuWB + '/Gui') @@ -275,33 +277,6 @@ def Activated(self): prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUpGui") if prefs.IsEmpty(): #if prefs.GetContents() is None: - def mk_str(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.encode('utf-8') - return input - else: #py2 - if type(input) == unicode: - input = input.encode('utf-8') - return input - else: - return input - def mk_uni(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.decode('utf-8') - return input - else: #py2 - if type(input) != unicode: - input = input.decode('utf-8') - return input - else: - return input - ## FreeCAD.Console.PrintError('Creating first time ksu preferences\n') #prefs.SetString('prefix3d_1',make_string(default_prefix3d)) prefs.SetInt('pcb_color',0) diff --git a/kicadStepUpCMD.py b/kicadStepUpCMD.py index 2f4e91a..23afee8 100644 --- a/kicadStepUpCMD.py +++ b/kicadStepUpCMD.py @@ -32,6 +32,8 @@ import constrainator from constrainator import add_constraints, sanitizeSkBsp +from utils import mk_str + ksuCMD_version__='2.5.7' global invisible_objs @@ -2815,19 +2817,6 @@ def Activated(self): # do something here... if FreeCADGui.Selection.getSelection(): sel=FreeCADGui.Selection.getSelection() - def mk_str(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.encode('utf-8') - return input - else: #py2 - if type(input) == unicode: - input = input.encode('utf-8') - return input - else: - return input if len(sel) != 1: msg="Select one object with Shape to be colored Cloned!\n" reply = QtGui.QMessageBox.information(None,"Warning", msg) @@ -2884,19 +2873,6 @@ def Activated(self): # do something here... if FreeCADGui.Selection.getSelection(): sel=FreeCADGui.Selection.getSelection() - def mk_str(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.encode('utf-8') - return input - else: #py2 - if type(input) == unicode: - input = input.encode('utf-8') - return input - else: - return input if len(sel) != 1: msg="Select one object with Shape to generate a colored Binder!\n" reply = QtGui.QMessageBox.information(None,"Warning", msg) @@ -2963,19 +2939,6 @@ def Activated(self): # do something here... if FreeCADGui.Selection.getSelection(): sel=FreeCADGui.Selection.getSelection() - def mk_str(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.encode('utf-8') - return input - else: #py2 - if type(input) == unicode: - input = input.encode('utf-8') - return input - else: - return input if len(sel) != 2: msg="Select the Binder and one object with Shape to ReLink the Binder!\n" reply = QtGui.QMessageBox.information(None,"Warning", msg) @@ -3019,20 +2982,6 @@ def Activated(self): if FreeCADGui.Selection.getSelection(): sel=FreeCADGui.Selection.getSelection() doc=FreeCAD.activeDocument() - def mk_str(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.encode('utf-8') - return input - else: #py2 - if type(input) == unicode: - input = input.encode('utf-8') - return input - else: - return input - ## doc.openTransaction('union') if len(sel)<1: msg="Select one or two objects with Shape to be copied!\n" @@ -3098,20 +3047,6 @@ def Activated(self): # do something here... if FreeCADGui.Selection.getSelection(): sel=FreeCADGui.Selection.getSelection() - def mk_str(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.encode('utf-8') - return input - else: #py2 - if type(input) == unicode: - input = input.encode('utf-8') - return input - else: - return input - ## if len(sel)<1: msg="Select at least one object with Shape to be copied!\n" reply = QtGui.QMessageBox.information(None,"Warning", msg) @@ -3219,21 +3154,7 @@ def Activated(self): FreeCAD.Console.PrintWarning("Select ONE Part Design Next object\nor one or more objects to be copied!\n") FreeCADGui.addCommand('ksuToolsDeepCopy',ksuToolsDeepCopy()) -##### -def mk_str_u(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.encode('utf-8') - return input - else: #py2 - if type(input) == unicode: - input = input.encode('utf-8') - return input - else: - return input -### + make_compound = False # import FreeCAD as app,FreeCADGui as gui @@ -3275,7 +3196,7 @@ def deep_copy_part(doc, part, compound='flat',suffix='(copy)'): pName= 'None' if make_compound=='compound': - compound = doc.addObject('Part::Compound', mk_str_u(part.Label)+suffix) + compound = doc.addObject('Part::Compound', mk_str(part.Label)+suffix) compound.Links = copied_subobjects if 0: o=copied_subobjects[0] @@ -3286,7 +3207,7 @@ def deep_copy_part(doc, part, compound='flat',suffix='(copy)'): compound.ViewObject.ShapeAppearance = oo.ViewObject.ShapeAppearance pName = doc.ActiveObject.Name elif make_compound=='part': - doc.addObject('App::Part',mk_str_u(part.Label)+'_') + doc.addObject('App::Part',mk_str(part.Label)+'_') #FreeCAD.Console.PrintMessage(doc.ActiveObject.Label) actobj=doc.ActiveObject for uplvlobj in actobj.InListRecursive: @@ -3352,9 +3273,9 @@ def copy_subobject(doc, o,suffix='(copy)'): copy.Shape = o.Shape #copy.Label = 'Copy of ' + o.Label if suffix=='_': - copy.Label = mk_str_u(o.Label)+suffix + copy.Label = mk_str(o.Label)+suffix else: - copy.Label = mk_str_u(o.Label)+'.'+suffix + copy.Label = mk_str(o.Label)+'.'+suffix #copy.Placement = get_recursive_inverse_placement(o).inverse() copy.Placement = o.getGlobalPlacement() @@ -3759,19 +3680,6 @@ def Activated(self): # do something here... if FreeCADGui.Selection.getSelection(): sel=FreeCADGui.Selection.getSelection() - def mk_str(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.encode('utf-8') - return input - else: #py2 - if type(input) == unicode: - input = input.encode('utf-8') - return input - else: - return input def i_say(msg): FreeCAD.Console.PrintMessage(msg) FreeCAD.Console.PrintMessage('\n') diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..8e7df46 --- /dev/null +++ b/utils.py @@ -0,0 +1,29 @@ +import sys + +def mk_str(input): + if (sys.version_info > (3, 0)): #py3 + if isinstance(input, str): + return input + else: + input = input.encode('utf-8') + return input + else: #py2 + if type(input) == unicode: + input = input.encode('utf-8') + return input + else: + return input + +def mk_uni(input): + if (sys.version_info > (3, 0)): #py3 + if isinstance(input, str): + return input + else: + input = input.decode('utf-8') + return input + else: #py2 + if type(input) != unicode: + input = input.decode('utf-8') + return input + else: + return input From 3dbc354e6b5975eb3edd22ebf87d31d19ddb1a13 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Mon, 29 Dec 2025 16:52:24 +0200 Subject: [PATCH 2/6] Use common code for make_string/make_unicode --- kicadStepUptools.py | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/kicadStepUptools.py b/kicadStepUptools.py index 34516db..769c5b1 100644 --- a/kicadStepUptools.py +++ b/kicadStepUptools.py @@ -449,6 +449,8 @@ import re import time +from utils import mk_str as make_string +from utils import mk_uni as make_unicode max_recursion_limit=5000 # kSU issue#198 sys.setrecursionlimit(max_recursion_limit) @@ -1787,34 +1789,6 @@ def open(filename,insert=None): # onLoadFootprint(filename) -def make_unicode(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.decode('utf-8') - return input - else: #py2 - if type(input) != unicode: - input = input.decode('utf-8') - return input - else: - return input - -def make_string(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.encode('utf-8') - return input - else: #py2 - if type(input) == unicode: - input = input.encode('utf-8') - return input - else: - return input - def PLine(prm1,prm2): if hasattr(Part,"LineSegment"): return Part.LineSegment(prm1, prm2) From ede3ea8b05402574c62201debf68febdb59ffc39 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Mon, 29 Dec 2025 18:46:46 +0200 Subject: [PATCH 3/6] Replace make_unicode_t with common mk_str --- tracks.py | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/tracks.py b/tracks.py index c28f218..848515b 100644 --- a/tracks.py +++ b/tracks.py @@ -22,6 +22,9 @@ from kicad_parser import makeVect, make_gr_rect, make_gr_poly, makeThickLine from fcad_parser import unquote #maui +from utils import mk_str as make_string +from utils import mk_uni as make_unicode + global use_AppPart, use_Links, use_LinkGroups use_AppPart=False # False use_Links=False @@ -118,23 +121,9 @@ def crc_gen_t(data): #make_unicode(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) #hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:].encode('utf-8') #print(data +u'_'+ hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) - return u'_'+ make_unicode_t(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) + return u'_'+ make_unicode(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) ## -def make_unicode_t(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.decode('utf-8') - return input - else: #py2 - if type(input) != unicode: - input = input.decode('utf-8') - return input - else: - return input - def mkColor(*color): if len(color)==1: if isinstance(color[0],basestring): @@ -294,7 +283,6 @@ def simple_cpy (obj,lbl): # from kicadStepUptools import removesubtree, cfg_read_all -from kicadStepUptools import make_unicode, make_string import fcad_parser from fcad_parser import KicadPCB,SexpList @@ -334,7 +322,7 @@ def addtracks(fname = None): last_pcb_path=os.path.dirname(fname) path, ftname = os.path.split(fname) ftname=os.path.splitext(ftname)[0] - ftname_sfx=crc_gen_t(make_unicode_t(ftname)) + ftname_sfx=crc_gen_t(make_unicode(ftname)) pg = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUp") pg.SetString("last_pcb_path", make_string(last_pcb_path)) # py3 .decode("utf-8") prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUpGui") From 58d192c39371332d4ee11ce7846a16b4bbe8ac64 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Mon, 29 Dec 2025 19:02:41 +0200 Subject: [PATCH 4/6] Use common crc_gen function --- fps.py | 31 +++---------------------------- kicadStepUptools.py | 14 +------------- makefacedxf.py | 31 +++---------------------------- tracks.py | 17 ++--------------- utils.py | 7 +++++++ 5 files changed, 16 insertions(+), 84 deletions(-) diff --git a/fps.py b/fps.py index 0508a38..2ed54a5 100644 --- a/fps.py +++ b/fps.py @@ -28,6 +28,8 @@ import math from math import radians +from utils import crc_gen, mk_str as make_string, mk_uni as make_unicode + consolePrint = FreeCAD.Console.PrintMessage consolePrint('fp loader v'+fps_version+'\n') @@ -98,32 +100,6 @@ def makeAnno (name,bp,txt,afs): return anno # -def crc_gen_t(data): - import binascii - import re - - #data=u'Würfel' - content=re.sub(r'[^\x00-\x7F]+','_', data) - #make_unicode(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) - #hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:].encode('utf-8') - #print(data +u'_'+ hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) - return u'_'+ make_unicode_t(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) -## - -def make_unicode_t(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.decode('utf-8') - return input - else: #py2 - if type(input) != unicode: - input = input.decode('utf-8') - return input - else: - return input - def mkColor(*color): if len(color)==1: if isinstance(color[0],basestring): @@ -270,7 +246,6 @@ def simple_cpy (obj,lbl): # from kicadStepUptools import removesubtree, cfg_read_all -from kicadStepUptools import make_unicode, make_string import fcad_parser from fcad_parser import KicadPCB,SexpList @@ -355,7 +330,7 @@ def addfootprint(fname = None): last_pcb_path=os.path.dirname(fname) path, ftname = os.path.split(fname) ftname=os.path.splitext(ftname)[0] - ftname_sfx=crc_gen_t(make_unicode_t(ftname)) + ftname_sfx=crc_gen(make_unicode(ftname)) pg = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUp") pg.SetString("last_pcb_path", make_string(last_pcb_path)) # py3 .decode("utf-8") prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUpGui") diff --git a/kicadStepUptools.py b/kicadStepUptools.py index 769c5b1..0b2617a 100644 --- a/kicadStepUptools.py +++ b/kicadStepUptools.py @@ -449,8 +449,7 @@ import re import time -from utils import mk_str as make_string -from utils import mk_uni as make_unicode +from utils import crc_gen, mk_str as make_string, mk_uni as make_unicode max_recursion_limit=5000 # kSU issue#198 sys.setrecursionlimit(max_recursion_limit) @@ -6666,17 +6665,6 @@ def PullPCB(file_name=None): # print('Cancel') ## -def crc_gen(data): - import binascii - import re - - #data=u'Würfel' - content=re.sub(r'[^\x00-\x7F]+','_', data) - #make_unicode(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) - #hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:].encode('utf-8') - #print(data +u'_'+ hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) - return u'_'+ make_unicode(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) -## def check_lightDir(set_default=False): pg=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View") diff --git a/makefacedxf.py b/makefacedxf.py index 16b25af..12fb81a 100644 --- a/makefacedxf.py +++ b/makefacedxf.py @@ -25,6 +25,8 @@ FC_export_min_version="11670" #11670 latest JM silks_version = '1.5' +from utils import crc_gen, mk_str as make_string, mk_uni as make_unicode + use_LinkGroups = False if 'LinkView' in dir(FreeCADGui): prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUpGui") @@ -65,32 +67,6 @@ def getFCversion(): #if FC_git_Nbr >= int(FC_export_min_version): use_AppPart=True -def crc_gen_d(data): - import binascii - import re - - #data=u'Würfel' - content=re.sub(r'[^\x00-\x7F]+','_', data) - #make_unicode(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) - #hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:].encode('utf-8') - #print(data +u'_'+ hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) - return u'_'+ make_unicode_d(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) -## - -def make_unicode_d(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.decode('utf-8') - return input - else: #py2 - if type(input) != unicode: - input = input.decode('utf-8') - return input - else: - return input - def find_pcb_name(): #searching for a pcb pcb_name = '' @@ -135,7 +111,6 @@ def simple_cpy (obj,lbl): import importDXF else: from dxf_parser import _importDXF -from kicadStepUptools import make_unicode, make_string def makeFaceDXF(): global copper_diffuse, silks_diffuse, use_dxf_internal @@ -170,7 +145,7 @@ def makeFaceDXF(): if len(fname) > 0: #importDXF.open(fname) last_pcb_path=os.path.dirname(fname) - ftname_sfx=crc_gen_d(make_unicode_d(filename)) + ftname_sfx=crc_gen(make_unicode(filename)) pg = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUp") pg.SetString("last_pcb_path", make_string(last_pcb_path)) # py3 .decode("utf-8") diff --git a/tracks.py b/tracks.py index 848515b..6970244 100644 --- a/tracks.py +++ b/tracks.py @@ -22,8 +22,7 @@ from kicad_parser import makeVect, make_gr_rect, make_gr_poly, makeThickLine from fcad_parser import unquote #maui -from utils import mk_str as make_string -from utils import mk_uni as make_unicode +from utils import crc_gen, mk_str as make_string, mk_uni as make_unicode global use_AppPart, use_Links, use_LinkGroups use_AppPart=False # False @@ -112,18 +111,6 @@ def recompute_active_object(): FreeCAD.ActiveDocument.ActiveObject.recompute() ## -def crc_gen_t(data): - import binascii - import re - - #data=u'Würfel' - content=re.sub(r'[^\x00-\x7F]+','_', data) - #make_unicode(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) - #hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:].encode('utf-8') - #print(data +u'_'+ hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) - return u'_'+ make_unicode(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:]) -## - def mkColor(*color): if len(color)==1: if isinstance(color[0],basestring): @@ -322,7 +309,7 @@ def addtracks(fname = None): last_pcb_path=os.path.dirname(fname) path, ftname = os.path.split(fname) ftname=os.path.splitext(ftname)[0] - ftname_sfx=crc_gen_t(make_unicode(ftname)) + ftname_sfx=crc_gen(make_unicode(ftname)) pg = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUp") pg.SetString("last_pcb_path", make_string(last_pcb_path)) # py3 .decode("utf-8") prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUpGui") diff --git a/utils.py b/utils.py index 8e7df46..2ad72c1 100644 --- a/utils.py +++ b/utils.py @@ -1,4 +1,6 @@ +import re import sys +import binascii def mk_str(input): if (sys.version_info > (3, 0)): #py3 @@ -27,3 +29,8 @@ def mk_uni(input): return input else: return input + +def crc_gen(data): + # Replace non-ascii characters with '_' + content=re.sub(r'[^\x00-\x7F]+','_', data) + return u'_' + mk_uni(hex(binascii.crc_hqx(content.encode('utf-8'), 0))[2:]) From 1356e151ad8653c56439d5077c4c57cfef99cb3e Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Mon, 29 Dec 2025 22:26:23 +0200 Subject: [PATCH 5/6] Rename to mk_str/mk_uni to more common make_string/make_unicode --- InitGui.py | 2 +- fps.py | 2 +- kicadStepUpCMD.py | 5 +---- kicadStepUptools.py | 2 +- makefacedxf.py | 2 +- tracks.py | 2 +- utils.py | 6 +++--- 7 files changed, 9 insertions(+), 12 deletions(-) diff --git a/InitGui.py b/InitGui.py index 2daae61..1fe5c26 100644 --- a/InitGui.py +++ b/InitGui.py @@ -34,7 +34,7 @@ import ksu_locator from kicadStepUpCMD import * -from utils import mk_str, mk_uni +from utils import make_string as mk_str, make_unicode as mk_uni ksuWBpath = os.path.dirname(ksu_locator.__file__) diff --git a/fps.py b/fps.py index 2ed54a5..162bcec 100644 --- a/fps.py +++ b/fps.py @@ -28,7 +28,7 @@ import math from math import radians -from utils import crc_gen, mk_str as make_string, mk_uni as make_unicode +from utils import crc_gen, make_string, make_unicode consolePrint = FreeCAD.Console.PrintMessage consolePrint('fp loader v'+fps_version+'\n') diff --git a/kicadStepUpCMD.py b/kicadStepUpCMD.py index 23afee8..ab292c8 100644 --- a/kicadStepUpCMD.py +++ b/kicadStepUpCMD.py @@ -32,7 +32,7 @@ import constrainator from constrainator import add_constraints, sanitizeSkBsp -from utils import mk_str +from utils import make_string as mk_str, make_string ksuCMD_version__='2.5.7' @@ -3984,7 +3984,6 @@ def Activated(self): import _DXF_Import import os - from kicadStepUptools import make_unicode, make_string # _DXF_Import.open('D:/Temp/t4k3-DWG.DXF') prefs_ = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUpGui") last_pcb_path = prefs_.GetString("last_pcb_path") @@ -4031,7 +4030,6 @@ def Activated(self): try: import ezdxf import os - from kicadStepUptools import make_unicode, make_string # _DXF_Import.open('D:/Temp/t4k3-DWG.DXF') prefs_ = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUpGui") last_pcb_path = prefs_.GetString("last_pcb_path") @@ -4079,7 +4077,6 @@ def Activated(self): import _DXF_Import from dxf_parser import _importDXF import os - from kicadStepUptools import make_unicode, make_string prefs_ = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUpGui") last_pcb_path = prefs_.GetString("last_pcb_path") if not(prefs_.GetBool('not_native_dlg')): diff --git a/kicadStepUptools.py b/kicadStepUptools.py index 0b2617a..a40f413 100644 --- a/kicadStepUptools.py +++ b/kicadStepUptools.py @@ -449,7 +449,7 @@ import re import time -from utils import crc_gen, mk_str as make_string, mk_uni as make_unicode +from utils import crc_gen, make_string, make_unicode max_recursion_limit=5000 # kSU issue#198 sys.setrecursionlimit(max_recursion_limit) diff --git a/makefacedxf.py b/makefacedxf.py index 12fb81a..2941b65 100644 --- a/makefacedxf.py +++ b/makefacedxf.py @@ -25,7 +25,7 @@ FC_export_min_version="11670" #11670 latest JM silks_version = '1.5' -from utils import crc_gen, mk_str as make_string, mk_uni as make_unicode +from utils import crc_gen, make_string, make_unicode use_LinkGroups = False if 'LinkView' in dir(FreeCADGui): diff --git a/tracks.py b/tracks.py index 6970244..78ea256 100644 --- a/tracks.py +++ b/tracks.py @@ -22,7 +22,7 @@ from kicad_parser import makeVect, make_gr_rect, make_gr_poly, makeThickLine from fcad_parser import unquote #maui -from utils import crc_gen, mk_str as make_string, mk_uni as make_unicode +from utils import crc_gen, make_string, make_unicode global use_AppPart, use_Links, use_LinkGroups use_AppPart=False # False diff --git a/utils.py b/utils.py index 2ad72c1..ce9978c 100644 --- a/utils.py +++ b/utils.py @@ -2,7 +2,7 @@ import sys import binascii -def mk_str(input): +def make_string(input): if (sys.version_info > (3, 0)): #py3 if isinstance(input, str): return input @@ -16,7 +16,7 @@ def mk_str(input): else: return input -def mk_uni(input): +def make_unicode(input): if (sys.version_info > (3, 0)): #py3 if isinstance(input, str): return input @@ -33,4 +33,4 @@ def mk_uni(input): def crc_gen(data): # Replace non-ascii characters with '_' content=re.sub(r'[^\x00-\x7F]+','_', data) - return u'_' + mk_uni(hex(binascii.crc_hqx(content.encode('utf-8'), 0))[2:]) + return u'_' + make_unicode(hex(binascii.crc_hqx(content.encode('utf-8'), 0))[2:]) From c8c49f4965baf81782f720d324de299537d51241 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Mon, 29 Dec 2025 22:28:16 +0200 Subject: [PATCH 6/6] utils: Drop python2 code --- utils.py | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/utils.py b/utils.py index ce9978c..9b6c8f2 100644 --- a/utils.py +++ b/utils.py @@ -1,34 +1,16 @@ +#-*- coding: utf-8 -*- import re -import sys import binascii def make_string(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.encode('utf-8') - return input - else: #py2 - if type(input) == unicode: - input = input.encode('utf-8') - return input - else: - return input + if isinstance(input, str): + return input + return input.encode('utf-8') def make_unicode(input): - if (sys.version_info > (3, 0)): #py3 - if isinstance(input, str): - return input - else: - input = input.decode('utf-8') - return input - else: #py2 - if type(input) != unicode: - input = input.decode('utf-8') - return input - else: - return input + if isinstance(input, str): + return input + return input.decode('utf-8') def crc_gen(data): # Replace non-ascii characters with '_'