ref: 4041a6da578929d7b5d8b65231b3c19e08905e83
parent: 7c785e6842c286b9c65e4fee8b755cfeeaefcda9
parent: b8ed85e444b521e59423f5552ad420d03d183060
author: Paul Brossier <piem@piem.org>
date: Mon Apr 18 18:48:53 EDT 2016
Merge pull request #40 from nphilipp/develop--py3k-fixes Miscellaneous fixes for Python, mostly version 3
--- a/python/VERSION
+++ b/python/VERSION
@@ -1,7 +1,7 @@
AUBIO_MAJOR_VERSION=0
AUBIO_MINOR_VERSION=4
AUBIO_PATCH_VERSION=2
-AUBIO_VERSION_STATUS='~alpha'
+AUBIO_VERSION_STATUS='a0'
LIBAUBIO_LT_CUR=4
LIBAUBIO_LT_REV=1
LIBAUBIO_LT_AGE=1
--- a/python/ext/aubio-types.h
+++ b/python/ext/aubio-types.h
@@ -39,6 +39,11 @@
#define AUBIO_NPY_SMPL NPY_FLOAT
#endif
+// compat with Python < 2.6
+#ifndef Py_TYPE
+#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
+#endif
+
// special python type for cvec
typedef struct
{
--- a/python/ext/aubiowraphell.h
+++ b/python/ext/aubiowraphell.h
@@ -13,7 +13,7 @@
{ \
self->o = new_aubio_## NAME ( PARAMS ); \
if (self->o == NULL) { \
- PyErr_SetString (PyExc_StandardError, "error creating object"); \
+ PyErr_SetString (PyExc_RuntimeError, "error creating object"); \
return -1; \
} \
\
@@ -25,7 +25,7 @@
Py_ ## NAME ## _del ( Py_ ## NAME * self) \
{ \
del_aubio_ ## NAME (self->o); \
- self->ob_type->tp_free ((PyObject *) self); \
+ Py_TYPE(self)->tp_free ((PyObject *) self); \
}
#define AUBIO_MEMBERS_START(NAME) \
--- a/python/ext/py-cvec.c
+++ b/python/ext/py-cvec.c
@@ -59,7 +59,7 @@
Py_cvec_del (Py_cvec * self)
{
del_cvec (self->o);
- self->ob_type->tp_free ((PyObject *) self);
+ Py_TYPE(self)->tp_free ((PyObject *) self);
}
static PyObject *
--- a/python/ext/py-filter.c
+++ b/python/ext/py-filter.c
@@ -57,7 +57,7 @@
{
del_fvec(self->out);
del_aubio_filter (self->o);
- self->ob_type->tp_free ((PyObject *) self);
+ Py_TYPE(self)->tp_free ((PyObject *) self);
}
static PyObject *
--- a/python/ext/py-sink.c
+++ b/python/ext/py-sink.c
@@ -115,7 +115,7 @@
aubio_sink_preset_samplerate ( self->o, self->samplerate );
}
if (self->o == NULL) {
- PyErr_SetString (PyExc_StandardError, "error creating sink with this uri");
+ PyErr_SetString (PyExc_RuntimeError, "error creating sink with this uri");
return -1;
}
self->samplerate = aubio_sink_get_samplerate ( self->o );
--- a/python/ext/py-source.c
+++ b/python/ext/py-source.c
@@ -139,7 +139,7 @@
if (self->o == NULL) {
char_t errstr[30 + strlen(self->uri)];
sprintf(errstr, "error creating source with %s", self->uri);
- PyErr_SetString (PyExc_StandardError, errstr);
+ PyErr_SetString (PyExc_RuntimeError, errstr);
return -1;
}
self->samplerate = aubio_source_get_samplerate ( self->o );
--- a/python/lib/aubio/midiconv.py
+++ b/python/lib/aubio/midiconv.py
@@ -6,9 +6,11 @@
_valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, 'b': -1, u'♭': -1, u'\ufffd': -2}
_valid_octaves = range(-1, 10)
if type(note) not in (str, unicode):
- raise TypeError, "a string is required, got %s" % note
+ raise TypeError("a string is required, got %s" % note)
if not (1 < len(note) < 5):
- raise ValueError, "string of 2 to 4 characters expected, got %d (%s)" % (len(note), note)
+ raise ValueError(
+ "string of 2 to 4 characters expected, got %d (%s)" %
+ (len(note), note))
notename, modifier, octave = [None]*3
if len(note) == 4:
@@ -26,23 +28,24 @@
octave = int(octave)
if notename not in _valid_notenames:
- raise ValueError, "%s is not a valid note name" % notename
+ raise ValueError("%s is not a valid note name" % notename)
if modifier not in _valid_modifiers:
- raise ValueError, "%s is not a valid modifier" % modifier
+ raise ValueError("%s is not a valid modifier" % modifier)
if octave not in _valid_octaves:
- raise ValueError, "%s is not a valid octave" % octave
+ raise ValueError("%s is not a valid octave" % octave)
midi = 12 + octave * 12 + _valid_notenames[notename] + _valid_modifiers[modifier]
if midi > 127:
- raise ValueError, "%s is outside of the range C-2 to G8" % note
+ raise ValueError("%s is outside of the range C-2 to G8" % note)
return midi
def midi2note(midi):
" convert midi note number to note name, e.g. [0, 127] -> [C-1, G9] "
if type(midi) != int:
- raise TypeError, "an integer is required, got %s" % midi
+ raise TypeError("an integer is required, got %s" % midi)
if not (-1 < midi < 128):
- raise ValueError, "an integer between 0 and 127 is excepted, got %d" % midi
+ raise ValueError(
+ "an integer between 0 and 127 is excepted, got %d" % midi)
midi = int(midi)
_valid_notenames = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
return _valid_notenames[midi % 12] + str( midi / 12 - 1)
--- a/python/lib/gen_pyobject.py
+++ b/python/lib/gen_pyobject.py
@@ -70,7 +70,7 @@
example: proto = "int main (int argc, char ** argv)"
returns: [['int', 'argc'], ['char **','argv']]
"""
- return map(split_type, get_params(proto))
+ return list(map(split_type, get_params(proto)))
def get_return_type(proto):
import re
--- a/python/lib/generator.py
+++ b/python/lib/generator.py
@@ -3,7 +3,7 @@
""" This file generates a c file from a list of cpp prototypes. """
import os, sys, shutil
-from gen_pyobject import write_msg, gen_new_init, gen_do, gen_members, gen_methods, gen_finish
+from .gen_pyobject import write_msg, gen_new_init, gen_do, gen_members, gen_methods, gen_finish
def get_cpp_objects():
@@ -11,6 +11,7 @@
cpp_output = filter(lambda y: len(y) > 1, cpp_output)
cpp_output = filter(lambda y: not y.startswith('#'), cpp_output)
+ cpp_output = list(cpp_output)
i = 1
while 1:
@@ -85,9 +86,11 @@
object_methods = filter(lambda x: this_object in x, cpp_output)
object_methods = [a.strip() for a in object_methods]
object_methods = filter(lambda x: not x.startswith('typedef'), object_methods)
+ object_methods = list(object_methods)
#for method in object_methods:
# write_msg(method)
- new_methods = filter(lambda x: 'new_'+object_name in x, object_methods)
+ new_methods = list(filter(
+ lambda x: 'new_'+object_name in x, object_methods))
if len(new_methods) > 1:
write_msg("-- WARNING: more than one new method for", object_name)
for method in new_methods:
@@ -98,7 +101,8 @@
for method in new_methods:
write_msg(method)
- del_methods = filter(lambda x: 'del_'+object_name in x, object_methods)
+ del_methods = list(filter(
+ lambda x: 'del_'+object_name in x, object_methods))
if len(del_methods) > 1:
write_msg("-- WARNING: more than one del method for", object_name)
for method in del_methods:
@@ -106,7 +110,8 @@
elif len(del_methods) < 1:
write_msg("-- WARNING: no del method for", object_name)
- do_methods = filter(lambda x: object_name+'_do' in x, object_methods)
+ do_methods = list(filter(
+ lambda x: object_name+'_do' in x, object_methods))
if len(do_methods) > 1:
pass
#write_msg("-- WARNING: more than one do method for", object_name)
@@ -135,6 +140,7 @@
other_methods = filter(lambda x: x not in do_methods, other_methods)
other_methods = filter(lambda x: x not in get_methods, other_methods)
other_methods = filter(lambda x: x not in set_methods, other_methods)
+ other_methods = list(other_methods)
if len(other_methods) > 0:
write_msg("-- WARNING: some methods for", object_name, "were unidentified")