2to3 --fix=idioms

This commit is contained in:
Behdad Esfahbod 2013-11-27 04:15:34 -05:00
parent c2e2e835ec
commit ac1b435946
44 changed files with 126 additions and 173 deletions

View File

@ -177,7 +177,7 @@ class AFM:
ncomponents = int(m.group(2))
rest = rest[m.regs[0][1]:]
components = []
while 1:
while True:
m = componentRE.match(rest)
if m is None:
raise error("syntax error in AFM file: " + repr(rest))
@ -215,8 +215,7 @@ class AFM:
lines.append(attr + " " + str(value))
# then write the attributes we don't know about,
# in alphabetical order
items = attrs.items()
items.sort()
items = sorted(attrs.items())
for attr, value in items:
if attr in preferredAttributeOrder:
continue
@ -254,8 +253,7 @@ class AFM:
lines.append("EndKernData")
if self._composites:
composites = self._composites.items()
composites.sort()
composites = sorted(self._composites.items())
lines.append("StartComposites %s" % len(self._composites))
for charname, components in composites:
line = "CC %s %s ;" % (charname, len(components))
@ -316,7 +314,7 @@ class AFM:
raise AttributeError(attr)
def __getitem__(self, key):
if type(key) == types.TupleType:
if isinstance(key, types.TupleType):
# key is a tuple, return the kernpair
return self._kerning[key]
else:
@ -324,7 +322,7 @@ class AFM:
return self._chars[key]
def __setitem__(self, key, value):
if type(key) == types.TupleType:
if isinstance(key, types.TupleType):
# key is a tuple, set kernpair
self._kerning[key] = value
else:
@ -332,7 +330,7 @@ class AFM:
self._chars[key] = value
def __delitem__(self, key):
if type(key) == types.TupleType:
if isinstance(key, types.TupleType):
# key is a tuple, del kernpair
del self._kerning[key]
else:

View File

@ -136,7 +136,7 @@ class CFFWriter:
def toFile(self, file):
lastPosList = None
count = 1
while 1:
while True:
if DEBUG:
print "CFFWriter.toFile() iteration:", count
count = count + 1
@ -558,8 +558,7 @@ class CharStrings:
return self.charStrings[name], sel
def toXML(self, xmlWriter, progress):
names = self.keys()
names.sort()
names = sorted(self.keys())
i = 0
step = 10
numGlyphs = len(names)

View File

@ -206,8 +206,7 @@ class FontFamily:
def _buildboundingboxtable(self):
if self.boundingBoxes and self._rawoffsettable[:6] == '\0\0\0\0\0\6':
boxes = self.boundingBoxes.items()
boxes.sort()
boxes = sorted(self.boundingBoxes.items())
data = '\0\0\0\0\0\6' + struct.pack(">h", len(boxes) - 1)
for style, (l, b, r, t) in boxes:
data = data + struct.pack(">hhhhh", style, l, b, r, t)
@ -241,8 +240,7 @@ class FontFamily:
return
numberofentries = len(self.widthTables)
data = struct.pack('>h', numberofentries - 1)
tables = self.widthTables.items()
tables.sort()
tables = sorted(self.widthTables.items())
for stylecode, table in tables:
data = data + struct.pack('>h', stylecode)
if len(table) != (3 + self.ffLastChar - self.ffFirstChar):
@ -284,8 +282,7 @@ class FontFamily:
return
numberofentries = len(self.kernTables)
data = [struct.pack('>h', numberofentries - 1)]
tables = self.kernTables.items()
tables.sort()
tables = sorted(self.kernTables.items())
for stylecode, table in tables:
data.append(struct.pack('>h', stylecode))
data.append(struct.pack('>h', len(table))) # numberofpairs
@ -375,8 +372,7 @@ class FontFamily:
for part in split:
nameparts[part] = None
del nameparts[self.ffFamilyName]
nameparts = nameparts.keys()
nameparts.sort()
nameparts = sorted(nameparts.keys())
items = splitnames.items()
items.sort()
numindices = 0
@ -433,8 +429,7 @@ class FontFamily:
return
numberofentries = len(self.glyphEncoding)
data = struct.pack(">h", numberofentries)
items = self.glyphEncoding.items()
items.sort()
items = sorted(self.glyphEncoding.items())
for glyphcode, glyphname in items:
data = data + chr(glyphcode) + chr(len(glyphname)) + glyphname
self._rawglyphencodingsubtable = data
@ -497,8 +492,7 @@ class BitmapFontFile:
for fond in self.fonds:
fond.parse()
if hasattr(fond, "psNames") and fond.psNames:
psNames = fond.psNames.values()
psNames.sort()
psNames = sorted(fond.psNames.values())
self.fondsbyname[psNames[0]] = fond
def minimalparse(self):

View File

@ -132,8 +132,7 @@ def splitQuadratic(pt1, pt2, pt3, where, isHorizontal):
a, b, c = calcQuadraticParameters(pt1, pt2, pt3)
solutions = solveQuadratic(a[isHorizontal], b[isHorizontal],
c[isHorizontal] - where)
solutions = [t for t in solutions if 0 <= t < 1]
solutions.sort()
solutions = sorted([t for t in solutions if 0 <= t < 1])
if not solutions:
return [(pt1, pt2, pt3)]
return _splitQuadraticAtT(a, b, c, *solutions)
@ -157,8 +156,7 @@ def splitCubic(pt1, pt2, pt3, pt4, where, isHorizontal):
a, b, c, d = calcCubicParameters(pt1, pt2, pt3, pt4)
solutions = solveCubic(a[isHorizontal], b[isHorizontal], c[isHorizontal],
d[isHorizontal] - where)
solutions = [t for t in solutions if 0 <= t < 1]
solutions.sort()
solutions = sorted([t for t in solutions if 0 <= t < 1])
if not solutions:
return [(pt1, pt2, pt3, pt4)]
return _splitCubicAtT(a, b, c, d, *solutions)

View File

@ -65,7 +65,7 @@ class ByteCodeBase:
def read_realNumber(self, b0, data, index):
number = ''
while 1:
while True:
b = ord(data[index])
index = index + 1
nibble0 = (b & 0xf0) >> 4
@ -87,7 +87,7 @@ def buildOperatorDict(operatorList):
oper[item[0]] = item[1]
else:
oper[item[0]] = item[1:]
if type(item[0]) == types.TupleType:
if isinstance(item[0], types.TupleType):
opc[item[1]] = item[0]
else:
opc[item[1]] = (item[0],)
@ -334,7 +334,7 @@ class T2CharString(ByteCodeBase):
return None, 0, 0
token = self.program[index]
index = index + 1
isOperator = type(token) == StringType
isOperator = isinstance(token, StringType)
return token, isOperator, index
def getBytes(self, index, nBytes):
@ -364,7 +364,7 @@ class T2CharString(ByteCodeBase):
else:
index = 0
args = []
while 1:
while True:
token, isOperator, index = self.getToken(index)
if token is None:
break
@ -472,7 +472,7 @@ class T1CharString(T2CharString):
return
program = []
index = 0
while 1:
while True:
token, isOperator, index = self.getToken(index)
if token is None:
break
@ -510,7 +510,7 @@ class SimpleT2Decompiler:
pushToProgram = lambda x: None
pushToStack = self.operandStack.append
index = 0
while 1:
while True:
token, isOperator, index = charString.getToken(index)
if token is None:
break # we're done!
@ -1143,7 +1143,7 @@ class DictDecompiler(ByteCodeBase):
return None, index
def handle_operator(self, operator, argType):
if type(argType) == type(()):
if isinstance(argType, type(())):
value = ()
for i in range(len(argType)-1, -1, -1):
arg = argType[i]

View File

@ -63,7 +63,7 @@ error = "sstruct.error"
def pack(format, object):
formatstring, names, fixes = getformat(format)
elements = []
if type(object) is not types.DictType:
if not isinstance(object, types.DictType):
object = object.__dict__
for name in names:
value = object[name]
@ -78,7 +78,7 @@ def unpack(format, data, object=None):
if object is None:
object = {}
formatstring, names, fixes = getformat(format)
if type(object) is types.DictType:
if isinstance(object, types.DictType):
dict = object
else:
dict = object.__dict__

View File

@ -77,8 +77,7 @@ def caselessSort(alist):
(lower(item), item), alist)
except TypeError:
# at least one element in alist is not a string, proceed the normal way...
alist = alist[:]
alist.sort()
alist = sorted(alist[:])
return alist
else:
tupledlist.sort()

View File

@ -37,7 +37,7 @@ class XMLReader:
parser.CharacterDataHandler = self._characterDataHandler
pos = 0
while 1:
while True:
chunk = file.read(BUFSIZE)
if not chunk:
parser.Parse(chunk, 1)

View File

@ -108,8 +108,7 @@ class XMLWriter:
def stringifyattrs(self, *args, **kwargs):
if kwargs:
assert not args
attributes = kwargs.items()
attributes.sort()
attributes = sorted(kwargs.items())
elif args:
assert len(args) == 1
attributes = args[0]

View File

@ -276,7 +276,7 @@ def dataFromFile(pathOrFSSpec, nameOrID="", resType='NFNT'):
if not nameOrID:
# just take the first in the file
res = Res.Get1IndResource(resType, 1)
elif type(nameOrID) == types.IntType:
elif isinstance(nameOrID, types.IntType):
res = Res.Get1Resource(resType, nameOrID)
else:
res = Res.Get1NamedResource(resType, nameOrID)

View File

@ -120,8 +120,7 @@ class PointInsidePen(BasePen):
cy = (y2 - dy) * 3.0
by = (y3 - y2) * 3.0 - cy
ay = y4 - dy - cy - by
solutions = solveCubic(ay, by, cy, dy - y)
solutions.sort()
solutions = sorted(solveCubic(ay, by, cy, dy - y))
solutions = [t for t in solutions if ZERO_MINUS_EPSILON <= t <= ONE_PLUS_EPSILON]
if not solutions:
return
@ -176,8 +175,7 @@ class PointInsidePen(BasePen):
c = y1
b = (y2 - c) * 2.0
a = y3 - c - b
solutions = solveQuadratic(a, b, c - y)
solutions.sort()
solutions = sorted(solveQuadratic(a, b, c - y))
solutions = [t for t in solutions if ZERO_MINUS_EPSILON <= t <= ONE_PLUS_EPSILON]
if not solutions:
return

View File

@ -177,7 +177,7 @@ def readPFB(path, onlyHeader=0):
"""reads a PFB font file, returns raw data"""
f = open(path, "rb")
data = []
while 1:
while True:
if f.read(1) != chr(128):
raise T1Error('corrupt PFB file')
code = ord(f.read(1))
@ -311,7 +311,7 @@ def decryptType1(data):
def findEncryptedChunks(data):
chunks = []
while 1:
while True:
eBegin = string.find(data, EEXECBEGIN)
if eBegin < 0:
break

View File

@ -519,8 +519,7 @@ class TTFont:
def getGlyphNames(self):
"""Get a list of glyph names, sorted alphabetically."""
glyphNames = self.getGlyphOrder()[:]
glyphNames.sort()
glyphNames = sorted(self.getGlyphOrder()[:])
return glyphNames
def getGlyphNames2(self):
@ -913,8 +912,7 @@ def sortedTagList(tagList, tableOrder=None):
specification, or according to a custom tableOrder. If given and not
None, tableOrder needs to be a list of tag names.
"""
tagList = list(tagList)
tagList.sort()
tagList = sorted(tagList)
if tableOrder is None:
if "DSIG" in tagList:
# DSIG should be last (XXX spec reference?)

View File

@ -60,7 +60,7 @@ class SFNTResourceReader:
def __init__(self, path, res_name_or_index):
resref = MyOpenResFile(path)
Res.UseResFile(resref)
if type(res_name_or_index) == type(""):
if isinstance(res_name_or_index, type("")):
res = Res.Get1NamedResource('sfnt', res_name_or_index)
else:
res = Res.Get1IndResource('sfnt', res_name_or_index)

View File

@ -173,8 +173,7 @@ class SFNTWriter:
"""All tables must have been written to disk. Now write the
directory.
"""
tables = self.tables.items()
tables.sort()
tables = sorted(self.tables.items())
if len(tables) != self.numTables:
from fontTools import ttLib
raise ttLib.TTLibError("wrong number of tables; expected %d, found %d" % (self.numTables, len(tables)))
@ -250,8 +249,7 @@ class SFNTWriter:
# Create a SFNT directory for checksum calculation purposes
self.searchRange, self.entrySelector, self.rangeShift = getSearchRange(self.numTables)
directory = sstruct.pack(sfntDirectoryFormat, self)
tables = self.tables.items()
tables.sort()
tables = sorted(self.tables.items())
for tag, entry in tables:
sfntEntry = SFNTDirectoryEntry()
for item in ['tag', 'checkSum', 'offset', 'length']:

View File

@ -40,7 +40,7 @@ class BitmapGlyphMetrics:
def fromXML(self, name, attrs, content, ttFont):
metricNames = set(sstruct.getformat(self.__class__.binaryFormat)[1])
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
# Make sure this is a metric that is needed by GlyphMetrics.

View File

@ -119,7 +119,7 @@ class table_C_O_L_R_(DefaultTable.DefaultTable):
def __getitem__(self, glyphSelector):
if type(glyphSelector) == IntType:
if isinstance(glyphSelector, IntType):
# its a gid, convert to glyph name
glyphSelector = self.getGlyphName(glyphSelector)
@ -129,7 +129,7 @@ class table_C_O_L_R_(DefaultTable.DefaultTable):
return self.ColorLayers[glyphSelector]
def __setitem__(self, glyphSelector, value):
if type(glyphSelector) == IntType:
if isinstance(glyphSelector, IntType):
# its a gid, convert to glyph name
glyphSelector = self.getGlyphName(glyphSelector)
@ -151,7 +151,7 @@ class LayerRecord:
def fromXML(self, eltname, attrs, content, ttFont):
for (name, value) in attrs.items():
if name == "name":
if type(value) == IntType:
if isinstance(value, IntType):
value = ttFont.getGlyphName(value)
setattr(self, name, value)
else:

View File

@ -37,7 +37,7 @@ class DefaultTable:
return "<'%s' table at %x>" % (self.tableTag, id(self))
def __cmp__(self, other):
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.__dict__, other.__dict__)

View File

@ -155,7 +155,7 @@ class table_E_B_D_T_(DefaultTable.DefaultTable):
bitmapGlyphDict = {}
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name[4:].startswith(_bitmapGlyphSubclassPrefix[4:]):
@ -191,7 +191,7 @@ class EbdtComponent:
self.name = attrs['name']
componentNames = set(sstruct.getformat(ebdtComponentFormat)[1][1:])
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name in componentNames:
@ -287,7 +287,7 @@ def _readRowImageData(bitmapObject, name, attrs, content, ttFont):
dataRows = []
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attr, content = element
# Chop off 'imagedata' from the tag to get just the option.
@ -328,7 +328,7 @@ def _readBitwiseImageData(bitmapObject, name, attrs, content, ttFont):
dataRows = []
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attr, content = element
if name == 'row':
@ -415,7 +415,7 @@ class BitmapGlyph:
def fromXML(self, name, attrs, content, ttFont):
self.readMetrics(name, attrs, content, ttFont)
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attr, content = element
# Chop off 'imagedata' from the tag to get just the option.
@ -464,7 +464,7 @@ def _createBitmapPlusMetricsMixin(metricsClass):
def readMetrics(self, name, attrs, content, ttFont):
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name == curMetricsName:
@ -671,13 +671,13 @@ class ComponentBitmapGlyph(BitmapGlyph):
def fromXML(self, name, attrs, content, ttFont):
self.readMetrics(name, attrs, content, ttFont)
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attr, content = element
if name == 'components':
self.componentArray = []
for compElement in content:
if type(compElement) != TupleType:
if not isinstance(compElement, TupleType):
continue
name, attrs, content = compElement
if name == 'ebdtComponent':

View File

@ -242,7 +242,7 @@ class Strike:
def fromXML(self, name, attrs, content, ttFont, locator):
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name == 'bitmapSizeTable':
@ -282,7 +282,7 @@ class BitmapSizeTable:
# bitmap size table. Only read the information from these names.
dataNames = set(self._getXMLMetricNames())
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name == 'sbitLineMetrics':
@ -311,7 +311,7 @@ class SbitLineMetrics:
def fromXML(self, name, attrs, content, ttFont):
metricNames = set(sstruct.getformat(sbitLineMetricsFormat)[1])
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name in metricNames:
@ -378,7 +378,7 @@ class EblcIndexSubTable:
self.names = []
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name == 'glyphLoc':
@ -494,7 +494,7 @@ class FixedSizeIndexSubTableMixin:
def readMetrics(self, name, attrs, content, ttFont):
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name == 'imageSize':

View File

@ -35,8 +35,7 @@ class table_L_T_S_H_(DefaultTable.DefaultTable):
return struct.pack(">HH", version, numGlyphs) + yPels.tostring()
def toXML(self, writer, ttFont):
names = self.yPels.keys()
names.sort()
names = sorted(self.yPels.keys())
for name in names:
writer.simpletag("yPel", name=name, value=self.yPels[name])
writer.newline()

View File

@ -229,7 +229,7 @@ class GlyphRecord:
"""Compare method, so a list of NameRecords can be sorted
according to the spec by just sorting it..."""
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.glyphID, other.glyphID)
@ -314,7 +314,7 @@ class StringRecord:
"""Compare method, so a list of NameRecords can be sorted
according to the spec by just sorting it..."""
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.labelID, other.labelID)

View File

@ -172,7 +172,7 @@ class table_O_S_2f_2(DefaultTable.DefaultTable):
if name == "panose":
self.panose = panose = Panose()
for element in content:
if type(element) == TupleType:
if isinstance(element, TupleType):
name, attrs, content = element
panose.fromXML(name, attrs, content, ttFont)
elif name in ("ulUnicodeRange1", "ulUnicodeRange2",

View File

@ -327,7 +327,7 @@ class ColorPalettes:
def fromXML(self, name, attrs, content, ttFont):
for element in content:
if type(element) == type(""):
if isinstance(element, type("")):
continue
name, attrib, content = element
if name == "colorParamUINameID":
@ -352,7 +352,7 @@ class ColorPalette:
def fromXML(self, name, attrs, content, ttFont):
self.uiNameID = int(attrs["uiNameID"])
for element in content:
if type(element) == type(""):
if isinstance(element, type("")):
continue
name, attrib, content = element
if name == "colorRecord":

View File

@ -59,8 +59,7 @@ class table_T_S_I__1(DefaultTable.DefaultTable):
data = data + text
extra_indices = []
codes = self.extras.items()
codes.sort()
codes = sorted(self.extras.items())
for i in range(len(codes)):
if len(data) % 2:
data = data + "\015" # align on 2-byte boundaries, fill with return chars.
@ -78,8 +77,7 @@ class table_T_S_I__1(DefaultTable.DefaultTable):
return data
def toXML(self, writer, ttFont):
names = self.glyphPrograms.keys()
names.sort()
names = sorted(self.glyphPrograms.keys())
writer.newline()
for name in names:
text = self.glyphPrograms[name]

View File

@ -28,8 +28,7 @@ class table_T_S_I__5(DefaultTable.DefaultTable):
return a.tostring()
def toXML(self, writer, ttFont):
names = self.glyphGrouping.keys()
names.sort()
names = sorted(self.glyphGrouping.keys())
for glyphName in names:
writer.simpletag("glyphgroup", name=glyphName, value=self.glyphGrouping[glyphName])
writer.newline()

View File

@ -96,7 +96,7 @@ class table_V_O_R_G_(DefaultTable.DefaultTable):
def __getitem__(self, glyphSelector):
if type(glyphSelector) == IntType:
if isinstance(glyphSelector, IntType):
# its a gid, convert to glyph name
glyphSelector = self.getGlyphName(glyphSelector)
@ -106,7 +106,7 @@ class table_V_O_R_G_(DefaultTable.DefaultTable):
return self.VOriginRecords[glyphSelector]
def __setitem__(self, glyphSelector, value):
if type(glyphSelector) == IntType:
if isinstance(glyphSelector, IntType):
# its a gid, convert to glyph name
glyphSelector = self.getGlyphName(glyphSelector)

View File

@ -132,8 +132,7 @@ class CmapSubtable:
("language", self.language),
])
writer.newline()
codes = self.cmap.items()
codes.sort()
codes = sorted(self.cmap.items())
self._writeCodes(codes, writer)
writer.endtag(self.__class__.__name__)
writer.newline()
@ -151,7 +150,7 @@ class CmapSubtable:
writer.newline()
def __cmp__(self, other):
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
# implemented so that list.sort() sorts according to the cmap spec.
selfTuple = (
@ -191,8 +190,7 @@ class cmap_format_0(CmapSubtable):
if self.data:
return struct.pack(">HHH", 0, 262, self.language) + self.data
charCodeList = self.cmap.items()
charCodeList.sort()
charCodeList = sorted(self.cmap.items())
charCodes = [entry[0] for entry in charCodeList]
valueList = [entry[1] for entry in charCodeList]
assert charCodes == list(range(256))
@ -209,7 +207,7 @@ class cmap_format_0(CmapSubtable):
self.cmap = {}
cmap = self.cmap
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name != "map":
@ -380,8 +378,7 @@ class cmap_format_2(CmapSubtable):
kEmptyTwoCharCodeRange = -1
notdefGI = 0
items = self.cmap.items()
items.sort()
items = sorted(self.cmap.items())
charCodes = [item[0] for item in items]
names = [item[1] for item in items]
nameMap = ttFont.getReverseGlyphMap()
@ -529,7 +526,7 @@ class cmap_format_2(CmapSubtable):
cmap = self.cmap
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name != "map":
@ -821,7 +818,7 @@ class cmap_format_4(CmapSubtable):
cmap = self.cmap
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
nameMap, attrsMap, dummyContent = element
if nameMap != "map":
@ -890,7 +887,7 @@ class cmap_format_6(CmapSubtable):
cmap = self.cmap
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name != "map":
@ -1016,8 +1013,7 @@ class cmap_format_12_or_13(CmapSubtable):
("nGroups", self.nGroups),
])
writer.newline()
codes = self.cmap.items()
codes.sort()
codes = sorted(self.cmap.items())
self._writeCodes(codes, writer)
writer.endtag(self.__class__.__name__)
writer.newline()
@ -1033,7 +1029,7 @@ class cmap_format_12_or_13(CmapSubtable):
cmap = self.cmap
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name != "map":
@ -1164,8 +1160,7 @@ class cmap_format_14(CmapSubtable):
])
writer.newline()
uvsDict = self.uvsDict
uvsList = uvsDict.keys()
uvsList.sort()
uvsList = sorted(uvsDict.keys())
for uvs in uvsList:
uvList = uvsDict[uvs]
uvList.sort(cmpUVSListEntry)
@ -1190,7 +1185,7 @@ class cmap_format_14(CmapSubtable):
uvsDict = self.uvsDict
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name != "map":
@ -1211,8 +1206,7 @@ class cmap_format_14(CmapSubtable):
return struct.pack(">HLL", self.format, self.length , self.numVarSelectorRecords) + self.data
uvsDict = self.uvsDict
uvsList = uvsDict.keys()
uvsList.sort()
uvsList = sorted(uvsDict.keys())
self.numVarSelectorRecords = len(uvsList)
offset = 10 + self.numVarSelectorRecords*11 # current value is end of VarSelectorRecords block.
data = []

View File

@ -25,8 +25,7 @@ class table__g_a_s_p(DefaultTable.DefaultTable):
version = 0 # ignore self.version
numRanges = len(self.gaspRange)
data = ""
items = self.gaspRange.items()
items.sort()
items = sorted(self.gaspRange.items())
for rangeMaxPPEM, rangeGaspBehavior in items:
data = data + struct.pack(">HH", rangeMaxPPEM, rangeGaspBehavior)
if rangeGaspBehavior & ~(GASP_GRIDFIT | GASP_DOGRAY):
@ -35,8 +34,7 @@ class table__g_a_s_p(DefaultTable.DefaultTable):
return data
def toXML(self, writer, ttFont):
items = self.gaspRange.items()
items.sort()
items = sorted(self.gaspRange.items())
for rangeMaxPPEM, rangeGaspBehavior in items:
writer.simpletag("gaspRange", [
("rangeMaxPPEM", rangeMaxPPEM),

View File

@ -124,7 +124,7 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
setattr(glyph, attr, safeEval(attrs.get(attr, '0')))
self.glyphs[glyphName] = glyph
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
glyph.fromXML(name, attrs, content, ttFont)
@ -290,7 +290,7 @@ class Glyph:
coordinates = GlyphCoordinates()
flags = []
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name != "pt":
@ -318,7 +318,7 @@ class Glyph:
elif name == "instructions":
self.program = ttProgram.Program()
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
self.program.fromXML(name, attrs, content, ttFont)
@ -425,7 +425,7 @@ class Glyph:
xFormat = ">" # big endian
yFormat = ">" # big endian
i = j = 0
while 1:
while True:
flag = ord(data[i])
i = i + 1
repeat = 1
@ -672,7 +672,7 @@ class Glyph:
# padding.
coordBytes = 0
j = 0
while 1:
while True:
flag = data[i]
i = i + 1
repeat = 1
@ -725,7 +725,7 @@ class Glyph:
self.data = data
def __cmp__(self, other):
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.__dict__, other.__dict__)
@ -888,7 +888,7 @@ class GlyphComponent:
self.flags = safeEval(attrs["flags"])
def __cmp__(self, other):
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.__dict__, other.__dict__)
@ -971,7 +971,7 @@ class GlyphCoordinates:
def reprflag(flag):
bin = ""
if type(flag) == StringType:
if isinstance(flag, StringType):
flag = ord(flag)
while flag:
if flag & 0x01:

View File

@ -34,8 +34,7 @@ class table__h_d_m_x(DefaultTable.DefaultTable):
pad = (self.recordSize - 2 - numGlyphs) * "\0"
self.numRecords = len(self.hdmx)
data = sstruct.pack(hdmxHeaderFormat, self)
items = self.hdmx.items()
items.sort()
items = sorted(self.hdmx.items())
for ppem, widths in items:
data = data + chr(ppem) + chr(max(widths.values()))
for glyphID in range(len(glyphOrder)):
@ -47,8 +46,7 @@ class table__h_d_m_x(DefaultTable.DefaultTable):
def toXML(self, writer, ttFont):
writer.begintag("hdmxData")
writer.newline()
ppems = self.hdmx.keys()
ppems.sort()
ppems = sorted(self.hdmx.keys())
records = []
format = ""
for ppem in ppems:

View File

@ -87,7 +87,7 @@ class table__h_e_a_d(DefaultTable.DefaultTable):
setattr(self, name, value)
def __cmp__(self, other):
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
selfdict = self.__dict__.copy()

View File

@ -72,8 +72,7 @@ class table__h_m_t_x(DefaultTable.DefaultTable):
return data
def toXML(self, writer, ttFont):
names = self.metrics.keys()
names.sort()
names = sorted(self.metrics.keys())
for glyphName in names:
advance, sb = self.metrics[glyphName]
writer.simpletag("mtx", [

View File

@ -120,10 +120,9 @@ class KernTable_format_0:
data = struct.pack(">HHHH", nPairs, searchRange, entrySelector, rangeShift)
# yeehee! (I mean, turn names into indices)
kernTable = map(lambda ((left, right), value), getGlyphID=ttFont.getGlyphID:
kernTable = sorted(map(lambda ((left, right), value), getGlyphID=ttFont.getGlyphID:
(getGlyphID(left), getGlyphID(right), value),
self.kernTable.items())
kernTable.sort()
self.kernTable.items()))
for left, right, value in kernTable:
data = data + struct.pack(">HHh", left, right, value)
return struct.pack(">HHH", self.version, len(data) + 6, self.coverage) + data
@ -131,8 +130,7 @@ class KernTable_format_0:
def toXML(self, writer, ttFont):
writer.begintag("kernsubtable", coverage=self.coverage, format=0)
writer.newline()
items = self.kernTable.items()
items.sort()
items = sorted(self.kernTable.items())
for (left, right), value in items:
writer.simpletag("pair", [
("l", left),
@ -149,7 +147,7 @@ class KernTable_format_0:
if not hasattr(self, "kernTable"):
self.kernTable = {}
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
self.kernTable[(attrs["l"], attrs["r"])] = safeEval(attrs["v"])
@ -164,7 +162,7 @@ class KernTable_format_0:
del self.kernTable[pair]
def __cmp__(self, other):
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.__dict__, other.__dict__)

View File

@ -60,7 +60,7 @@ class table__l_o_c_a(DefaultTable.DefaultTable):
return len(self.locations)
def __cmp__(self, other):
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.locations, other.locations)

View File

@ -112,8 +112,7 @@ class table__m_a_x_p(DefaultTable.DefaultTable):
headTable.flags = headTable.flags & ~0x2
def testrepr(self):
items = self.__dict__.items()
items.sort()
items = sorted(self.__dict__.items())
print ". . . . . . . . ."
for combo in items:
print " %s: %s" % combo

View File

@ -89,7 +89,7 @@ class table__n_a_m_e(DefaultTable.DefaultTable):
return None # not found
def __cmp__(self, other):
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.names, other.names)
@ -138,7 +138,7 @@ class NameRecord:
"""Compare method, so a list of NameRecords can be sorted
according to the spec by just sorting it..."""
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
selftuple = (
getattr(self, "platformID", None),

View File

@ -165,8 +165,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
"ps name mapping for those cases where they differ. That's what\n"
"you see below.\n")
writer.newline()
items = self.mapping.items()
items.sort()
items = sorted(self.mapping.items())
for name, psName in items:
writer.simpletag("psName", name=name, psName=psName)
writer.newline()
@ -195,7 +194,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
elif name == "psNames":
self.mapping = {}
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name == "psName":
@ -203,7 +202,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
elif name == "extraNames":
self.extraNames = []
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
if name == "psName":

View File

@ -43,8 +43,7 @@ class BaseTTXConverter(DefaultTable):
self.table = tableClass()
self.table.decompile(reader, font)
if cachingStats:
stats = [(v, k) for k, v in cachingStats.items()]
stats.sort()
stats = sorted([(v, k) for k, v in cachingStats.items()])
stats.reverse()
print "cachingsstats for ", self.tableTag
for v, k in stats:
@ -289,7 +288,7 @@ class OTTableWriter(object):
return hash(self.items)
def __cmp__(self, other):
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.items, other.items)
@ -675,7 +674,7 @@ class BaseTable(object):
setattr(self, conv.name, value)
def __cmp__(self, other):
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
self.ensureDecompiled()
@ -829,19 +828,19 @@ class ValueRecord:
for k, v in attrs.items():
setattr(self, k, int(v))
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
value = getattr(otTables, name)()
for elem2 in content:
if type(elem2) != TupleType:
if not isinstance(elem2, TupleType):
continue
name2, attrs2, content2 = elem2
value.fromXML(name2, attrs2, content2, font)
setattr(self, name, value)
def __cmp__(self, other):
if type(self) != type(other): return cmp(type(self), type(other))
if not isinstance(self, type(other)): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.__dict__, other.__dict__)

View File

@ -198,7 +198,7 @@ class Struct(BaseConverter):
if Format is not None:
table.Format = int(Format)
for element in content:
if type(element) == TupleType:
if isinstance(element, TupleType):
name, attrs, content = element
table.fromXML(name, attrs, content, font)
else:

View File

@ -163,8 +163,7 @@ class SingleSubst(FormatSwitchingBaseTable):
items = mapping.items()
getGlyphID = font.getGlyphID
gidItems = [(getGlyphID(item[0]), getGlyphID(item[1])) for item in items]
sortableItems = list(zip(gidItems, items))
sortableItems.sort()
sortableItems = sorted(zip(gidItems, items))
# figure out format
format = 2
@ -193,8 +192,7 @@ class SingleSubst(FormatSwitchingBaseTable):
return rawTable
def toXML2(self, xmlWriter, font):
items = self.mapping.items()
items.sort()
items = sorted(self.mapping.items())
for inGlyph, outGlyph in items:
xmlWriter.simpletag("Substitution",
[("in", inGlyph), ("out", outGlyph)])
@ -273,8 +271,7 @@ class ClassDef(FormatSwitchingBaseTable):
return {"ClassRangeRecord": ranges}
def toXML2(self, xmlWriter, font):
items = self.classDefs.items()
items.sort()
items = sorted(self.classDefs.items())
for glyphName, cls in items:
xmlWriter.simpletag("ClassDef", [("glyph", glyphName), ("class", cls)])
xmlWriter.newline()
@ -329,8 +326,7 @@ class AlternateSubst(FormatSwitchingBaseTable):
return {"Coverage": cov, "AlternateSet": alternates}
def toXML2(self, xmlWriter, font):
items = self.alternates.items()
items.sort()
items = sorted(self.alternates.items())
for glyphName, alternates in items:
xmlWriter.begintag("AlternateSet", glyph=glyphName)
xmlWriter.newline()
@ -349,7 +345,7 @@ class AlternateSubst(FormatSwitchingBaseTable):
set = []
alternates[glyphName] = set
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
set.append(attrs["glyph"])
@ -396,8 +392,7 @@ class LigatureSubst(FormatSwitchingBaseTable):
return {"Coverage": cov, "LigatureSet": ligSets}
def toXML2(self, xmlWriter, font):
items = self.ligatures.items()
items.sort()
items = sorted(self.ligatures.items())
for glyphName, ligSets in items:
xmlWriter.begintag("LigatureSet", glyph=glyphName)
xmlWriter.newline()
@ -417,7 +412,7 @@ class LigatureSubst(FormatSwitchingBaseTable):
ligs = []
ligatures[glyphName] = ligs
for element in content:
if type(element) != TupleType:
if not isinstance(element, TupleType):
continue
name, attrs, content = element
lig = Ligature()
@ -523,8 +518,7 @@ def splitAlternateSubst(oldSubTable, newSubTable, overflowRecord):
if hasattr(oldSubTable, 'sortCoverageLast'):
newSubTable.sortCoverageLast = oldSubTable.sortCoverageLast
oldAlts = oldSubTable.alternates.items()
oldAlts.sort()
oldAlts = sorted(oldSubTable.alternates.items())
oldLen = len(oldAlts)
if overflowRecord.itemName in [ 'Coverage', 'RangeRecord']:
@ -552,8 +546,7 @@ def splitAlternateSubst(oldSubTable, newSubTable, overflowRecord):
def splitLigatureSubst(oldSubTable, newSubTable, overflowRecord):
ok = 1
newSubTable.Format = oldSubTable.Format
oldLigs = oldSubTable.ligatures.items()
oldLigs.sort()
oldLigs = sorted(oldSubTable.ligatures.items())
oldLen = len(oldLigs)
if overflowRecord.itemName in [ 'Coverage', 'RangeRecord']:

View File

@ -269,7 +269,7 @@ class Program:
skipWhite=_skipWhite, mnemonicDict=mnemonicDict, strip=string.strip,
binary2num=binary2num):
assembly = self.assembly
if type(assembly) == type([]):
if isinstance(assembly, type([])):
assembly = string.join(assembly, " ")
bytecode = []
push = bytecode.append

View File

@ -173,8 +173,7 @@ def ttList(input, output, options):
import string
ttf = TTFont(input, fontNumber=options.fontNumber, lazy=True)
reader = ttf.reader
tags = reader.keys()
tags.sort()
tags = sorted(reader.keys())
print 'Listing table info for "%s":' % input
format = " %4s %10s %7s %7s"
print format % ("tag ", " checksum", " length", " offset")
@ -224,7 +223,7 @@ def ttCompile(input, output, options):
overflowRecord = e.value
print "Attempting to fix OTLOffsetOverflowError", e
lastItem = overflowRecord
while 1:
while True:
ok = 0
if overflowRecord.itemName == None:
ok = fixLookupOverFlows(ttf, overflowRecord)

View File

@ -46,7 +46,7 @@ def roundTrip(ttFile1, options, report):
diffcmd = 'diff -U2 -I ".*modified value\|checkSumAdjustment.*" "%s" "%s"' % (xmlFile1, xmlFile2)
output = os.popen(diffcmd, "r", 1)
lines = []
while 1:
while True:
line = output.readline()
if not line:
break