Skip to content

Commit 2898934

Browse files
committed
audit 2to3 pass
1 parent 8c145d9 commit 2898934

16 files changed

Lines changed: 362 additions & 374 deletions

File tree

plotdevice/gfx/atoms.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def _set_strokewidth(self, strokewidth):
296296
def _get_capstyle(self):
297297
return self._penstyle.cap
298298
def _set_capstyle(self, style):
299-
from bezier import BUTT, ROUND, SQUARE
299+
from .bezier import BUTT, ROUND, SQUARE
300300
if style not in (BUTT, ROUND, SQUARE):
301301
badstyle = 'Line cap style should be BUTT, ROUND or SQUARE.'
302302
raise DeviceError(badstyle)
@@ -306,7 +306,7 @@ def _set_capstyle(self, style):
306306
def _get_joinstyle(self):
307307
return self._penstyle.join
308308
def _set_joinstyle(self, style):
309-
from bezier import MITER, ROUND, BEVEL
309+
from .bezier import MITER, ROUND, BEVEL
310310
if style not in (MITER, ROUND, BEVEL):
311311
badstyle = 'Line join style should be MITER, ROUND or BEVEL.'
312312
raise DeviceError(badstyle)
@@ -319,7 +319,7 @@ def _set_dashstyle(self, *segments):
319319
if None in segments:
320320
steps = None
321321
else:
322-
steps = map(int, _flatten(segments))
322+
steps = list(map(int, _flatten(segments)))
323323
if len(steps)%2:
324324
steps += steps[-1:] # assume even spacing for omitted skip sizes
325325
self._penstyle = self._penstyle._replace(dash=steps)
@@ -421,13 +421,9 @@ def sanitize(self, val):
421421
except ValueError:
422422
return 0.0
423423
elif self.type == TEXT:
424-
return unicode(str(val), "utf_8", "replace")
425-
try:
426-
return unicode(str(val), "utf_8", "replace")
427-
except:
428-
return ""
424+
return str(val)
429425
elif self.type == BOOLEAN:
430-
if unicode(val).lower() in ("true", "1", "yes"):
426+
if str(val).lower() in ("true", "1", "yes"):
431427
return True
432428
else:
433429
return False

plotdevice/gfx/geometry.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ def __ne__(self, other):
6565
return not self.__eq__(other)
6666

6767
@paired
68-
def __abs__(self): return map(abs, self)
68+
def __abs__(self): return list(map(abs, self))
6969
@paired
7070
def __pos__(self): return self
7171
@paired
72-
def __neg__(self): return map(neg, self)
72+
def __neg__(self): return list(map(neg, self))
7373
@paired
74-
def __add__(self, other): return map(sum, zip(self, other))
74+
def __add__(self, other): return list(map(sum, list(zip(self, other))))
7575
@paired
76-
def __radd__(self, other): return map(sum, zip(self, other))
76+
def __radd__(self, other): return list(map(sum, list(zip(self, other))))
7777
@paired
78-
def __sub__(self, other): return map(sum, zip(self, -other))
78+
def __sub__(self, other): return list(map(sum, list(zip(self, -other))))
7979
@paired
80-
def __rsub__(self, other): return map(sum, zip(other, -self))
80+
def __rsub__(self, other): return list(map(sum, list(zip(other, -self))))
8181
@paired
8282
def __mul__(self, other): return [a * b for a,b in zip(self, other)]
8383
@paired
@@ -427,7 +427,6 @@ def parse_coords(coords, types):
427427
class MagicNumber(object):
428428
# be a well-behaved pseudo-number (based on the float in self.value)
429429
def __int__(self): return int(self.value)
430-
def __long__(self): return long(self.value)
431430
def __float__(self): return float(self.value)
432431
def __cmp__(self, n): return cmp(self.value, n)
433432

plotdevice/gfx/text.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def append(self, txt=None, **kwargs):
118118
# try using the nsmagic parsing of HTML/RTF to build an attributed string
119119
if not is_xml:
120120
txt_bytes = txt.encode('utf-8')
121-
txt_opts = {u'CharacterEncoding': NSUTF8StringEncoding}
121+
txt_opts = {'CharacterEncoding': NSUTF8StringEncoding}
122122
decoded, info, err = NSMutableAttributedString.alloc().initWithData_options_documentAttributes_error_(
123123
NSData.dataWithBytes_length_(txt_bytes, len(txt_bytes)), txt_opts, None, None
124124
)
@@ -276,7 +276,7 @@ def _dedent(cls, attrib_txt, idx=0, inherit=False):
276276
def overleaf(self):
277277
"""Returns a Text object containing any characters that did not fit within this object's bounds.
278278
If the entire string fits within the current object, returns None."""
279-
seen = u"".join(getattr(f, 'text') for f in self._blocks)
279+
seen = "".join(getattr(f, 'text') for f in self._blocks)
280280
full = self.text
281281
if full not in seen:
282282
next_pg = self.copy()
@@ -680,7 +680,7 @@ def groups(self, default=None):
680680
but returns TextFragment objects rather than character strings
681681
"""
682682
self._is_regex('groups')
683-
indices = range(1,len(self.m.regs))
683+
indices = list(range(1, len(self.m.regs)))
684684
if not indices:
685685
return ()
686686
return tuple(m if m else default for m in self.group(*indices))

plotdevice/gfx/typography.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __repr__(self):
6868
spec.insert(2, self._face.variant)
6969
spec.insert(1, '/' if self._face.italic else '|')
7070
spec.insert(1, ("%.1fpt"%self._metrics['size']).replace('.0pt','pt'))
71-
return (u'Font(%s)'%" ".join(spec)).encode('utf-8')
71+
return ('Font(%s)'%" ".join(spec)).encode('utf-8')
7272

7373
def __enter__(self):
7474
if not hasattr(self, '_rollback'):
@@ -249,7 +249,7 @@ def __repr__(self):
249249
n = len(getattr(self, group))
250250
if n:
251251
contents.append('%i %s%s' % (n, group[:-1], '' if n==1 else 's'))
252-
return (u'Family(%s)'%", ".join(contents)).encode('utf-8')
252+
return ('Family(%s)'%", ".join(contents)).encode('utf-8')
253253

254254
@property
255255
def name(self):
@@ -285,7 +285,7 @@ def variants(self):
285285
if f.variant not in v_names:
286286
v_names.append(f.variant)
287287
if any(v_names) and None in v_names:
288-
return tuple([None] + filter(None,v_names))
288+
return tuple(None, *filter(None, v_names))
289289
return tuple(v_names)
290290

291291
@property
@@ -371,7 +371,7 @@ def style(self, name, *args, **kwargs):
371371
spec.update(fontspec(*args, **kwargs))
372372
color = kwargs.get('fill')
373373
if color and not isinstance(color, Color):
374-
if isinstance(color, (str, int, float, long)):
374+
if isinstance(color, (str, int, float)):
375375
color = (color,)
376376
color = Color(*color)
377377
if color:

plotdevice/gui/editor.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def draggingEntered_(self, sender):
2828
NSPasteboardURLReadingContentsConformToTypesKey:NSImage.imageTypes() }
2929
urls = pb.readObjectsForClasses_options_([NSURL], options)
3030
strs = pb.readObjectsForClasses_options_([NSString], {})
31-
rewrite = u"\n".join([u'"%s"'%u.path() for u in urls] + strs) + u"\n"
31+
rewrite = "\n".join(['"%s"'%u.path() for u in urls] + strs) + "\n"
3232
pb.declareTypes_owner_([NSStringPboardType], self)
3333
pb.setString_forType_(rewrite, NSStringPboardType)
3434
return super(DraggyWebView, self).draggingEntered_(sender)
@@ -123,9 +123,9 @@ def webView_didClearWindowObject_forFrame_(self, sender, win, frame):
123123

124124
def webView_contextMenuItemsForElement_defaultMenuItems_(self, sender, elt, menu):
125125
items = [
126-
NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(u"Cut", "cut:", ""),
127-
NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(u"Copy", "copy:", ""),
128-
NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(u"Paste", "paste:", ""),
126+
NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Cut", "cut:", ""),
127+
NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Copy", "copy:", ""),
128+
NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Paste", "paste:", ""),
129129
NSMenuItem.separatorItem(),
130130
]
131131

@@ -188,7 +188,7 @@ def _get_source(self):
188188
return self.webview.stringByEvaluatingJavaScriptFromString_('editor.source();')
189189
@objc.python_method
190190
def _set_source(self, src):
191-
self.js(u'editor.source', args(src))
191+
self.js('editor.source', args(src))
192192
source = property(_get_source, _set_source)
193193

194194
def fontChanged(self, note=None):
@@ -417,8 +417,8 @@ def changeColor_(self, clr):
417417
@objc.python_method
418418
def append(self, txt, stream='message'):
419419
if not txt: return
420-
defer_endl = txt.endswith(u'\n')
421-
txt = (u"\n" if self.endl else u"") + (txt[:-1 if defer_endl else None])
420+
defer_endl = txt.endswith('\n')
421+
txt = ("\n" if self.endl else "") + (txt[:-1 if defer_endl else None])
422422
atxt = NSAttributedString.alloc().initWithString_attributes_(txt, self._attrs(stream))
423423
self.ts.beginEditing()
424424
self.ts.appendAttributedString_(atxt)

plotdevice/gui/widgets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def beginExport(self):
4848
def updateExport_total_(self, written, total):
4949
self.spinner.setMaxValue_(total)
5050
self.spinner.setDoubleValue_(written)
51-
msg = "Frame %i/%i"%(written, total) if written<total else u"Finishing…"
51+
msg = "Frame %i/%i"%(written, total) if written<total else "Finishing…"
5252
self.counter.setStringValue_(msg)
5353

5454
def finishExport(self):
@@ -305,7 +305,7 @@ def beginExport(self, kind):
305305
exportPanel.setPrompt_("Export")
306306
exportPanel.setCanSelectHiddenExtension_(True)
307307
exportPanel.setShowsTagField_(False)
308-
exportPanel.setAllowedFileTypes_(filter(None, self.formats[kind]))
308+
exportPanel.setAllowedFileTypes_(list(filter(None, self.formats[kind])))
309309
exportPanel.setRequiredFileType_(format)
310310
exportPanel.setAccessoryView_(accessory)
311311

plotdevice/lib/foundry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import difflib
77
from operator import itemgetter, attrgetter
88
from collections import namedtuple, OrderedDict as odict, defaultdict as ddict
9-
from cocoa import *
9+
from .cocoa import *
1010
from ..util import numlike
1111
import cFoundry
1212

@@ -447,7 +447,7 @@ def standardized(axis, val):
447447
def parse_display_name(dname):
448448
"""Try to extract style attributes from the font's display name"""
449449
# break the string on spaces and on lc/uc transitions
450-
elts = list(filter(None, re.sub(r'(?<=[^ ])([A-Z][a-z]+)',r' \1',dname).split(' ')))
450+
elts = list([s for s in re.sub(r'(?<=[^ ])([A-Z][a-z]+)',r' \1',dname).split(' ') if s])
451451

452452
# disregard the first italic-y word in the name (if any)
453453
for i in range(len(elts)-1,-1,-1):
@@ -677,8 +677,8 @@ def list_fam(self, famname, names=False):
677677

678678

679679
# if something that looks like a weight pops up as a variant in a face, wipe it out
680-
seen_weights = filter(None, set(f.weight for f in fam))
681-
seen_vars = filter(None, set(f.variant for f in fam))
680+
seen_weights = [w for w in set(f.weight for f in fam) if w]
681+
seen_vars = [v for v in set(f.variant for f in fam) if v]
682682
iffy_vars = [v for v in seen_vars if v in seen_weights]
683683
for i,f in enumerate(fam):
684684
if f.variant in iffy_vars:

plotdevice/lib/pathmatics.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import objc
22
from collections import namedtuple
3-
from cocoa import CGPathRelease
3+
from .cocoa import CGPathRelease
44
import cPathmatics
55

66

@@ -215,7 +215,7 @@ def segment_lengths(path, relative=False, n=20):
215215
if relative:
216216
length = sum(lengths)
217217
try:
218-
return map(lambda l: l / length, lengths)
218+
return [l / length for l in lengths]
219219
except ZeroDivisionError: # If the length is zero, just return zero for all segments
220220
return [0.0] * len(lengths)
221221
else:
@@ -406,7 +406,7 @@ def points(path, amount=100):
406406
except ZeroDivisionError:
407407
delta = 1.0
408408

409-
for i in xrange(amount):
409+
for i in range(amount):
410410
yield point(path, delta*i)
411411

412412
def contours(path):
@@ -524,9 +524,7 @@ def findpath(points, curvature=1.0):
524524
ax[i] = -(points[i+1].x-points[i-1].x-ax[i-1]) * bi[i]
525525
ay[i] = -(points[i+1].y-points[i-1].y-ay[i-1]) * bi[i]
526526

527-
r = range(1, len(points)-1)
528-
r.reverse()
529-
for i in r:
527+
for i in reversed(range(1, len(points)-1)):
530528
dx[i] = ax[i] + dx[i+1] * bi[i]
531529
dy[i] = ay[i] + dy[i+1] * bi[i]
532530

plotdevice/run/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
objc_dir = abspath(join(dirname(__file__), '../../build/lib/plotdevice/lib/PyObjC'))
1111

1212
# add our embedded PyObjC site-dir to the sys.path (and remove any conflicts)
13-
map(sys.path.remove, filter(lambda p:p.endswith('PyObjC'), sys.path))
13+
for pyobjc_pth in [p for p in sys.path if p.endswith('PyObjC')]:
14+
sys.path.remove(pyobjc_pth)
1415
site.addsitedir(objc_dir)
1516

1617
# test the sys.path by attempting to load a PyObjC submodule

plotdevice/run/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def stacktrace(script=None, src=None):
5050
# we only want to prepend the Traceback text for syntax errs
5151
if 'SyntaxError' not in msg: return msg
5252

53-
return u"Traceback (most recent call last):\n%s" % msg
53+
return "Traceback (most recent call last):\n%s" % msg
5454

5555
def coredump(script=None, src=None, syntax=True):
5656
"""Get a clean stacktrace with absolute paths and source pulled from the editor rather than disk"""

0 commit comments

Comments
 (0)