userNameToFileName expects userName to be unicode strings, let it raise
if not
This commit is contained in:
parent
ec0fe57545
commit
bb21cb7c3a
@ -3,6 +3,7 @@ import shutil
|
|||||||
from io import StringIO, BytesIO, open
|
from io import StringIO, BytesIO, open
|
||||||
import codecs
|
import codecs
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
from fontTools.misc.py23 import basestring, unicode
|
||||||
from ufoLib.glifLib import GlyphSet
|
from ufoLib.glifLib import GlyphSet
|
||||||
from ufoLib.validators import *
|
from ufoLib.validators import *
|
||||||
from ufoLib.filenames import userNameToFileName
|
from ufoLib.filenames import userNameToFileName
|
||||||
@ -38,11 +39,6 @@ fontinfo.plist values between the possible format versions.
|
|||||||
convertFontInfoValueForAttributeFromVersion3ToVersion2
|
convertFontInfoValueForAttributeFromVersion3ToVersion2
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
|
||||||
basestring
|
|
||||||
except NameError:
|
|
||||||
basestring = str
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"makeUFOPath"
|
"makeUFOPath"
|
||||||
"UFOLibError",
|
"UFOLibError",
|
||||||
@ -1066,9 +1062,9 @@ class UFOWriter(object):
|
|||||||
# not caching this could be slightly expensive,
|
# not caching this could be slightly expensive,
|
||||||
# but caching it will be cumbersome
|
# but caching it will be cumbersome
|
||||||
existing = [d.lower() for d in list(self.layerContents.values())]
|
existing = [d.lower() for d in list(self.layerContents.values())]
|
||||||
if not isinstance(layerName, basestring):
|
if not isinstance(layerName, unicode):
|
||||||
try:
|
try:
|
||||||
layerName = str(layerName)
|
layerName = unicode(layerName)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
raise UFOLibError("The specified layer name is not a Unicode string.")
|
raise UFOLibError("The specified layer name is not a Unicode string.")
|
||||||
directory = userNameToFileName(layerName, existing=existing, prefix="glyphs.")
|
directory = userNameToFileName(layerName, existing=existing, prefix="glyphs.")
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
User name to file name conversion.
|
User name to file name conversion.
|
||||||
This was taken form the UFO 3 spec.
|
This was taken form the UFO 3 spec.
|
||||||
"""
|
"""
|
||||||
from fontTools.misc.py23 import unicode
|
from fontTools.misc.py23 import basestring, unicode
|
||||||
|
|
||||||
|
|
||||||
illegalCharacters = "\" * + / : < > ? [ \ ] | \0".split(" ")
|
illegalCharacters = "\" * + / : < > ? [ \ ] | \0".split(" ")
|
||||||
@ -68,7 +68,8 @@ def userNameToFileName(userName, existing=[], prefix="", suffix=""):
|
|||||||
u'alt._con'
|
u'alt._con'
|
||||||
"""
|
"""
|
||||||
# the incoming name must be a unicode string
|
# the incoming name must be a unicode string
|
||||||
assert isinstance(userName, unicode), "The value for userName must be a unicode string."
|
if not isinstance(userName, unicode):
|
||||||
|
raise ValueError("The value for userName must be a unicode string.")
|
||||||
# establish the prefix and suffix lengths
|
# establish the prefix and suffix lengths
|
||||||
prefixLength = len(prefix)
|
prefixLength = len(prefix)
|
||||||
suffixLength = len(suffix)
|
suffixLength = len(suffix)
|
||||||
|
@ -15,7 +15,7 @@ from __future__ import unicode_literals
|
|||||||
import os
|
import os
|
||||||
from io import BytesIO, open
|
from io import BytesIO, open
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
from fontTools.misc.py23 import tobytes
|
from fontTools.misc.py23 import tobytes, unicode
|
||||||
from ufoLib.plistlib import PlistWriter, readPlist, writePlist
|
from ufoLib.plistlib import PlistWriter, readPlist, writePlist
|
||||||
from ufoLib.plistFromETree import readPlistFromTree
|
from ufoLib.plistFromETree import readPlistFromTree
|
||||||
from ufoLib.pointPen import AbstractPointPen, PointToSegmentPen
|
from ufoLib.pointPen import AbstractPointPen, PointToSegmentPen
|
||||||
@ -457,9 +457,9 @@ def glyphNameToFileName(glyphName, glyphSet):
|
|||||||
existing = [name.lower() for name in list(glyphSet.contents.values())]
|
existing = [name.lower() for name in list(glyphSet.contents.values())]
|
||||||
else:
|
else:
|
||||||
existing = []
|
existing = []
|
||||||
if not isinstance(glyphName, basestring):
|
if not isinstance(glyphName, unicode):
|
||||||
try:
|
try:
|
||||||
new = str(glyphName)
|
new = unicode(glyphName)
|
||||||
glyphName = new
|
glyphName = new
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user