ufoLib meta: automated 2to3 conversion
This commit is contained in:
parent
2c2ffb97c0
commit
337ef3202b
@ -31,14 +31,14 @@ fontinfo.plist values between the possible format versions.
|
||||
|
||||
import os
|
||||
import shutil
|
||||
from cStringIO import StringIO
|
||||
from io import StringIO
|
||||
import codecs
|
||||
from copy import deepcopy
|
||||
from plistlib import readPlist, writePlist
|
||||
from glifLib import GlyphSet, READ_MODE, WRITE_MODE
|
||||
from validators import *
|
||||
from filenames import userNameToFileName
|
||||
from converters import convertUFO1OrUFO2KerningToUFO3Kerning
|
||||
from .plistlib import readPlist, writePlist
|
||||
from .glifLib import GlyphSet, READ_MODE, WRITE_MODE
|
||||
from .validators import *
|
||||
from .filenames import userNameToFileName
|
||||
from .converters import convertUFO1OrUFO2KerningToUFO3Kerning
|
||||
|
||||
try:
|
||||
set
|
||||
@ -159,13 +159,13 @@ class UFOReader(object):
|
||||
invalidFormatMessage = "groups.plist is not properly formatted."
|
||||
if not isinstance(groups, dict):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
for groupName, glyphList in groups.items():
|
||||
if not isinstance(groupName, basestring):
|
||||
for groupName, glyphList in list(groups.items()):
|
||||
if not isinstance(groupName, str):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
elif not isinstance(glyphList, list):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
for glyphName in glyphList:
|
||||
if not isinstance(glyphName, basestring):
|
||||
if not isinstance(glyphName, str):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
self._upConvertedKerningData = dict(
|
||||
kerning={},
|
||||
@ -320,7 +320,7 @@ class UFOReader(object):
|
||||
infoDataToSet = _convertFontInfoDataVersion2ToVersion3(infoDataToSet)
|
||||
# version 2
|
||||
elif self._formatVersion == 2:
|
||||
for attr, dataValidationDict in fontInfoAttributesVersion2ValueData.items():
|
||||
for attr, dataValidationDict in list(fontInfoAttributesVersion2ValueData.items()):
|
||||
value = infoDict.get(attr)
|
||||
if value is None:
|
||||
continue
|
||||
@ -328,7 +328,7 @@ class UFOReader(object):
|
||||
infoDataToSet = _convertFontInfoDataVersion2ToVersion3(infoDataToSet)
|
||||
# version 3
|
||||
elif self._formatVersion == 3:
|
||||
for attr, dataValidationDict in fontInfoAttributesVersion3ValueData.items():
|
||||
for attr, dataValidationDict in list(fontInfoAttributesVersion3ValueData.items()):
|
||||
value = infoDict.get(attr)
|
||||
if value is None:
|
||||
continue
|
||||
@ -339,7 +339,7 @@ class UFOReader(object):
|
||||
# validate data
|
||||
infoDataToSet = validateInfoVersion3Data(infoDataToSet)
|
||||
# populate the object
|
||||
for attr, value in infoDataToSet.items():
|
||||
for attr, value in list(infoDataToSet.items()):
|
||||
try:
|
||||
setattr(info, attr, value)
|
||||
except AttributeError:
|
||||
@ -352,13 +352,13 @@ class UFOReader(object):
|
||||
invalidFormatMessage = "kerning.plist is not properly formatted."
|
||||
if not isinstance(data, dict):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
for first, secondDict in data.items():
|
||||
if not isinstance(first, basestring):
|
||||
for first, secondDict in list(data.items()):
|
||||
if not isinstance(first, str):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
elif not isinstance(secondDict, dict):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
for second, value in secondDict.items():
|
||||
if not isinstance(second, basestring):
|
||||
for second, value in list(secondDict.items()):
|
||||
if not isinstance(second, str):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
elif not isinstance(value, (int, float)):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
@ -480,7 +480,7 @@ class UFOReader(object):
|
||||
glyphSet = self.getGlyphSet(layerName)
|
||||
allUnicodes = glyphSet.getUnicodes()
|
||||
cmap = {}
|
||||
for glyphName, unicodes in allUnicodes.iteritems():
|
||||
for glyphName, unicodes in allUnicodes.items():
|
||||
for code in unicodes:
|
||||
if code in cmap:
|
||||
cmap[code].append(glyphName)
|
||||
@ -806,7 +806,7 @@ class UFOWriter(object):
|
||||
# flip the dictionaries
|
||||
remap = {}
|
||||
for side in ("side1", "side2"):
|
||||
for writeName, dataName in maps[side].items():
|
||||
for writeName, dataName in list(maps[side].items()):
|
||||
remap[dataName] = writeName
|
||||
self._downConversionKerningData = dict(groupRenameMap=remap)
|
||||
|
||||
@ -835,11 +835,11 @@ class UFOWriter(object):
|
||||
# to the same group name there is no check to
|
||||
# ensure that the contents are identical. that
|
||||
# is left up to the caller.
|
||||
for name, contents in groups.items():
|
||||
for name, contents in list(groups.items()):
|
||||
if name in remap:
|
||||
continue
|
||||
remappedGroups[name] = contents
|
||||
for name, contents in groups.items():
|
||||
for name, contents in list(groups.items()):
|
||||
if name not in remap:
|
||||
continue
|
||||
name = remap[name]
|
||||
@ -847,7 +847,7 @@ class UFOWriter(object):
|
||||
groups = remappedGroups
|
||||
# pack and write
|
||||
groupsNew = {}
|
||||
for key, value in groups.items():
|
||||
for key, value in list(groups.items()):
|
||||
groupsNew[key] = list(value)
|
||||
if groupsNew:
|
||||
self._writePlist(GROUPS_FILENAME, groupsNew)
|
||||
@ -866,7 +866,7 @@ class UFOWriter(object):
|
||||
"""
|
||||
# gather version 3 data
|
||||
infoData = {}
|
||||
for attr in fontInfoAttributesVersion3ValueData.keys():
|
||||
for attr in list(fontInfoAttributesVersion3ValueData.keys()):
|
||||
if hasattr(info, attr):
|
||||
try:
|
||||
value = getattr(info, attr)
|
||||
@ -904,14 +904,14 @@ class UFOWriter(object):
|
||||
invalidFormatMessage = "The kerning is not properly formatted."
|
||||
if not isDictEnough(kerning):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
for pair, value in kerning.items():
|
||||
for pair, value in list(kerning.items()):
|
||||
if not isinstance(pair, (list, tuple)):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
if not len(pair) == 2:
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
if not isinstance(pair[0], basestring):
|
||||
if not isinstance(pair[0], str):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
if not isinstance(pair[1], basestring):
|
||||
if not isinstance(pair[1], str):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
if not isinstance(value, (int, float)):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
@ -919,14 +919,14 @@ class UFOWriter(object):
|
||||
if self._formatVersion < 3 and self._downConversionKerningData is not None:
|
||||
remap = self._downConversionKerningData["groupRenameMap"]
|
||||
remappedKerning = {}
|
||||
for (side1, side2), value in kerning.items():
|
||||
for (side1, side2), value in list(kerning.items()):
|
||||
side1 = remap.get(side1, side1)
|
||||
side2 = remap.get(side2, side2)
|
||||
remappedKerning[side1, side2] = value
|
||||
kerning = remappedKerning
|
||||
# pack and write
|
||||
kerningDict = {}
|
||||
for left, right in kerning.keys():
|
||||
for left, right in list(kerning.keys()):
|
||||
value = kerning[left, right]
|
||||
if not left in kerningDict:
|
||||
kerningDict[left] = {}
|
||||
@ -960,7 +960,7 @@ class UFOWriter(object):
|
||||
"""
|
||||
if self._formatVersion == 1:
|
||||
raise UFOLibError("features.fea is not allowed in UFO Format Version 1.")
|
||||
if not isinstance(features, basestring):
|
||||
if not isinstance(features, str):
|
||||
raise UFOLibError("The features are not text.")
|
||||
self._makeDirectory()
|
||||
path = os.path.join(self._path, FEATURES_FILENAME)
|
||||
@ -999,7 +999,7 @@ class UFOWriter(object):
|
||||
newOrder.append(layerName)
|
||||
layerOrder = newOrder
|
||||
else:
|
||||
layerOrder = self.layerContents.keys()
|
||||
layerOrder = list(self.layerContents.keys())
|
||||
if set(layerOrder) != set(self.layerContents.keys()):
|
||||
raise UFOLibError("The layer order contents does not match the glyph sets that have been created.")
|
||||
layerContents = [(layerName, self.layerContents[layerName]) for layerName in layerOrder]
|
||||
@ -1007,7 +1007,7 @@ class UFOWriter(object):
|
||||
|
||||
def _findDirectoryForLayerName(self, layerName):
|
||||
foundDirectory = None
|
||||
for existingLayerName, directoryName in self.layerContents.items():
|
||||
for existingLayerName, directoryName in list(self.layerContents.items()):
|
||||
if layerName is None and directoryName == DEFAULT_GLYPHS_DIRNAME:
|
||||
foundDirectory = directoryName
|
||||
break
|
||||
@ -1032,7 +1032,7 @@ class UFOWriter(object):
|
||||
raise UFOLibError("Only the default layer can be writen in UFO %d." % self.formatVersion)
|
||||
# locate a layer name when None has been given
|
||||
if layerName is None and defaultLayer:
|
||||
for existingLayerName, directory in self.layerContents.items():
|
||||
for existingLayerName, directory in list(self.layerContents.items()):
|
||||
if directory == DEFAULT_GLYPHS_DIRNAME:
|
||||
layerName = existingLayerName
|
||||
if layerName is None:
|
||||
@ -1060,7 +1060,7 @@ class UFOWriter(object):
|
||||
# matches the default being written. also make sure that this layer
|
||||
# name is not already linked to a non-default layer.
|
||||
if defaultLayer:
|
||||
for existingLayerName, directory in self.layerContents.items():
|
||||
for existingLayerName, directory in list(self.layerContents.items()):
|
||||
if directory == DEFAULT_GLYPHS_DIRNAME:
|
||||
if existingLayerName != layerName:
|
||||
raise UFOLibError("Another layer is already mapped to the default directory.")
|
||||
@ -1076,10 +1076,10 @@ class UFOWriter(object):
|
||||
else:
|
||||
# not caching this could be slightly expensive,
|
||||
# but caching it will be cumbersome
|
||||
existing = [d.lower() for d in self.layerContents.values()]
|
||||
if not isinstance(layerName, unicode):
|
||||
existing = [d.lower() for d in list(self.layerContents.values())]
|
||||
if not isinstance(layerName, str):
|
||||
try:
|
||||
layerName = unicode(layerName)
|
||||
layerName = str(layerName)
|
||||
except UnicodeDecodeError:
|
||||
raise UFOLibError("The specified layer name is not a Unicode string.")
|
||||
directory = userNameToFileName(layerName, existing=existing, prefix="glyphs.")
|
||||
@ -1118,14 +1118,14 @@ class UFOWriter(object):
|
||||
if newLayerName in self.layerContents:
|
||||
raise UFOLibError("A layer named %s already exists." % newLayerName)
|
||||
# make sure the default layer doesn't already exist
|
||||
if defaultLayer and DEFAULT_GLYPHS_DIRNAME in self.layerContents.values():
|
||||
if defaultLayer and DEFAULT_GLYPHS_DIRNAME in list(self.layerContents.values()):
|
||||
raise UFOLibError("A default layer already exists.")
|
||||
# get the paths
|
||||
oldDirectory = self._findDirectoryForLayerName(layerName)
|
||||
if defaultLayer:
|
||||
newDirectory = DEFAULT_GLYPHS_DIRNAME
|
||||
else:
|
||||
existing = [name.lower() for name in self.layerContents.values()]
|
||||
existing = [name.lower() for name in list(self.layerContents.values())]
|
||||
newDirectory = userNameToFileName(newLayerName, existing=existing, prefix="glyphs.")
|
||||
# update the internal mapping
|
||||
del self.layerContents[layerName]
|
||||
@ -1341,7 +1341,7 @@ def validateInfoVersion2Data(infoData):
|
||||
value is in the accepted range.
|
||||
"""
|
||||
validInfoData = {}
|
||||
for attr, value in infoData.items():
|
||||
for attr, value in list(infoData.items()):
|
||||
isValidValue = validateFontInfoVersion2ValueForAttribute(attr, value)
|
||||
if not isValidValue:
|
||||
raise UFOLibError("Invalid value for attribute %s (%s)." % (attr, repr(value)))
|
||||
@ -1385,7 +1385,7 @@ def validateInfoVersion3Data(infoData):
|
||||
value is in the accepted range.
|
||||
"""
|
||||
validInfoData = {}
|
||||
for attr, value in infoData.items():
|
||||
for attr, value in list(infoData.items()):
|
||||
isValidValue = validateFontInfoVersion3ValueForAttribute(attr, value)
|
||||
if not isValidValue:
|
||||
raise UFOLibError("Invalid value for attribute %s (%s)." % (attr, repr(value)))
|
||||
@ -1395,10 +1395,10 @@ def validateInfoVersion3Data(infoData):
|
||||
|
||||
# Value Options
|
||||
|
||||
fontInfoOpenTypeHeadFlagsOptions = range(0, 15)
|
||||
fontInfoOpenTypeHeadFlagsOptions = list(range(0, 15))
|
||||
fontInfoOpenTypeOS2SelectionOptions = [1, 2, 3, 4, 7, 8, 9]
|
||||
fontInfoOpenTypeOS2UnicodeRangesOptions = range(0, 128)
|
||||
fontInfoOpenTypeOS2CodePageRangesOptions = range(0, 64)
|
||||
fontInfoOpenTypeOS2UnicodeRangesOptions = list(range(0, 128))
|
||||
fontInfoOpenTypeOS2CodePageRangesOptions = list(range(0, 64))
|
||||
fontInfoOpenTypeOS2TypeOptions = [0, 1, 2, 3, 8, 9]
|
||||
|
||||
# Version Attribute Definitions
|
||||
@ -1450,23 +1450,23 @@ fontInfoAttributesVersion1 = set([
|
||||
])
|
||||
|
||||
fontInfoAttributesVersion2ValueData = {
|
||||
"familyName" : dict(type=basestring),
|
||||
"styleName" : dict(type=basestring),
|
||||
"styleMapFamilyName" : dict(type=basestring),
|
||||
"styleMapStyleName" : dict(type=basestring, valueValidator=fontInfoStyleMapStyleNameValidator),
|
||||
"familyName" : dict(type=str),
|
||||
"styleName" : dict(type=str),
|
||||
"styleMapFamilyName" : dict(type=str),
|
||||
"styleMapStyleName" : dict(type=str, valueValidator=fontInfoStyleMapStyleNameValidator),
|
||||
"versionMajor" : dict(type=int),
|
||||
"versionMinor" : dict(type=int),
|
||||
"year" : dict(type=int),
|
||||
"copyright" : dict(type=basestring),
|
||||
"trademark" : dict(type=basestring),
|
||||
"copyright" : dict(type=str),
|
||||
"trademark" : dict(type=str),
|
||||
"unitsPerEm" : dict(type=(int, float)),
|
||||
"descender" : dict(type=(int, float)),
|
||||
"xHeight" : dict(type=(int, float)),
|
||||
"capHeight" : dict(type=(int, float)),
|
||||
"ascender" : dict(type=(int, float)),
|
||||
"italicAngle" : dict(type=(float, int)),
|
||||
"note" : dict(type=basestring),
|
||||
"openTypeHeadCreated" : dict(type=basestring, valueValidator=fontInfoOpenTypeHeadCreatedValidator),
|
||||
"note" : dict(type=str),
|
||||
"openTypeHeadCreated" : dict(type=str, valueValidator=fontInfoOpenTypeHeadCreatedValidator),
|
||||
"openTypeHeadLowestRecPPEM" : dict(type=(int, float)),
|
||||
"openTypeHeadFlags" : dict(type="integerList", valueValidator=genericIntListValidator, valueOptions=fontInfoOpenTypeHeadFlagsOptions),
|
||||
"openTypeHheaAscender" : dict(type=(int, float)),
|
||||
@ -1475,25 +1475,25 @@ fontInfoAttributesVersion2ValueData = {
|
||||
"openTypeHheaCaretSlopeRise" : dict(type=int),
|
||||
"openTypeHheaCaretSlopeRun" : dict(type=int),
|
||||
"openTypeHheaCaretOffset" : dict(type=(int, float)),
|
||||
"openTypeNameDesigner" : dict(type=basestring),
|
||||
"openTypeNameDesignerURL" : dict(type=basestring),
|
||||
"openTypeNameManufacturer" : dict(type=basestring),
|
||||
"openTypeNameManufacturerURL" : dict(type=basestring),
|
||||
"openTypeNameLicense" : dict(type=basestring),
|
||||
"openTypeNameLicenseURL" : dict(type=basestring),
|
||||
"openTypeNameVersion" : dict(type=basestring),
|
||||
"openTypeNameUniqueID" : dict(type=basestring),
|
||||
"openTypeNameDescription" : dict(type=basestring),
|
||||
"openTypeNamePreferredFamilyName" : dict(type=basestring),
|
||||
"openTypeNamePreferredSubfamilyName" : dict(type=basestring),
|
||||
"openTypeNameCompatibleFullName" : dict(type=basestring),
|
||||
"openTypeNameSampleText" : dict(type=basestring),
|
||||
"openTypeNameWWSFamilyName" : dict(type=basestring),
|
||||
"openTypeNameWWSSubfamilyName" : dict(type=basestring),
|
||||
"openTypeNameDesigner" : dict(type=str),
|
||||
"openTypeNameDesignerURL" : dict(type=str),
|
||||
"openTypeNameManufacturer" : dict(type=str),
|
||||
"openTypeNameManufacturerURL" : dict(type=str),
|
||||
"openTypeNameLicense" : dict(type=str),
|
||||
"openTypeNameLicenseURL" : dict(type=str),
|
||||
"openTypeNameVersion" : dict(type=str),
|
||||
"openTypeNameUniqueID" : dict(type=str),
|
||||
"openTypeNameDescription" : dict(type=str),
|
||||
"openTypeNamePreferredFamilyName" : dict(type=str),
|
||||
"openTypeNamePreferredSubfamilyName" : dict(type=str),
|
||||
"openTypeNameCompatibleFullName" : dict(type=str),
|
||||
"openTypeNameSampleText" : dict(type=str),
|
||||
"openTypeNameWWSFamilyName" : dict(type=str),
|
||||
"openTypeNameWWSSubfamilyName" : dict(type=str),
|
||||
"openTypeOS2WidthClass" : dict(type=int, valueValidator=fontInfoOpenTypeOS2WidthClassValidator),
|
||||
"openTypeOS2WeightClass" : dict(type=int, valueValidator=fontInfoOpenTypeOS2WeightClassValidator),
|
||||
"openTypeOS2Selection" : dict(type="integerList", valueValidator=genericIntListValidator, valueOptions=fontInfoOpenTypeOS2SelectionOptions),
|
||||
"openTypeOS2VendorID" : dict(type=basestring),
|
||||
"openTypeOS2VendorID" : dict(type=str),
|
||||
"openTypeOS2Panose" : dict(type="integerList", valueValidator=fontInfoVersion2OpenTypeOS2PanoseValidator),
|
||||
"openTypeOS2FamilyClass" : dict(type="integerList", valueValidator=fontInfoOpenTypeOS2FamilyClassValidator),
|
||||
"openTypeOS2UnicodeRanges" : dict(type="integerList", valueValidator=genericIntListValidator, valueOptions=fontInfoOpenTypeOS2UnicodeRangesOptions),
|
||||
@ -1520,8 +1520,8 @@ fontInfoAttributesVersion2ValueData = {
|
||||
"openTypeVheaCaretSlopeRise" : dict(type=int),
|
||||
"openTypeVheaCaretSlopeRun" : dict(type=int),
|
||||
"openTypeVheaCaretOffset" : dict(type=(int, float)),
|
||||
"postscriptFontName" : dict(type=basestring),
|
||||
"postscriptFullName" : dict(type=basestring),
|
||||
"postscriptFontName" : dict(type=str),
|
||||
"postscriptFullName" : dict(type=str),
|
||||
"postscriptSlantAngle" : dict(type=(float, int)),
|
||||
"postscriptUniqueID" : dict(type=int),
|
||||
"postscriptUnderlineThickness" : dict(type=(int, float)),
|
||||
@ -1539,11 +1539,11 @@ fontInfoAttributesVersion2ValueData = {
|
||||
"postscriptForceBold" : dict(type=bool),
|
||||
"postscriptDefaultWidthX" : dict(type=(int, float)),
|
||||
"postscriptNominalWidthX" : dict(type=(int, float)),
|
||||
"postscriptWeightName" : dict(type=basestring),
|
||||
"postscriptDefaultCharacter" : dict(type=basestring),
|
||||
"postscriptWeightName" : dict(type=str),
|
||||
"postscriptDefaultCharacter" : dict(type=str),
|
||||
"postscriptWindowsCharacterSet" : dict(type=int, valueValidator=fontInfoPostscriptWindowsCharacterSetValidator),
|
||||
"macintoshFONDFamilyID" : dict(type=int),
|
||||
"macintoshFONDName" : dict(type=basestring),
|
||||
"macintoshFONDName" : dict(type=str),
|
||||
}
|
||||
fontInfoAttributesVersion2 = set(fontInfoAttributesVersion2ValueData.keys())
|
||||
|
||||
@ -1595,11 +1595,11 @@ fontInfoAttributesVersion3 = set(fontInfoAttributesVersion3ValueData.keys())
|
||||
|
||||
# insert the type validator for all attrs that
|
||||
# have no defined validator.
|
||||
for attr, dataDict in fontInfoAttributesVersion2ValueData.items():
|
||||
for attr, dataDict in list(fontInfoAttributesVersion2ValueData.items()):
|
||||
if "valueValidator" not in dataDict:
|
||||
dataDict["valueValidator"] = genericTypeValidator
|
||||
|
||||
for attr, dataDict in fontInfoAttributesVersion3ValueData.items():
|
||||
for attr, dataDict in list(fontInfoAttributesVersion3ValueData.items()):
|
||||
if "valueValidator" not in dataDict:
|
||||
dataDict["valueValidator"] = genericTypeValidator
|
||||
|
||||
@ -1609,7 +1609,7 @@ for attr, dataDict in fontInfoAttributesVersion3ValueData.items():
|
||||
|
||||
def _flipDict(d):
|
||||
flipped = {}
|
||||
for key, value in d.items():
|
||||
for key, value in list(d.items()):
|
||||
flipped[value] = key
|
||||
return flipped
|
||||
|
||||
@ -1751,7 +1751,7 @@ def convertFontInfoValueForAttributeFromVersion2ToVersion1(attr, value):
|
||||
|
||||
def _convertFontInfoDataVersion1ToVersion2(data):
|
||||
converted = {}
|
||||
for attr, value in data.items():
|
||||
for attr, value in list(data.items()):
|
||||
# FontLab gives -1 for the weightValue
|
||||
# for fonts wil no defined value. Many
|
||||
# format version 1 UFOs will have this.
|
||||
@ -1770,7 +1770,7 @@ def _convertFontInfoDataVersion1ToVersion2(data):
|
||||
|
||||
def _convertFontInfoDataVersion2ToVersion1(data):
|
||||
converted = {}
|
||||
for attr, value in data.items():
|
||||
for attr, value in list(data.items()):
|
||||
newAttr, newValue = convertFontInfoValueForAttributeFromVersion2ToVersion1(attr, value)
|
||||
# only take attributes that are registered for version 1
|
||||
if newAttr not in fontInfoAttributesVersion1:
|
||||
@ -1861,7 +1861,7 @@ def convertFontInfoValueForAttributeFromVersion3ToVersion2(attr, value):
|
||||
|
||||
def _convertFontInfoDataVersion3ToVersion2(data):
|
||||
converted = {}
|
||||
for attr, value in data.items():
|
||||
for attr, value in list(data.items()):
|
||||
newAttr, newValue = convertFontInfoValueForAttributeFromVersion3ToVersion2(attr, value)
|
||||
if newAttr not in fontInfoAttributesVersion2:
|
||||
continue
|
||||
@ -1870,7 +1870,7 @@ def _convertFontInfoDataVersion3ToVersion2(data):
|
||||
|
||||
def _convertFontInfoDataVersion2ToVersion3(data):
|
||||
converted = {}
|
||||
for attr, value in data.items():
|
||||
for attr, value in list(data.items()):
|
||||
attr, value = convertFontInfoValueForAttributeFromVersion2ToVersion3(attr, value)
|
||||
converted[attr] = value
|
||||
return converted
|
||||
|
@ -8,11 +8,11 @@ def convertUFO1OrUFO2KerningToUFO3Kerning(kerning, groups):
|
||||
# gather known kerning groups based on the prefixes
|
||||
firstReferencedGroups, secondReferencedGroups = findKnownKerningGroups(groups)
|
||||
# Make lists of groups referenced in kerning pairs.
|
||||
for first, seconds in kerning.items():
|
||||
for first, seconds in list(kerning.items()):
|
||||
if first in groups:
|
||||
if not first.startswith("public.kern1."):
|
||||
firstReferencedGroups.add(first)
|
||||
for second in seconds.keys():
|
||||
for second in list(seconds.keys()):
|
||||
if second in groups:
|
||||
if not second.startswith("public.kern2."):
|
||||
secondReferencedGroups.add(second)
|
||||
@ -20,7 +20,7 @@ def convertUFO1OrUFO2KerningToUFO3Kerning(kerning, groups):
|
||||
firstRenamedGroups = {}
|
||||
for first in firstReferencedGroups:
|
||||
# Make a list of existing group names.
|
||||
existingGroupNames = groups.keys() + firstRenamedGroups.keys()
|
||||
existingGroupNames = list(groups.keys()) + list(firstRenamedGroups.keys())
|
||||
# Add the prefix to the name.
|
||||
newName = "public.kern1." + first
|
||||
# Make a unique group name.
|
||||
@ -30,7 +30,7 @@ def convertUFO1OrUFO2KerningToUFO3Kerning(kerning, groups):
|
||||
secondRenamedGroups = {}
|
||||
for second in secondReferencedGroups:
|
||||
# Make a list of existing group names.
|
||||
existingGroupNames = groups.keys() + secondRenamedGroups.keys()
|
||||
existingGroupNames = list(groups.keys()) + list(secondRenamedGroups.keys())
|
||||
# Add the prefix to the name.
|
||||
newName = "public.kern2." + second
|
||||
# Make a unique group name.
|
||||
@ -39,17 +39,17 @@ def convertUFO1OrUFO2KerningToUFO3Kerning(kerning, groups):
|
||||
secondRenamedGroups[second] = newName
|
||||
# Populate the new group names into the kerning dictionary as needed.
|
||||
newKerning = {}
|
||||
for first, seconds in kerning.items():
|
||||
for first, seconds in list(kerning.items()):
|
||||
first = firstRenamedGroups.get(first, first)
|
||||
newSeconds = {}
|
||||
for second, value in seconds.items():
|
||||
for second, value in list(seconds.items()):
|
||||
second = secondRenamedGroups.get(second, second)
|
||||
newSeconds[second] = value
|
||||
newKerning[first] = newSeconds
|
||||
# Make copies of the referenced groups and store them
|
||||
# under the new names in the overall groups dictionary.
|
||||
allRenamedGroups = firstRenamedGroups.items()
|
||||
allRenamedGroups += secondRenamedGroups.items()
|
||||
allRenamedGroups = list(firstRenamedGroups.items())
|
||||
allRenamedGroups += list(secondRenamedGroups.items())
|
||||
for oldName, newName in allRenamedGroups:
|
||||
group = list(groups[oldName])
|
||||
groups[newName] = group
|
||||
@ -95,7 +95,7 @@ def findKnownKerningGroups(groups):
|
||||
]
|
||||
firstGroups = set()
|
||||
secondGroups = set()
|
||||
for groupName in groups.keys():
|
||||
for groupName in list(groups.keys()):
|
||||
for firstPrefix in knownFirstGroupPrefixes:
|
||||
if groupName.startswith(firstPrefix):
|
||||
firstGroups.add(groupName)
|
||||
|
@ -66,7 +66,7 @@ def userNameToFileName(userName, existing=[], prefix="", suffix=""):
|
||||
u'alt._con'
|
||||
"""
|
||||
# the incoming name must be a unicode string
|
||||
assert isinstance(userName, unicode), "The value for userName must be a unicode string."
|
||||
assert isinstance(userName, str), "The value for userName must be a unicode string."
|
||||
# establish the prefix and suffix lengths
|
||||
prefixLength = len(prefix)
|
||||
suffixLength = len(suffix)
|
||||
|
@ -12,13 +12,13 @@ glyph data. See the class doc string for details.
|
||||
"""
|
||||
|
||||
import os
|
||||
from cStringIO import StringIO
|
||||
from io import StringIO
|
||||
from warnings import warn
|
||||
from xmlTreeBuilder import buildTree, stripCharacterData
|
||||
from .xmlTreeBuilder import buildTree, stripCharacterData
|
||||
from ufoLib.pointPen import AbstractPointPen
|
||||
from plistlib import readPlist, writePlistToString
|
||||
from filenames import userNameToFileName
|
||||
from validators import isDictEnough, genericTypeValidator, colorValidator,\
|
||||
from .plistlib import readPlist, writePlistToString
|
||||
from .filenames import userNameToFileName
|
||||
from .validators import isDictEnough, genericTypeValidator, colorValidator,\
|
||||
guidelinesValidator, anchorsValidator, identifierValidator, imageValidator, glyphLibValidator
|
||||
|
||||
try:
|
||||
@ -144,10 +144,10 @@ class GlyphSet(object):
|
||||
if not isinstance(contents, dict):
|
||||
invalidFormat = True
|
||||
else:
|
||||
for name, fileName in contents.items():
|
||||
if not isinstance(name, basestring):
|
||||
for name, fileName in list(contents.items()):
|
||||
if not isinstance(name, str):
|
||||
invalidFormat = True
|
||||
if not isinstance(fileName, basestring):
|
||||
if not isinstance(fileName, str):
|
||||
invalidFormat = True
|
||||
elif not os.path.exists(os.path.join(self.dirName, fileName)):
|
||||
raise GlifLibError("contents.plist references a file that does not exist: %s" % fileName)
|
||||
@ -167,7 +167,7 @@ class GlyphSet(object):
|
||||
"""
|
||||
if self._reverseContents is None:
|
||||
d = {}
|
||||
for k, v in self.contents.iteritems():
|
||||
for k, v in self.contents.items():
|
||||
d[v.lower()] = k
|
||||
self._reverseContents = d
|
||||
return self._reverseContents
|
||||
@ -196,7 +196,7 @@ class GlyphSet(object):
|
||||
raise GlifLibError("layerinfo.plist is not properly formatted.")
|
||||
infoDict = validateLayerInfoVersion3Data(infoDict)
|
||||
# populate the object
|
||||
for attr, value in infoDict.items():
|
||||
for attr, value in list(infoDict.items()):
|
||||
try:
|
||||
setattr(info, attr, value)
|
||||
except AttributeError:
|
||||
@ -207,7 +207,7 @@ class GlyphSet(object):
|
||||
raise GlifLibError("layerinfo.plist is not allowed in UFO %d." % self.ufoFormatVersion)
|
||||
# gather data
|
||||
infoData = {}
|
||||
for attr in layerInfoVersion3ValueData.keys():
|
||||
for attr in list(layerInfoVersion3ValueData.keys()):
|
||||
if hasattr(info, attr):
|
||||
try:
|
||||
value = getattr(info, attr)
|
||||
@ -255,7 +255,7 @@ class GlyphSet(object):
|
||||
if needRead:
|
||||
fileName = self.contents[glyphName]
|
||||
if not os.path.exists(path):
|
||||
raise KeyError, glyphName
|
||||
raise KeyError(glyphName)
|
||||
f = open(path, "rb")
|
||||
text = f.read()
|
||||
f.close()
|
||||
@ -385,7 +385,7 @@ class GlyphSet(object):
|
||||
# dict-like support
|
||||
|
||||
def keys(self):
|
||||
return self.contents.keys()
|
||||
return list(self.contents.keys())
|
||||
|
||||
def has_key(self, glyphName):
|
||||
return glyphName in self.contents
|
||||
@ -397,7 +397,7 @@ class GlyphSet(object):
|
||||
|
||||
def __getitem__(self, glyphName):
|
||||
if glyphName not in self.contents:
|
||||
raise KeyError, glyphName
|
||||
raise KeyError(glyphName)
|
||||
return self.glyphClass(glyphName, self)
|
||||
|
||||
# quickly fetch unicode values
|
||||
@ -411,7 +411,7 @@ class GlyphSet(object):
|
||||
"""
|
||||
unicodes = {}
|
||||
if glyphNames is None:
|
||||
glyphNames = self.contents.keys()
|
||||
glyphNames = list(self.contents.keys())
|
||||
for glyphName in glyphNames:
|
||||
text = self.getGLIF(glyphName)
|
||||
unicodes[glyphName] = _fetchUnicodes(text)
|
||||
@ -426,7 +426,7 @@ class GlyphSet(object):
|
||||
"""
|
||||
components = {}
|
||||
if glyphNames is None:
|
||||
glyphNames = self.contents.keys()
|
||||
glyphNames = list(self.contents.keys())
|
||||
for glyphName in glyphNames:
|
||||
text = self.getGLIF(glyphName)
|
||||
components[glyphName] = _fetchComponentBases(text)
|
||||
@ -441,7 +441,7 @@ class GlyphSet(object):
|
||||
"""
|
||||
images = {}
|
||||
if glyphNames is None:
|
||||
glyphNames = self.contents.keys()
|
||||
glyphNames = list(self.contents.keys())
|
||||
for glyphName in glyphNames:
|
||||
text = self.getGLIF(glyphName)
|
||||
images[glyphName] = _fetchImageFileName(text)
|
||||
@ -465,10 +465,10 @@ def glyphNameToFileName(glyphName, glyphSet):
|
||||
"""
|
||||
Wrapper around the userNameToFileName function in filenames.py
|
||||
"""
|
||||
existing = [name.lower() for name in glyphSet.contents.values()]
|
||||
if not isinstance(glyphName, unicode):
|
||||
existing = [name.lower() for name in list(glyphSet.contents.values())]
|
||||
if not isinstance(glyphName, str):
|
||||
try:
|
||||
new = unicode(glyphName)
|
||||
new = str(glyphName)
|
||||
glyphName = new
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
@ -552,7 +552,7 @@ def writeGlyphToString(glyphName, glyphObject=None, drawPointsFunc=None, writer=
|
||||
aFile = None
|
||||
identifiers = set()
|
||||
# start
|
||||
if not isinstance(glyphName, basestring):
|
||||
if not isinstance(glyphName, str):
|
||||
raise GlifLibError("The glyph name is not properly formatted.")
|
||||
if len(glyphName) == 0:
|
||||
raise GlifLibError("The glyph name is empty.")
|
||||
@ -566,7 +566,7 @@ def writeGlyphToString(glyphName, glyphObject=None, drawPointsFunc=None, writer=
|
||||
n = glyphName.encode("utf8")
|
||||
utf8GlyphName = n
|
||||
except UnicodeEncodeError:
|
||||
raise GlifLibError(u"encountered a glyph name (%s) that can't be converted to UTF-8." % glyphName)
|
||||
raise GlifLibError("encountered a glyph name (%s) that can't be converted to UTF-8." % glyphName)
|
||||
writer.begintag("glyph", [("name", utf8GlyphName), ("format", formatVersion)])
|
||||
writer.newline()
|
||||
# advance
|
||||
@ -651,7 +651,7 @@ def _writeUnicodes(glyphObject, writer):
|
||||
|
||||
def _writeNote(glyphObject, writer):
|
||||
note = getattr(glyphObject, "note", None)
|
||||
if not isinstance(note, (str, unicode)):
|
||||
if not isinstance(note, str):
|
||||
raise GlifLibError("note attribute must be str or unicode")
|
||||
note = note.encode("utf-8")
|
||||
writer.begintag("note")
|
||||
@ -771,7 +771,7 @@ def _writeLib(glyphObject, writer):
|
||||
# -----------------------
|
||||
|
||||
layerInfoVersion3ValueData = {
|
||||
"color" : dict(type=basestring, valueValidator=colorValidator),
|
||||
"color" : dict(type=str, valueValidator=colorValidator),
|
||||
"lib" : dict(type=dict, valueValidator=genericTypeValidator)
|
||||
}
|
||||
|
||||
@ -813,7 +813,7 @@ def validateLayerInfoVersion3Data(infoData):
|
||||
value is in the accepted range.
|
||||
"""
|
||||
validInfoData = {}
|
||||
for attr, value in infoData.items():
|
||||
for attr, value in list(infoData.items()):
|
||||
if attr not in layerInfoVersion3ValueData:
|
||||
raise GlifLibError("Unknown attribute %s." % attr)
|
||||
isValidValue = validateLayerInfoVersion3ValueForAttribute(attr, value)
|
||||
@ -1018,7 +1018,7 @@ def _readNote(glyphObject, children):
|
||||
_relaxedSetattr(glyphObject, "note", note)
|
||||
|
||||
def _readLib(glyphObject, children):
|
||||
from plistFromTree import readPlistFromTree
|
||||
from .plistFromTree import readPlistFromTree
|
||||
assert len(children) == 1
|
||||
lib = readPlistFromTree(children[0])
|
||||
valid, message = glyphLibValidator(lib)
|
||||
@ -1097,7 +1097,8 @@ def _buildAnchorFormat1(point):
|
||||
anchor = dict(x=x, y=y, name=name)
|
||||
return anchor
|
||||
|
||||
def _buildOutlineContourFormat1(pen, (attrs, children)):
|
||||
def _buildOutlineContourFormat1(pen, xxx_todo_changeme):
|
||||
(attrs, children) = xxx_todo_changeme
|
||||
if set(attrs.keys()):
|
||||
raise GlifLibError("Unknown attributes in contour element.")
|
||||
pen.beginPath()
|
||||
@ -1115,7 +1116,8 @@ def _buildOutlinePointsFormat1(pen, children):
|
||||
name = attrs["name"]
|
||||
pen.addPoint((x, y), segmentType=segmentType, smooth=smooth, name=name)
|
||||
|
||||
def _buildOutlineComponentFormat1(pen, (attrs, children)):
|
||||
def _buildOutlineComponentFormat1(pen, xxx_todo_changeme1):
|
||||
(attrs, children) = xxx_todo_changeme1
|
||||
if len(children):
|
||||
raise GlifLibError("Unknown child elements of component element." % subElement)
|
||||
if set(attrs.keys()) - componentAttributesFormat1:
|
||||
@ -1148,7 +1150,8 @@ def buildOutlineFormat2(glyphObject, pen, xmlNodes, identifiers):
|
||||
else:
|
||||
raise GlifLibError("Unknown element in outline element: %s" % element)
|
||||
|
||||
def _buildOutlineContourFormat2(pen, (attrs, children), identifiers):
|
||||
def _buildOutlineContourFormat2(pen, xxx_todo_changeme2, identifiers):
|
||||
(attrs, children) = xxx_todo_changeme2
|
||||
if set(attrs.keys()) - contourAttributesFormat2:
|
||||
raise GlifLibError("Unknown attributes in contour element.")
|
||||
identifier = attrs.get("identifier")
|
||||
@ -1188,7 +1191,8 @@ def _buildOutlinePointsFormat2(pen, children, identifiers):
|
||||
pen.addPoint((x, y), segmentType=segmentType, smooth=smooth, name=name)
|
||||
raise warn("The addPoint method needs an identifier kwarg. The point's identifier value has been discarded.", DeprecationWarning)
|
||||
|
||||
def _buildOutlineComponentFormat2(pen, (attrs, children), identifiers):
|
||||
def _buildOutlineComponentFormat2(pen, xxx_todo_changeme3, identifiers):
|
||||
(attrs, children) = xxx_todo_changeme3
|
||||
if len(children):
|
||||
raise GlifLibError("Unknown child elements of component element." % subElement)
|
||||
if set(attrs.keys()) - componentAttributesFormat2:
|
||||
@ -1232,7 +1236,7 @@ def _validateAndMassagePointStructures(children, pointAttributes, openContourOff
|
||||
if subElement != "point":
|
||||
raise GlifLibError("Unknown child element (%s) of contour element." % subElement)
|
||||
# unknown attributes
|
||||
unknownAttributes = [attr for attr in attrs.keys() if attr not in pointAttributes]
|
||||
unknownAttributes = [attr for attr in list(attrs.keys()) if attr not in pointAttributes]
|
||||
if unknownAttributes:
|
||||
raise GlifLibError("Unknown attributes in point element.")
|
||||
# search for unknown children
|
||||
|
@ -6,7 +6,7 @@ by xmlTreeBuilder.
|
||||
__all__ = "readPlistFromTree"
|
||||
|
||||
|
||||
from plistlib import PlistParser
|
||||
from .plistlib import PlistParser
|
||||
|
||||
|
||||
def readPlistFromTree(tree):
|
||||
@ -30,14 +30,14 @@ class PlistTreeParser(PlistParser):
|
||||
if isinstance(child, tuple):
|
||||
self.parseElement(child[0], child[1], child[2])
|
||||
else:
|
||||
if not isinstance(child, unicode):
|
||||
if not isinstance(child, str):
|
||||
# ugh, xmlTreeBuilder returns utf-8 :-(
|
||||
child = unicode(child, "utf-8")
|
||||
child = str(child, "utf-8")
|
||||
self.handleData(child)
|
||||
self.handleEndElement(element)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from xmlTreeBuilder import buildTree
|
||||
from .xmlTreeBuilder import buildTree
|
||||
tree = buildTree("xxx.plist", stripData=0)
|
||||
print readPlistFromTree(tree)
|
||||
print(readPlistFromTree(tree))
|
||||
|
@ -28,7 +28,7 @@ def _gatherTestCasesFromCallerByMagic():
|
||||
|
||||
def _gatherTestCasesFromDict(d):
|
||||
testCases = []
|
||||
for ob in d.values():
|
||||
for ob in list(d.values()):
|
||||
if isinstance(ob, type) and issubclass(ob, unittest.TestCase):
|
||||
testCases.append(ob)
|
||||
return testCases
|
||||
@ -90,7 +90,7 @@ class Glyph(object):
|
||||
def drawPoints(self, pointPen):
|
||||
if self.outline:
|
||||
py = "\n".join(self.outline)
|
||||
exec py in {"pointPen" : pointPen}
|
||||
exec(py, {"pointPen" : pointPen})
|
||||
|
||||
def py(self):
|
||||
text = []
|
||||
@ -130,7 +130,7 @@ def _dictToString(d):
|
||||
value = _tupleToString(value)
|
||||
elif isinstance(value, (int, float)):
|
||||
value = str(value)
|
||||
elif isinstance(value, basestring):
|
||||
elif isinstance(value, str):
|
||||
value = "\"%s\"" % value
|
||||
text.append("%s : %s" % (key, value))
|
||||
if not text:
|
||||
@ -148,7 +148,7 @@ def _listToString(l):
|
||||
value = _tupleToString(value)
|
||||
elif isinstance(value, (int, float)):
|
||||
value = str(value)
|
||||
elif isinstance(value, basestring):
|
||||
elif isinstance(value, str):
|
||||
value = "\"%s\"" % value
|
||||
text.append(value)
|
||||
if not text:
|
||||
@ -166,7 +166,7 @@ def _tupleToString(t):
|
||||
value = _tupleToString(value)
|
||||
elif isinstance(value, (int, float)):
|
||||
value = str(value)
|
||||
elif isinstance(value, basestring):
|
||||
elif isinstance(value, str):
|
||||
value = "\"%s\"" % value
|
||||
text.append(value)
|
||||
if not text:
|
||||
@ -586,8 +586,8 @@ fontInfoVersion3 = {
|
||||
# identifier
|
||||
dict(x=100, y=200, angle=45, identifier="guide1"),
|
||||
dict(x=100, y=200, angle=45, identifier="guide2"),
|
||||
dict(x=100, y=200, angle=45, identifier=u"\x20"),
|
||||
dict(x=100, y=200, angle=45, identifier=u"\x7E"),
|
||||
dict(x=100, y=200, angle=45, identifier="\x20"),
|
||||
dict(x=100, y=200, angle=45, identifier="\x7E"),
|
||||
# colors
|
||||
dict(x=100, y=200, angle=45, color="0,0,0,0"),
|
||||
dict(x=100, y=200, angle=45, color="1,0,0,0"),
|
||||
|
@ -9,16 +9,16 @@ from ufoLib.test.testSupport import Glyph, stripText
|
||||
class TestGLIF1(unittest.TestCase):
|
||||
|
||||
def assertEqual(self, first, second, msg=None):
|
||||
if isinstance(first, basestring):
|
||||
if isinstance(first, str):
|
||||
first = stripText(first)
|
||||
if isinstance(second, basestring):
|
||||
if isinstance(second, str):
|
||||
second = stripText(second)
|
||||
return super(TestGLIF1, self).assertEqual(first, second, msg=msg)
|
||||
|
||||
def pyToGLIF(self, py):
|
||||
py = stripText(py)
|
||||
glyph = Glyph()
|
||||
exec py in {"glyph" : glyph, "pointPen" : glyph}
|
||||
exec(py, {"glyph" : glyph, "pointPen" : glyph})
|
||||
glif = writeGlyphToString(glyph.name, glyphObject=glyph, drawPointsFunc=glyph.drawPoints, formatVersion=1)
|
||||
glif = "\n".join(glif.splitlines()[1:])
|
||||
return glif
|
||||
|
@ -9,16 +9,16 @@ from ufoLib.test.testSupport import Glyph, stripText
|
||||
class TestGLIF2(unittest.TestCase):
|
||||
|
||||
def assertEqual(self, first, second, msg=None):
|
||||
if isinstance(first, basestring):
|
||||
if isinstance(first, str):
|
||||
first = stripText(first)
|
||||
if isinstance(second, basestring):
|
||||
if isinstance(second, str):
|
||||
second = stripText(second)
|
||||
return super(TestGLIF2, self).assertEqual(first, second, msg=msg)
|
||||
|
||||
def pyToGLIF(self, py):
|
||||
py = stripText(py)
|
||||
glyph = Glyph()
|
||||
exec py in {"glyph" : glyph, "pointPen" : glyph}
|
||||
exec(py, {"glyph" : glyph, "pointPen" : glyph})
|
||||
glif = writeGlyphToString(glyph.name, glyphObject=glyph, drawPointsFunc=glyph.drawPoints, formatVersion=2)
|
||||
glif = "\n".join(glif.splitlines()[1:])
|
||||
return glif
|
||||
|
@ -7,7 +7,7 @@ import tempfile
|
||||
import codecs
|
||||
from plistlib import writePlist, readPlist
|
||||
from ufoLib import UFOReader, UFOWriter, UFOLibError
|
||||
from testSupport import fontInfoVersion1, fontInfoVersion2
|
||||
from .testSupport import fontInfoVersion1, fontInfoVersion2
|
||||
|
||||
|
||||
class TestInfoObject(object): pass
|
||||
@ -52,7 +52,7 @@ class ReadFontInfoVersion1TestCase(unittest.TestCase):
|
||||
32 : "bold",
|
||||
33 : "bold italic"
|
||||
}
|
||||
for old, new in fontStyle1To2.items():
|
||||
for old, new in list(fontStyle1To2.items()):
|
||||
info = dict(fontInfoVersion1)
|
||||
info["fontStyle"] = old
|
||||
self._writeInfoToPlist(info)
|
||||
@ -73,7 +73,7 @@ class ReadFontInfoVersion1TestCase(unittest.TestCase):
|
||||
"Extra-expanded" : 8,
|
||||
"Ultra-expanded" : 9
|
||||
}
|
||||
for old, new in widthName1To2.items():
|
||||
for old, new in list(widthName1To2.items()):
|
||||
info = dict(fontInfoVersion1)
|
||||
info["widthName"] = old
|
||||
self._writeInfoToPlist(info)
|
||||
@ -95,7 +95,7 @@ class WriteFontInfoVersion1TestCase(unittest.TestCase):
|
||||
|
||||
def makeInfoObject(self):
|
||||
infoObject = TestInfoObject()
|
||||
for attr, value in fontInfoVersion2.items():
|
||||
for attr, value in list(fontInfoVersion2.items()):
|
||||
setattr(infoObject, attr, value)
|
||||
return infoObject
|
||||
|
||||
@ -108,7 +108,7 @@ class WriteFontInfoVersion1TestCase(unittest.TestCase):
|
||||
writer = UFOWriter(self.dstDir, formatVersion=1)
|
||||
writer.writeInfo(infoObject)
|
||||
writtenData = self.readPlist()
|
||||
for attr, originalValue in fontInfoVersion1.items():
|
||||
for attr, originalValue in list(fontInfoVersion1.items()):
|
||||
newValue = writtenData[attr]
|
||||
self.assertEqual(newValue, originalValue)
|
||||
|
||||
@ -119,7 +119,7 @@ class WriteFontInfoVersion1TestCase(unittest.TestCase):
|
||||
32 : "bold",
|
||||
33 : "bold italic"
|
||||
}
|
||||
for old, new in fontStyle1To2.items():
|
||||
for old, new in list(fontStyle1To2.items()):
|
||||
infoObject = self.makeInfoObject()
|
||||
infoObject.styleMapStyleName = new
|
||||
writer = UFOWriter(self.dstDir, formatVersion=1)
|
||||
@ -139,7 +139,7 @@ class WriteFontInfoVersion1TestCase(unittest.TestCase):
|
||||
"Extra-expanded" : 8,
|
||||
"Ultra-expanded" : 9
|
||||
}
|
||||
for old, new in widthName1To2.items():
|
||||
for old, new in list(widthName1To2.items()):
|
||||
infoObject = self.makeInfoObject()
|
||||
infoObject.openTypeOS2WidthClass = new
|
||||
writer = UFOWriter(self.dstDir, formatVersion=1)
|
||||
|
@ -7,7 +7,7 @@ import tempfile
|
||||
import codecs
|
||||
from plistlib import writePlist, readPlist
|
||||
from ufoLib import UFOReader, UFOWriter, UFOLibError
|
||||
from testSupport import fontInfoVersion2
|
||||
from .testSupport import fontInfoVersion2
|
||||
|
||||
|
||||
class TestInfoObject(object): pass
|
||||
@ -39,7 +39,7 @@ class ReadFontInfoVersion2TestCase(unittest.TestCase):
|
||||
reader = UFOReader(self.dstDir)
|
||||
reader.readInfo(infoObject)
|
||||
readData = {}
|
||||
for attr in fontInfoVersion2.keys():
|
||||
for attr in list(fontInfoVersion2.keys()):
|
||||
readData[attr] = getattr(infoObject, attr)
|
||||
self.assertEqual(originalData, readData)
|
||||
|
||||
@ -782,7 +782,7 @@ class WriteFontInfoVersion2TestCase(unittest.TestCase):
|
||||
|
||||
def makeInfoObject(self):
|
||||
infoObject = TestInfoObject()
|
||||
for attr, value in fontInfoVersion2.items():
|
||||
for attr, value in list(fontInfoVersion2.items()):
|
||||
setattr(infoObject, attr, value)
|
||||
return infoObject
|
||||
|
||||
@ -795,7 +795,7 @@ class WriteFontInfoVersion2TestCase(unittest.TestCase):
|
||||
writer = UFOWriter(self.dstDir, formatVersion=2)
|
||||
writer.writeInfo(infoObject)
|
||||
writtenData = self.readPlist()
|
||||
for attr, originalValue in fontInfoVersion2.items():
|
||||
for attr, originalValue in list(fontInfoVersion2.items()):
|
||||
newValue = writtenData[attr]
|
||||
self.assertEqual(newValue, originalValue)
|
||||
|
||||
|
@ -8,7 +8,7 @@ import codecs
|
||||
from plistlib import writePlist, readPlist
|
||||
from ufoLib import UFOReader, UFOWriter, UFOLibError
|
||||
from ufoLib.glifLib import GlifLibError
|
||||
from testSupport import fontInfoVersion3
|
||||
from .testSupport import fontInfoVersion3
|
||||
|
||||
|
||||
class TestInfoObject(object): pass
|
||||
@ -44,7 +44,7 @@ class ReadFontInfoVersion3TestCase(unittest.TestCase):
|
||||
reader = UFOReader(self.dstDir)
|
||||
reader.readInfo(infoObject)
|
||||
readData = {}
|
||||
for attr in fontInfoVersion3.keys():
|
||||
for attr in list(fontInfoVersion3.keys()):
|
||||
readData[attr] = getattr(infoObject, attr)
|
||||
self.assertEqual(originalData, readData)
|
||||
|
||||
@ -1707,7 +1707,7 @@ class WriteFontInfoVersion3TestCase(unittest.TestCase):
|
||||
|
||||
def makeInfoObject(self):
|
||||
infoObject = TestInfoObject()
|
||||
for attr, value in fontInfoVersion3.items():
|
||||
for attr, value in list(fontInfoVersion3.items()):
|
||||
setattr(infoObject, attr, value)
|
||||
return infoObject
|
||||
|
||||
@ -1720,7 +1720,7 @@ class WriteFontInfoVersion3TestCase(unittest.TestCase):
|
||||
writer = UFOWriter(self.dstDir, formatVersion=3)
|
||||
writer.writeInfo(infoObject)
|
||||
writtenData = self.readPlist()
|
||||
for attr, originalValue in fontInfoVersion3.items():
|
||||
for attr, originalValue in list(fontInfoVersion3.items()):
|
||||
newValue = writtenData[attr]
|
||||
self.assertEqual(newValue, originalValue)
|
||||
self.tearDownUFO()
|
||||
@ -3341,13 +3341,13 @@ class WriteFontInfoVersion3TestCase(unittest.TestCase):
|
||||
self.tearDownUFO()
|
||||
## below min
|
||||
infoObject = self.makeInfoObject()
|
||||
infoObject.guidelines = [dict(x=0, identifier=u"\0x1F")]
|
||||
infoObject.guidelines = [dict(x=0, identifier="\0x1F")]
|
||||
writer = UFOWriter(self.dstDir, formatVersion=3)
|
||||
self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject)
|
||||
self.tearDownUFO()
|
||||
## above max
|
||||
infoObject = self.makeInfoObject()
|
||||
infoObject.guidelines = [dict(x=0, identifier=u"\0x7F")]
|
||||
infoObject.guidelines = [dict(x=0, identifier="\0x7F")]
|
||||
writer = UFOWriter(self.dstDir, formatVersion=3)
|
||||
self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject)
|
||||
self.tearDownUFO()
|
||||
@ -3977,7 +3977,7 @@ class UFO3WriteLayersTestCase(unittest.TestCase):
|
||||
def testRenameLayer(self):
|
||||
self.makeUFO()
|
||||
writer = UFOWriter(self.ufoPath)
|
||||
writer.renameGlyphSet("layer 1", u"layer 3")
|
||||
writer.renameGlyphSet("layer 1", "layer 3")
|
||||
writer.writeLayerContents(["public.default", "layer 3", "layer 2"])
|
||||
# directories
|
||||
path = os.path.join(self.ufoPath, "glyphs")
|
||||
@ -4001,8 +4001,8 @@ class UFO3WriteLayersTestCase(unittest.TestCase):
|
||||
def testRenameLayerDefault(self):
|
||||
self.makeUFO()
|
||||
writer = UFOWriter(self.ufoPath)
|
||||
writer.renameGlyphSet("public.default", u"layer xxx")
|
||||
writer.renameGlyphSet("layer 1", u"layer 1", defaultLayer=True)
|
||||
writer.renameGlyphSet("public.default", "layer xxx")
|
||||
writer.renameGlyphSet("layer 1", "layer 1", defaultLayer=True)
|
||||
writer.writeLayerContents(["layer xxx", "layer 1", "layer 2"])
|
||||
path = os.path.join(self.ufoPath, "glyphs")
|
||||
exists = os.path.exists(path)
|
||||
@ -4027,14 +4027,14 @@ class UFO3WriteLayersTestCase(unittest.TestCase):
|
||||
def testRenameLayerDuplicateName(self):
|
||||
self.makeUFO()
|
||||
writer = UFOWriter(self.ufoPath)
|
||||
self.assertRaises(UFOLibError, writer.renameGlyphSet, "layer 1", u"layer 2")
|
||||
self.assertRaises(UFOLibError, writer.renameGlyphSet, "layer 1", "layer 2")
|
||||
|
||||
# rename unknown layer
|
||||
|
||||
def testRenameLayerDuplicateName(self):
|
||||
self.makeUFO()
|
||||
writer = UFOWriter(self.ufoPath)
|
||||
self.assertRaises(UFOLibError, writer.renameGlyphSet, "does not exist", u"layer 2")
|
||||
self.assertRaises(UFOLibError, writer.renameGlyphSet, "does not exist", "layer 2")
|
||||
|
||||
# remove valid layer
|
||||
|
||||
@ -4169,7 +4169,7 @@ class UFO3WriteDataTestCase(unittest.TestCase):
|
||||
self.tearDownUFO()
|
||||
# basic file with unicode text
|
||||
path = "data/org.unifiedfontobject.writebytesbasicunicodefile.txt"
|
||||
bytes = u"tëßt"
|
||||
bytes = "tëßt"
|
||||
writer = UFOWriter(self.dstDir, formatVersion=3)
|
||||
writer.writeBytesToPath(path, bytes, encoding="utf8")
|
||||
path = os.path.join(self.dstDir, path)
|
||||
|
@ -7,7 +7,7 @@ import tempfile
|
||||
import codecs
|
||||
from plistlib import writePlist, readPlist
|
||||
from ufoLib import convertUFOFormatVersion1ToFormatVersion2, UFOReader, UFOWriter
|
||||
from testSupport import expectedFontInfo1To2Conversion, expectedFontInfo2To1Conversion
|
||||
from .testSupport import expectedFontInfo1To2Conversion, expectedFontInfo2To1Conversion
|
||||
|
||||
|
||||
# the format version 1 lib.plist contains some data
|
||||
|
@ -25,12 +25,12 @@ class GlyphSetTests(unittest.TestCase):
|
||||
dstDir = self.dstDir
|
||||
src = GlyphSet(srcDir)
|
||||
dst = GlyphSet(dstDir)
|
||||
for glyphName in src.keys():
|
||||
for glyphName in list(src.keys()):
|
||||
g = src[glyphName]
|
||||
g.drawPoints(None) # load attrs
|
||||
dst.writeGlyph(glyphName, g, g.drawPoints)
|
||||
# compare raw file data:
|
||||
for glyphName in src.keys():
|
||||
for glyphName in list(src.keys()):
|
||||
fileName = src.contents[glyphName]
|
||||
org = file(os.path.join(srcDir, fileName), READ_MODE).read()
|
||||
new = file(os.path.join(dstDir, fileName), READ_MODE).read()
|
||||
@ -45,10 +45,10 @@ class GlyphSetTests(unittest.TestCase):
|
||||
def testReverseContents(self):
|
||||
gset = GlyphSet(GLYPHSETDIR)
|
||||
d = {}
|
||||
for k, v in gset.getReverseContents().items():
|
||||
for k, v in list(gset.getReverseContents().items()):
|
||||
d[v] = k
|
||||
org = {}
|
||||
for k, v in gset.contents.items():
|
||||
for k, v in list(gset.contents.items()):
|
||||
org[k] = v.lower()
|
||||
self.assertEqual(d, org)
|
||||
|
||||
@ -57,7 +57,7 @@ class GlyphSetTests(unittest.TestCase):
|
||||
dst = GlyphSet(self.dstDir)
|
||||
dstMap = dst.getReverseContents()
|
||||
self.assertEqual(dstMap, {})
|
||||
for glyphName in src.keys():
|
||||
for glyphName in list(src.keys()):
|
||||
g = src[glyphName]
|
||||
g.drawPoints(None) # load attrs
|
||||
dst.writeGlyph(glyphName, g, g.drawPoints)
|
||||
@ -73,20 +73,20 @@ class GlyphSetTests(unittest.TestCase):
|
||||
return "prefix" + glyphNameToFileName(glyphName, glyphSet)
|
||||
src = GlyphSet(GLYPHSETDIR)
|
||||
dst = GlyphSet(self.dstDir, myGlyphNameToFileName)
|
||||
for glyphName in src.keys():
|
||||
for glyphName in list(src.keys()):
|
||||
g = src[glyphName]
|
||||
g.drawPoints(None) # load attrs
|
||||
dst.writeGlyph(glyphName, g, g.drawPoints)
|
||||
d = {}
|
||||
for k, v in src.contents.items():
|
||||
print k, v
|
||||
for k, v in list(src.contents.items()):
|
||||
print(k, v)
|
||||
d[k] = "prefix" + v
|
||||
self.assertEqual(d, dst.contents)
|
||||
|
||||
def testGetUnicodes(self):
|
||||
src = GlyphSet(GLYPHSETDIR)
|
||||
unicodes = src.getUnicodes()
|
||||
for glyphName in src.keys():
|
||||
for glyphName in list(src.keys()):
|
||||
g = src[glyphName]
|
||||
g.drawPoints(None) # load attrs
|
||||
if not hasattr(g, "unicodes"):
|
||||
|
@ -69,17 +69,17 @@ def genericDictValidator(value, prototype):
|
||||
if not isinstance(value, dict):
|
||||
return False
|
||||
# missing required keys
|
||||
for key, (typ, required) in prototype.items():
|
||||
for key, (typ, required) in list(prototype.items()):
|
||||
if not required:
|
||||
continue
|
||||
if key not in value:
|
||||
return False
|
||||
# unknown keys
|
||||
for key in value.keys():
|
||||
for key in list(value.keys()):
|
||||
if key not in prototype:
|
||||
return False
|
||||
# incorrect types
|
||||
for key, v in value.items():
|
||||
for key, v in list(value.items()):
|
||||
prototypeType, required = prototype[key]
|
||||
if v is None and not required:
|
||||
continue
|
||||
@ -132,7 +132,7 @@ def fontInfoOpenTypeHeadCreatedValidator(value):
|
||||
Version 2+.
|
||||
"""
|
||||
# format: 0000/00/00 00:00:00
|
||||
if not isinstance(value, basestring):
|
||||
if not isinstance(value, str):
|
||||
return False
|
||||
# basic formatting
|
||||
if not len(value) == 19:
|
||||
@ -192,7 +192,7 @@ def fontInfoOpenTypeNameRecordsValidator(value):
|
||||
"""
|
||||
if not isinstance(value, list):
|
||||
return False
|
||||
dictPrototype = dict(nameID=(int, True), platformID=(int, True), encodingID=(int, True), languageID=(int, True), string=(basestring, True))
|
||||
dictPrototype = dict(nameID=(int, True), platformID=(int, True), encodingID=(int, True), languageID=(int, True), string=(str, True))
|
||||
for nameRecord in value:
|
||||
if not genericDictValidator(nameRecord, dictPrototype):
|
||||
return False
|
||||
@ -315,7 +315,7 @@ def fontInfoPostscriptWindowsCharacterSetValidator(value):
|
||||
"""
|
||||
Version 2+.
|
||||
"""
|
||||
validValues = range(1, 21)
|
||||
validValues = list(range(1, 21))
|
||||
if value not in validValues:
|
||||
return False
|
||||
return True
|
||||
@ -324,7 +324,7 @@ def fontInfoWOFFMetadataUniqueIDValidator(value):
|
||||
"""
|
||||
Version 3+.
|
||||
"""
|
||||
dictPrototype = dict(id=(basestring, True))
|
||||
dictPrototype = dict(id=(str, True))
|
||||
if not genericDictValidator(value, dictPrototype):
|
||||
return False
|
||||
return True
|
||||
@ -333,7 +333,7 @@ def fontInfoWOFFMetadataVendorValidator(value):
|
||||
"""
|
||||
Version 3+.
|
||||
"""
|
||||
dictPrototype = {"name" : (basestring, True), "url" : (basestring, False), "dir" : (basestring, False), "class" : (basestring, False)}
|
||||
dictPrototype = {"name" : (str, True), "url" : (str, False), "dir" : (str, False), "class" : (str, False)}
|
||||
if not genericDictValidator(value, dictPrototype):
|
||||
return False
|
||||
if "dir" in value and value.get("dir") not in ("ltr", "rtl"):
|
||||
@ -349,7 +349,7 @@ def fontInfoWOFFMetadataCreditsValidator(value):
|
||||
return False
|
||||
if not len(value["credits"]):
|
||||
return False
|
||||
dictPrototype = {"name" : (basestring, True), "url" : (basestring, False), "role" : (basestring, False), "dir" : (basestring, False), "class" : (basestring, False)}
|
||||
dictPrototype = {"name" : (str, True), "url" : (str, False), "role" : (str, False), "dir" : (str, False), "class" : (str, False)}
|
||||
for credit in value["credits"]:
|
||||
if not genericDictValidator(credit, dictPrototype):
|
||||
return False
|
||||
@ -361,7 +361,7 @@ def fontInfoWOFFMetadataDescriptionValidator(value):
|
||||
"""
|
||||
Version 3+.
|
||||
"""
|
||||
dictPrototype = dict(url=(basestring, False), text=(list, True))
|
||||
dictPrototype = dict(url=(str, False), text=(list, True))
|
||||
if not genericDictValidator(value, dictPrototype):
|
||||
return False
|
||||
for text in value["text"]:
|
||||
@ -373,7 +373,7 @@ def fontInfoWOFFMetadataLicenseValidator(value):
|
||||
"""
|
||||
Version 3+.
|
||||
"""
|
||||
dictPrototype = dict(url=(basestring, False), text=(list, False), id=(basestring, False))
|
||||
dictPrototype = dict(url=(str, False), text=(list, False), id=(str, False))
|
||||
if not genericDictValidator(value, dictPrototype):
|
||||
return False
|
||||
if "text" in value:
|
||||
@ -410,7 +410,7 @@ def fontInfoWOFFMetadataLicenseeValidator(value):
|
||||
"""
|
||||
Version 3+.
|
||||
"""
|
||||
dictPrototype = {"name" : (basestring, True), "dir" : (basestring, False), "class" : (basestring, False)}
|
||||
dictPrototype = {"name" : (str, True), "dir" : (str, False), "class" : (str, False)}
|
||||
if not genericDictValidator(value, dictPrototype):
|
||||
return False
|
||||
if "dir" in value and value.get("dir") not in ("ltr", "rtl"):
|
||||
@ -421,7 +421,7 @@ def fontInfoWOFFMetadataTextValue(value):
|
||||
"""
|
||||
Version 3+.
|
||||
"""
|
||||
dictPrototype = {"text" : (basestring, True), "language" : (basestring, False), "dir" : (basestring, False), "class" : (basestring, False)}
|
||||
dictPrototype = {"text" : (str, True), "language" : (str, False), "dir" : (str, False), "class" : (str, False)}
|
||||
if not genericDictValidator(value, dictPrototype):
|
||||
return False
|
||||
if "dir" in value and value.get("dir") not in ("ltr", "rtl"):
|
||||
@ -445,7 +445,7 @@ def fontInfoWOFFMetadataExtensionValidator(value):
|
||||
"""
|
||||
Version 3+.
|
||||
"""
|
||||
dictPrototype = dict(names=(list, False), items=(list, True), id=(basestring, False))
|
||||
dictPrototype = dict(names=(list, False), items=(list, True), id=(str, False))
|
||||
if not genericDictValidator(value, dictPrototype):
|
||||
return False
|
||||
if "names" in value:
|
||||
@ -461,7 +461,7 @@ def fontInfoWOFFMetadataExtensionItemValidator(value):
|
||||
"""
|
||||
Version 3+.
|
||||
"""
|
||||
dictPrototype = dict(id=(basestring, False), names=(list, True), values=(list, True))
|
||||
dictPrototype = dict(id=(str, False), names=(list, True), values=(list, True))
|
||||
if not genericDictValidator(value, dictPrototype):
|
||||
return False
|
||||
for name in value["names"]:
|
||||
@ -476,7 +476,7 @@ def fontInfoWOFFMetadataExtensionNameValidator(value):
|
||||
"""
|
||||
Version 3+.
|
||||
"""
|
||||
dictPrototype = {"text" : (basestring, True), "language" : (basestring, False), "dir" : (basestring, False), "class" : (basestring, False)}
|
||||
dictPrototype = {"text" : (str, True), "language" : (str, False), "dir" : (str, False), "class" : (str, False)}
|
||||
if not genericDictValidator(value, dictPrototype):
|
||||
return False
|
||||
if "dir" in value and value.get("dir") not in ("ltr", "rtl"):
|
||||
@ -487,7 +487,7 @@ def fontInfoWOFFMetadataExtensionValueValidator(value):
|
||||
"""
|
||||
Version 3+.
|
||||
"""
|
||||
dictPrototype = {"text" : (basestring, True), "language" : (basestring, False), "dir" : (basestring, False), "class" : (basestring, False)}
|
||||
dictPrototype = {"text" : (str, True), "language" : (str, False), "dir" : (str, False), "class" : (str, False)}
|
||||
if not genericDictValidator(value, dictPrototype):
|
||||
return False
|
||||
if "dir" in value and value.get("dir") not in ("ltr", "rtl"):
|
||||
@ -522,7 +522,7 @@ def guidelineValidator(value):
|
||||
"""
|
||||
dictPrototype = dict(
|
||||
x=((int, float), False), y=((int, float), False), angle=((int, float), False),
|
||||
name=(basestring, False), color=(basestring, False), identifier=(basestring, False)
|
||||
name=(str, False), color=(str, False), identifier=(str, False)
|
||||
)
|
||||
if not genericDictValidator(value, dictPrototype):
|
||||
return False
|
||||
@ -583,7 +583,7 @@ def anchorValidator(value):
|
||||
"""
|
||||
dictPrototype = dict(
|
||||
x=((int, float), False), y=((int, float), False),
|
||||
name=(basestring, False), color=(basestring, False), identifier=(basestring, False)
|
||||
name=(str, False), color=(str, False), identifier=(str, False)
|
||||
)
|
||||
if not genericDictValidator(value, dictPrototype):
|
||||
return False
|
||||
@ -619,7 +619,7 @@ def identifierValidator(value):
|
||||
"""
|
||||
validCharactersMin = 0x20
|
||||
validCharactersMax = 0x7E
|
||||
if not isinstance(value, basestring):
|
||||
if not isinstance(value, str):
|
||||
return False
|
||||
if not value:
|
||||
return False
|
||||
@ -678,7 +678,7 @@ def colorValidator(value):
|
||||
>>> colorValidator("1, 1, 1, 1")
|
||||
True
|
||||
"""
|
||||
if not isinstance(value, basestring):
|
||||
if not isinstance(value, str):
|
||||
return False
|
||||
parts = value.split(",")
|
||||
if len(parts) != 4:
|
||||
@ -714,10 +714,10 @@ def imageValidator(value):
|
||||
Version 3+.
|
||||
"""
|
||||
dictPrototype = dict(
|
||||
fileName=(basestring, True),
|
||||
fileName=(str, True),
|
||||
xScale=((int, float), False), xyScale=((int, float), False), yxScale=((int, float), False), yScale=((int, float), False),
|
||||
xOffset=((int, float), False), yOffset=((int, float), False),
|
||||
color=(basestring, False)
|
||||
color=(str, False)
|
||||
)
|
||||
if not genericDictValidator(value, dictPrototype):
|
||||
return False
|
||||
@ -775,7 +775,7 @@ def layerContentsValidator(value, ufoPath):
|
||||
if not len(entry) == 2:
|
||||
return False, bogusFileMessage
|
||||
for i in entry:
|
||||
if not isinstance(i, basestring):
|
||||
if not isinstance(i, str):
|
||||
return False, bogusFileMessage
|
||||
layerName, directoryName = entry
|
||||
# check directory naming
|
||||
@ -801,7 +801,7 @@ def layerContentsValidator(value, ufoPath):
|
||||
# store
|
||||
contents[layerName] = directoryName
|
||||
# missing default layer
|
||||
foundDefault = "glyphs" in contents.values()
|
||||
foundDefault = "glyphs" in list(contents.values())
|
||||
if not foundDefault:
|
||||
return False, "The required default glyph set is not in the UFO."
|
||||
return True, None
|
||||
@ -847,8 +847,8 @@ def groupsValidator(value):
|
||||
return False, bogusFormatMessage
|
||||
firstSideMapping = {}
|
||||
secondSideMapping = {}
|
||||
for groupName, glyphList in value.items():
|
||||
if not isinstance(groupName, basestring):
|
||||
for groupName, glyphList in list(value.items()):
|
||||
if not isinstance(groupName, str):
|
||||
return False, bogusFormatMessage
|
||||
if not isinstance(glyphList, (list, tuple)):
|
||||
return False, bogusFormatMessage
|
||||
@ -866,7 +866,7 @@ def groupsValidator(value):
|
||||
else:
|
||||
d = secondSideMapping
|
||||
for glyphName in glyphList:
|
||||
if not isinstance(glyphName, basestring):
|
||||
if not isinstance(glyphName, str):
|
||||
return False, "The group data %s contains an invalid member." % groupName
|
||||
if glyphName in d:
|
||||
return False, "The glyph \"%s\" occurs in too many kerning groups." % glyphName
|
||||
@ -907,7 +907,7 @@ def kerningValidatorReportPairs(kerning, groups):
|
||||
# flatten the groups
|
||||
flatFirstGroups = {}
|
||||
flatSecondGroups = {}
|
||||
for groupName, glyphList in groups.items():
|
||||
for groupName, glyphList in list(groups.items()):
|
||||
if not groupName.startswith("public.kern1.") and not groupName.startswith("public.kern2."):
|
||||
continue
|
||||
if groupName.startswith("public.kern1."):
|
||||
@ -1004,8 +1004,8 @@ def fontLibValidator(value):
|
||||
bogusFormatMessage = "The lib data is not in the correct format."
|
||||
if not isDictEnough(value):
|
||||
return False, bogusFormatMessage
|
||||
for key, value in value.items():
|
||||
if not isinstance(key, basestring):
|
||||
for key, value in list(value.items()):
|
||||
if not isinstance(key, str):
|
||||
return False, bogusFormatMessage
|
||||
# public.glyphOrder
|
||||
if key == "public.glyphOrder":
|
||||
@ -1013,7 +1013,7 @@ def fontLibValidator(value):
|
||||
if not isinstance(value, (list, tuple)):
|
||||
return False, bogusGlyphOrderMessage
|
||||
for glyphName in value:
|
||||
if not isinstance(glyphName, basestring):
|
||||
if not isinstance(glyphName, str):
|
||||
return False, bogusGlyphOrderMessage
|
||||
return True, None
|
||||
|
||||
@ -1045,8 +1045,8 @@ def glyphLibValidator(value):
|
||||
bogusFormatMessage = "The lib data is not in the correct format."
|
||||
if not isDictEnough(value):
|
||||
return False, bogusFormatMessage
|
||||
for key, value in value.items():
|
||||
if not isinstance(key, basestring):
|
||||
for key, value in list(value.items()):
|
||||
if not isinstance(key, str):
|
||||
return False, bogusFormatMessage
|
||||
# public.markColor
|
||||
if key == "public.markColor":
|
||||
|
@ -40,7 +40,7 @@ class XMLParser:
|
||||
parser.StartElementHandler = self.startElementHandler
|
||||
parser.EndElementHandler = self.endElementHandler
|
||||
parser.CharacterDataHandler = self.characterDataHandler
|
||||
if isinstance(pathOrFile, (str, unicode)):
|
||||
if isinstance(pathOrFile, str):
|
||||
f = open(pathOrFile)
|
||||
didOpen = 1
|
||||
else:
|
||||
@ -59,7 +59,7 @@ class XMLParser:
|
||||
proc.app.handle_start_tag = self.startElementHandler
|
||||
proc.app.handle_end_tag = self.endElementHandler
|
||||
proc.app.handle_data = self._xmlprocDataHandler
|
||||
if isinstance(pathOrFile, (str, unicode)):
|
||||
if isinstance(pathOrFile, str):
|
||||
f = open(pathOrFile)
|
||||
didOpen = 1
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user