Skip to content

Commit

Permalink
First light on Python 3 port: 2to3 plus manual fixes
Browse files Browse the repository at this point in the history
 * _pluginfo module rework
 * bytes <--> unicode (mostly on IO)
 * no more 'cmp' arg to sorting
  • Loading branch information
bgribble committed Feb 6, 2017
1 parent e65ce92 commit c240a95
Show file tree
Hide file tree
Showing 89 changed files with 376 additions and 311 deletions.
4 changes: 2 additions & 2 deletions mfp/__init__.py
@@ -1,3 +1,3 @@

from bang import Bang, Uninit
from gui_main import MFPGUI
from .bang import Bang, Uninit
from .gui_main import MFPGUI
2 changes: 1 addition & 1 deletion mfp/bang.py
Expand Up @@ -29,7 +29,7 @@ def __div__(self, other):
def __pow__(self, other):
return self

def __nonzero__ (self):
def __bool__ (self):
return False

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions mfp/builtins/ampl.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
ampl.py: Detector (peak/rms)
Expand Down Expand Up @@ -28,7 +28,7 @@ def trigger(self):
for param, val in self.inlets[0].items():
try:
self.dsp_setparam(param, float(val))
except Exception, e:
except Exception as e:
import traceback
tb = traceback.format_exc()
log.debug("ampl~: Error setting param", param, "to", type(val), str(val))
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/arith.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
arith.py: Builtin arithmetic DSP ops
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/audio.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
audio.py: Builtin AudioOut/AudioIn DSP objects
Expand Down
4 changes: 2 additions & 2 deletions mfp/builtins/biquad.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
biquad.py: Biquad filter implementation
Expand Down Expand Up @@ -29,7 +29,7 @@ def trigger(self):
for param, val in self.inlets[0].items():
try:
self.dsp_setparam(param, float(val))
except Exception, e:
except Exception as e:
import traceback
tb = traceback.format_exc()
log.debug("biquad~: Error setting param", param, "to", type(val), str(val))
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/buffer.py
Expand Up @@ -127,7 +127,7 @@ def slice(self, start, end, channel=0):
os.lseek(self.shm_obj.fd, self.offset(channel, start), os.SEEK_SET)
slc = os.read(self.shm_obj.fd, (end - start) * self.FLOAT_SIZE)
self.outlets[1] = list(numpy.fromstring(slc, dtype=numpy.float32))
except Exception, e:
except Exception as e:
import traceback
tb = traceback.format_exc()
log.debug("buffer~: slice error '%s" % e)
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/delay.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
delay.py: Builtin delay DSP object
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/dispatch.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
dispatch.py: Method dispatch builtins for user patches
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/errtest.py
@@ -1,5 +1,5 @@

#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
errtest.py: Error test helper (not of use unless you want to crash MFP)
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/line.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
p_line.py: Builtin line/ramp generator
Expand Down
8 changes: 4 additions & 4 deletions mfp/builtins/listops.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
p_listops.py: Wrappers for common list operations
Expand Down Expand Up @@ -94,9 +94,9 @@ def __init__(self, init_type, init_args, patch, scope, name):

def trigger(self):
if len(self.inlets) == 1:
self.outlets[0] = zip(*self.inlets[0])
self.outlets[0] = list(zip(*self.inlets[0]))
else:
self.outlets[0] = zip(*self.inlets)
self.outlets[0] = list(zip(*self.inlets))

class Map (Processor):
doc_tooltip_obj = "Apply a function to each list element"
Expand All @@ -113,7 +113,7 @@ def __init__(self, init_type, init_args, patch, scope, name):


def trigger(self):
self.outlets[0] = map(self.inlets[1], self.inlets[0])
self.outlets[0] = list(map(self.inlets[1], self.inlets[0]))


class Slice (Processor):
Expand Down
4 changes: 2 additions & 2 deletions mfp/builtins/loop.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
loop.py: Builtin iteration constructs
Expand All @@ -14,7 +14,7 @@ def iterable(o):
try:
getattr(o, '__getitem__')
return True
except AttributeError, e:
except AttributeError as e:
return False

class For(Processor):
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/noise.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
p_noise.py: Builtin noise
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/osc.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
osc.py: Builtin oscillator DSP objects
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/phasor.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
phasor.py: Builtin phasor DSP object
Expand Down
4 changes: 2 additions & 2 deletions mfp/builtins/plot.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
plot.py: Stub for graphical plot I/O
Expand Down Expand Up @@ -83,7 +83,7 @@ def __init__(self, init_type, init_args, patch, scope, name):
channels = initargs[0]
else:
channels = 1
self.hot_inlets = range(channels)
self.hot_inlets = list(range(channels))
self.gui_params = dict(plot_type="scatter")

self.doc_tooltip_inlet = []
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/plugin.py
Expand Up @@ -33,7 +33,7 @@ def __init__(self, init_type, init_args, patch, scope, name):

Processor.__init__(self, self.plug_inlets, self.plug_outlets, init_type, init_args,
patch, scope, name)
self.hot_inlets = range(self.plug_inlets)
self.hot_inlets = list(range(self.plug_inlets))
self.dsp_init("ladspa~", lib_name=self.lib_name, lib_index=self.lib_index,
plug_control=self.plug_control)

Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/printformat.py
Expand Up @@ -35,7 +35,7 @@ def trigger(self):
elif '%' in self.format_string:
try:
out = self.format_string % self.inlets[0]
except TypeError, e:
except TypeError as e:
pass
if out is None:
if not self.format_string:
Expand Down
8 changes: 4 additions & 4 deletions mfp/builtins/pyfunc.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
p_pyfunc.py: Wrappers for common unary and binary Python functions
Expand All @@ -13,9 +13,9 @@

def get_arglist(thunk):
if hasattr(thunk, 'func_code'):
return thunk.func_code.co_varnames
return thunk.__code__.co_varnames
elif hasattr(thunk, '__func__'):
return thunk.__func__.func_code.co_varnames
return thunk.__func__.__code__.co_varnames
else:
return None

Expand Down Expand Up @@ -325,7 +325,7 @@ def register():
mk_binary(operator.add, "+", "Add")
mk_binary(operator.sub, "-", "Subtract")
mk_binary(operator.mul, "*", "Multiply")
mk_binary(operator.div, "/", "Divide")
mk_binary(operator.truediv, "/", "Divide")
mk_binary(operator.mod, "%", "Modulo")
mk_binary(operator.pow, "^", "Raise to a power")
mk_binary(operator.pow, "**", "Raise to a power")
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/radiogroup.py
Expand Up @@ -33,7 +33,7 @@ def __init__(self, init_type, init_args, patch, scope, name):

self.init_selection = init_selection
self.selection = None
self.hot_inlets = range(num_inlets)
self.hot_inlets = list(range(num_inlets))

self.doc_tooltip_inlet = []
self.doc_tooltip_outlet = []
Expand Down
3 changes: 2 additions & 1 deletion mfp/builtins/route.py
Expand Up @@ -102,7 +102,8 @@ def trigger(self):
else:
direct_addr = self.addresses.get(k)
type_addr = None
type_matches = [self.type_addresses.get(t) for t in self.type_addresses.keys()
type_matches = [self.type_addresses.get(t)
for t in self.type_addresses.keys()
if isinstance(k, t)]
if type_matches:
type_addr = min(type_matches)
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/sig.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
p_sig.py: Builtin constant signal
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/snap.py
Expand Up @@ -48,7 +48,7 @@ def trigger(self):
for param, val in self.inlets[1].items():
try:
self.dsp_setparam(param, float(val))
except Exception, e:
except Exception as e:
import traceback
tb = traceback.format_exc()
log.debug("snap~: Error setting param", param, "to", type(val), str(val))
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/trigger.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
trigger.py: Repeat input on multiple outputs
Expand Down
2 changes: 1 addition & 1 deletion mfp/builtins/var.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
var.py: Variable holder
Expand Down
2 changes: 1 addition & 1 deletion mfp/dsp_object.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
dsp_slave.py
Python main loop for DSP subprocess
Expand Down
8 changes: 4 additions & 4 deletions mfp/evaluator.py
@@ -1,12 +1,12 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
evaluator.py: Augmented Python eval for strings in user interface
Copyright (c) 2011 Bill Gribble <grib@billgribble.com>
'''

import tokenize
from StringIO import StringIO
from io import StringIO

class LazyExpr(object):
def __init__(self, thunk):
Expand Down Expand Up @@ -87,8 +87,8 @@ def lazyrecurse(evalstr):


environ = { name: val
for name, val in (self.global_names.items() + self.local_names.items()
+ extra_bindings.items())
for name, val in (list(self.global_names.items()) + list(self.local_names.items())
+ list(extra_bindings.items()))
}
if "__self__" in environ:
environ["self"] = environ["__self__"]
Expand Down
2 changes: 1 addition & 1 deletion mfp/gui/button_element.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
button_element.py
A patch element corresponding to a "bang" or "toggle" style button
Expand Down
4 changes: 2 additions & 2 deletions mfp/gui/colordb.py
Expand Up @@ -37,7 +37,7 @@ def find(self, *colorinfo):
elif ll == 3:
key = (int(colorinfo[0]), int(colorinfo[1]), int(colorinfo[2]), 255)

if not self.rgba_colors.has_key(key):
if key not in self.rgba_colors:
nc = Clutter.Color.new(*key)
self.rgba_colors[key] = nc
else:
Expand All @@ -62,7 +62,7 @@ def find_cairo(self, *colorinfo):
if tmp is not None:
rv = RGBAColor(tmp.red / 255.0, tmp.green / 255.0, tmp.blue/255.0, tmp.alpha/255.0)
else:
print "ColorDB(): did not find color", colorinfo
print("ColorDB(): did not find color", colorinfo)
rv = RGBAColor(0, 0, 0, 255)
return rv

Expand Down
4 changes: 2 additions & 2 deletions mfp/gui/connection_element.py
Expand Up @@ -37,8 +37,8 @@ def __init__(self, window, obj_1, port_1, obj_2, port_2, dashed=False):
elif obj_2.layer is not None:
self.move_to_layer(obj_2.layer)
else:
print "WARNING: creating ConnectionElement with no layer"
print obj_1, obj_2
print("WARNING: creating ConnectionElement with no layer")
print(obj_1, obj_2)

self.draw()

Expand Down
4 changes: 2 additions & 2 deletions mfp/gui/enum_element.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
enum_element.py
A patch element corresponding to a number box or enum selector
Expand Down Expand Up @@ -124,7 +124,7 @@ def create_obj(self):
if self.obj_id is None:
self.create(self.proc_type, str(self.value))
if self.obj_id is None:
print "MessageElement: could not create message obj"
print("MessageElement: could not create message obj")
else:
MFPGUI().mfp.set_do_onload(self.obj_id, True)
self.obj_state = self.OBJ_COMPLETE
Expand Down
16 changes: 8 additions & 8 deletions mfp/gui/input_manager.py
@@ -1,4 +1,4 @@
#! /usr/bin/env python2.6
#! /usr/bin/env python
'''
input_manager.py: Handle keyboard and mouse input and route through input modes
Expand All @@ -8,8 +8,8 @@
from datetime import datetime, timedelta
import time

from input_mode import InputMode
from key_sequencer import KeySequencer
from .input_mode import InputMode
from .key_sequencer import KeySequencer
from ..utils import QuittableThread
from ..gui_main import MFPGUI
from mfp import log
Expand Down Expand Up @@ -63,8 +63,8 @@ def set_major_mode(self, mode):
self.window.display_bindings()

def enable_minor_mode(self, mode):
def modecmp(a, b):
return cmp(b.affinity, a.affinity) or cmp(b.seqno, a.seqno)
def modekey(a):
return -a.affinity, -a.seqno

do_enable = True
if mode in self.minor_modes:
Expand All @@ -74,7 +74,7 @@ def modecmp(a, b):
mode.seqno = self.minor_seqno
self.minor_seqno += 1
self.minor_modes[:0] = [mode]
self.minor_modes.sort(cmp=modecmp)
self.minor_modes.sort(key=modekey)
self.window.display_bindings()

if do_enable:
Expand Down Expand Up @@ -170,12 +170,12 @@ def handle_event(self, stage, event):
try:
retry_count += 1
rv = self.handle_keysym(keysym)
except self.InputNeedsRequeue, e:
except self.InputNeedsRequeue as e:
if retry_count < 5:
continue
else:
return False
except Exception, e:
except Exception as e:
log.error("Exception while handling key command", keysym)
log.debug(e)
log.debug_traceback()
Expand Down

0 comments on commit c240a95

Please sign in to comment.