Python version independent string and unicode handling.

This commit is contained in:
Markus Lampert
2017-10-22 12:01:35 -07:00
parent be115bcabf
commit 0d4e9d47c9
5 changed files with 28 additions and 9 deletions

View File

@@ -29,6 +29,7 @@ import FreeCADGui
import Path
import PathScripts
import PathScripts.PathLog as PathLog
import PathScripts.PathUtil as PathUtil
import PathScripts.PathUtils as PathUtils
import json
import os
@@ -270,13 +271,13 @@ class ToolLibraryManager():
parser = xml.sax.make_parser()
parser.setFeature(xml.sax.handler.feature_namespaces, 0)
parser.setContentHandler(xmlHandler)
parser.parse(unicode(filename[0]))
parser.parse(PathUtil.toUnicode(filename[0]))
if not xmlHandler.tooltable:
return None
ht = xmlHandler.tooltable
else:
with open(unicode(filename[0]), "rb") as fp:
with open(PathUtil.toUnicode(filename[0]), "rb") as fp:
ht = self.tooltableFromAttrs(json.load(fp))
tt = self._findList(listname)
@@ -299,7 +300,7 @@ class ToolLibraryManager():
fext = os.path.splitext(name)[1].lower()
if fext != ext:
name = "{}{}".format(name, ext)
return (open(unicode(name), 'wb'), name)
return (open(PathUtil.toUnicode(name), 'wb'), name)
if filename[1] == self.TooltableTypeXML:
fp,fname = openFileWithExtension(filename[0], '.xml')
@@ -315,7 +316,7 @@ class ToolLibraryManager():
json.dump(self.templateAttrs(tt), fp, sort_keys=True, indent=2)
fp.close()
print("Written ", unicode(fname))
print("Written ", PathUtil.toUnicode(fname))
except Exception as e:
print("Could not write file:", e)