Miscellaneous fixes for Python, mostly version 3
Showing the changes to python (10 of 10 files). Show all
Unified · Split
| @@ -1,7 +1,7 @@ | |||
| 1 | AUBIO_MAJOR_VERSION=0 | 1 | AUBIO_MAJOR_VERSION=0 |
| 2 | AUBIO_MINOR_VERSION=4 | 2 | AUBIO_MINOR_VERSION=4 |
| 3 | AUBIO_PATCH_VERSION=2 | 3 | AUBIO_PATCH_VERSION=2 |
| 4 | AUBIO_VERSION_STATUS='~alpha' | 4 | AUBIO_VERSION_STATUS='a0' |
| 5 | LIBAUBIO_LT_CUR=4 | 5 | LIBAUBIO_LT_CUR=4 |
| 6 | LIBAUBIO_LT_REV=1 | 6 | LIBAUBIO_LT_REV=1 |
| 7 | LIBAUBIO_LT_AGE=1 | 7 | LIBAUBIO_LT_AGE=1 |
| @@ -39,6 +39,11 @@ · 38 unmodified lines | |||
| 39 | #define AUBIO_NPY_SMPL NPY_FLOAT | 39 | #define AUBIO_NPY_SMPL NPY_FLOAT |
| 40 | #endif | 40 | #endif |
| 41 | 41 | ||
| 42 | // compat with Python < 2.6 | ||
| 43 | #ifndef Py_TYPE | ||
| 44 | #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) | ||
| 45 | #endif | ||
| 46 | |||
| 42 | // special python type for cvec | 47 | // special python type for cvec |
| 43 | typedef struct | 48 | typedef struct |
| 44 | { | 49 | { |
| @@ -13,7 +13,7 @@ Py_ ## NAME ## _init (Py_ ## NAME * self, PyObject * args, PyObject * kwds) \ · 12 unmodified lines | |||
| 13 | { \ | 13 | { \ |
| 14 | self->o = new_aubio_## NAME ( PARAMS ); \ | 14 | self->o = new_aubio_## NAME ( PARAMS ); \ |
| 15 | if (self->o == NULL) { \ | 15 | if (self->o == NULL) { \ |
| 16 | PyErr_SetString (PyExc_StandardError, "error creating object"); \ | 16 | PyErr_SetString (PyExc_RuntimeError, "error creating object"); \ |
| 17 | return -1; \ | 17 | return -1; \ |
| 18 | } \ | 18 | } \ |
| 19 | \ | 19 | \ |
| @@ -25,7 +25,7 @@ static void \ · 5 unmodified lines | |||
| 25 | Py_ ## NAME ## _del ( Py_ ## NAME * self) \ | 25 | Py_ ## NAME ## _del ( Py_ ## NAME * self) \ |
| 26 | { \ | 26 | { \ |
| 27 | del_aubio_ ## NAME (self->o); \ | 27 | del_aubio_ ## NAME (self->o); \ |
| 28 | self->ob_type->tp_free ((PyObject *) self); \ | 28 | Py_TYPE(self)->tp_free ((PyObject *) self); \ |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | #define AUBIO_MEMBERS_START(NAME) \ | 31 | #define AUBIO_MEMBERS_START(NAME) \ |
| @@ -59,7 +59,7 @@ static void · 58 unmodified lines | |||
| 59 | Py_cvec_del (Py_cvec * self) | 59 | Py_cvec_del (Py_cvec * self) |
| 60 | { | 60 | { |
| 61 | del_cvec (self->o); | 61 | del_cvec (self->o); |
| 62 | self->ob_type->tp_free ((PyObject *) self); | 62 | Py_TYPE(self)->tp_free ((PyObject *) self); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | static PyObject * | 65 | static PyObject * |
| @@ -57,7 +57,7 @@ Py_filter_del (Py_filter * self) · 56 unmodified lines | |||
| 57 | { | 57 | { |
| 58 | del_fvec(self->out); | 58 | del_fvec(self->out); |
| 59 | del_aubio_filter (self->o); | 59 | del_aubio_filter (self->o); |
| 60 | self->ob_type->tp_free ((PyObject *) self); | 60 | Py_TYPE(self)->tp_free ((PyObject *) self); |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | static PyObject * | 63 | static PyObject * |
| @@ -115,7 +115,7 @@ Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds) · 114 unmodified lines | |||
| 115 | aubio_sink_preset_samplerate ( self->o, self->samplerate ); | 115 | aubio_sink_preset_samplerate ( self->o, self->samplerate ); |
| 116 | } | 116 | } |
| 117 | if (self->o == NULL) { | 117 | if (self->o == NULL) { |
| 118 | PyErr_SetString (PyExc_StandardError, "error creating sink with this uri"); | 118 | PyErr_SetString (PyExc_RuntimeError, "error creating sink with this uri"); |
| 119 | return -1; | 119 | return -1; |
| 120 | } | 120 | } |
| 121 | self->samplerate = aubio_sink_get_samplerate ( self->o ); | 121 | self->samplerate = aubio_sink_get_samplerate ( self->o ); |
| @@ -139,7 +139,7 @@ Py_source_init (Py_source * self, PyObject * args, PyObject * kwds) · 138 unmodified lines | |||
| 139 | if (self->o == NULL) { | 139 | if (self->o == NULL) { |
| 140 | char_t errstr[30 + strlen(self->uri)]; | 140 | char_t errstr[30 + strlen(self->uri)]; |
| 141 | sprintf(errstr, "error creating source with %s", self->uri); | 141 | sprintf(errstr, "error creating source with %s", self->uri); |
| 142 | PyErr_SetString (PyExc_StandardError, errstr); | 142 | PyErr_SetString (PyExc_RuntimeError, errstr); |
| 143 | return -1; | 143 | return -1; |
| 144 | } | 144 | } |
| 145 | self->samplerate = aubio_source_get_samplerate ( self->o ); | 145 | self->samplerate = aubio_source_get_samplerate ( self->o ); |
| @@ -6,9 +6,11 @@ def note2midi(note): · 5 unmodified lines | |||
| 6 | _valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, 'b': -1, u'♭': -1, u'\ufffd': -2} | 6 | _valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, 'b': -1, u'♭': -1, u'\ufffd': -2} |
| 7 | _valid_octaves = range(-1, 10) | 7 | _valid_octaves = range(-1, 10) |
| 8 | if type(note) not in (str, unicode): | 8 | if type(note) not in (str, unicode): |
| 9 | raise TypeError, "a string is required, got %s" % note | 9 | raise TypeError("a string is required, got %s" % note) |
| 10 | if not (1 < len(note) < 5): | 10 | if not (1 < len(note) < 5): |
| 11 | raise ValueError, "string of 2 to 4 characters expected, got %d (%s)" % (len(note), note) | 11 | raise ValueError( |
| 12 | "string of 2 to 4 characters expected, got %d (%s)" % | ||
| 13 | (len(note), note)) | ||
| 12 | notename, modifier, octave = [None]*3 | 14 | notename, modifier, octave = [None]*3 |
| 13 | 15 | ||
| 14 | if len(note) == 4: | 16 | if len(note) == 4: |
| @@ -26,23 +28,24 @@ def note2midi(note): · 11 unmodified lines | |||
| 26 | octave = int(octave) | 28 | octave = int(octave) |
| 27 | 29 | ||
| 28 | if notename not in _valid_notenames: | 30 | if notename not in _valid_notenames: |
| 29 | raise ValueError, "%s is not a valid note name" % notename | 31 | raise ValueError("%s is not a valid note name" % notename) |
| 30 | if modifier not in _valid_modifiers: | 32 | if modifier not in _valid_modifiers: |
| 31 | raise ValueError, "%s is not a valid modifier" % modifier | 33 | raise ValueError("%s is not a valid modifier" % modifier) |
| 32 | if octave not in _valid_octaves: | 34 | if octave not in _valid_octaves: |
| 33 | raise ValueError, "%s is not a valid octave" % octave | 35 | raise ValueError("%s is not a valid octave" % octave) |
| 34 | 36 | ||
| 35 | midi = 12 + octave * 12 + _valid_notenames[notename] + _valid_modifiers[modifier] | 37 | midi = 12 + octave * 12 + _valid_notenames[notename] + _valid_modifiers[modifier] |
| 36 | if midi > 127: | 38 | if midi > 127: |
| 37 | raise ValueError, "%s is outside of the range C-2 to G8" % note | 39 | raise ValueError("%s is outside of the range C-2 to G8" % note) |
| 38 | return midi | 40 | return midi |
| 39 | 41 | ||
| 40 | def midi2note(midi): | 42 | def midi2note(midi): |
| 41 | " convert midi note number to note name, e.g. [0, 127] -> [C-1, G9] " | 43 | " convert midi note number to note name, e.g. [0, 127] -> [C-1, G9] " |
| 42 | if type(midi) != int: | 44 | if type(midi) != int: |
| 43 | raise TypeError, "an integer is required, got %s" % midi | 45 | raise TypeError("an integer is required, got %s" % midi) |
| 44 | if not (-1 < midi < 128): | 46 | if not (-1 < midi < 128): |
| 45 | raise ValueError, "an integer between 0 and 127 is excepted, got %d" % midi | 47 | raise ValueError( |
| 48 | "an integer between 0 and 127 is excepted, got %d" % midi) | ||
| 46 | midi = int(midi) | 49 | midi = int(midi) |
| 47 | _valid_notenames = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'] | 50 | _valid_notenames = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'] |
| 48 | return _valid_notenames[midi % 12] + str( midi / 12 - 1) | 51 | return _valid_notenames[midi % 12] + str( midi / 12 - 1) |
| @@ -70,7 +70,7 @@ def get_params_types_names(proto): · 69 unmodified lines | |||
| 70 | example: proto = "int main (int argc, char ** argv)" | 70 | example: proto = "int main (int argc, char ** argv)" |
| 71 | returns: [['int', 'argc'], ['char **','argv']] | 71 | returns: [['int', 'argc'], ['char **','argv']] |
| 72 | """ | 72 | """ |
| 73 | return map(split_type, get_params(proto)) | 73 | return list(map(split_type, get_params(proto))) |
| 74 | 74 | ||
| 75 | def get_return_type(proto): | 75 | def get_return_type(proto): |
| 76 | import re | 76 | import re |
| @@ -3,7 +3,7 @@ · 2 unmodified lines | |||
| 3 | """ This file generates a c file from a list of cpp prototypes. """ | 3 | """ This file generates a c file from a list of cpp prototypes. """ |
| 4 | 4 | ||
| 5 | import os, sys, shutil | 5 | import os, sys, shutil |
| 6 | from gen_pyobject import write_msg, gen_new_init, gen_do, gen_members, gen_methods, gen_finish | 6 | from .gen_pyobject import write_msg, gen_new_init, gen_do, gen_members, gen_methods, gen_finish |
| 7 | 7 | ||
| 8 | def get_cpp_objects(): | 8 | def get_cpp_objects(): |
| 9 | 9 | ||
| @@ -11,6 +11,7 @@ def get_cpp_objects(): · 1 unmodified line | |||
| 11 | 11 | ||
| 12 | cpp_output = filter(lambda y: len(y) > 1, cpp_output) | 12 | cpp_output = filter(lambda y: len(y) > 1, cpp_output) |
| 13 | cpp_output = filter(lambda y: not y.startswith('#'), cpp_output) | 13 | cpp_output = filter(lambda y: not y.startswith('#'), cpp_output) |
| 14 | cpp_output = list(cpp_output) | ||
| 14 | 15 | ||
| 15 | i = 1 | 16 | i = 1 |
| 16 | while 1: | 17 | while 1: |
| @@ -85,9 +86,11 @@ def generate_object_files(output_path): · 68 unmodified lines | |||
| 85 | object_methods = filter(lambda x: this_object in x, cpp_output) | 86 | object_methods = filter(lambda x: this_object in x, cpp_output) |
| 86 | object_methods = [a.strip() for a in object_methods] | 87 | object_methods = [a.strip() for a in object_methods] |
| 87 | object_methods = filter(lambda x: not x.startswith('typedef'), object_methods) | 88 | object_methods = filter(lambda x: not x.startswith('typedef'), object_methods) |
| 89 | object_methods = list(object_methods) | ||
| 88 | #for method in object_methods: | 90 | #for method in object_methods: |
| 89 | # write_msg(method) | 91 | # write_msg(method) |
| 90 | new_methods = filter(lambda x: 'new_'+object_name in x, object_methods) | 92 | new_methods = list(filter( |
| 93 | lambda x: 'new_'+object_name in x, object_methods)) | ||
| 91 | if len(new_methods) > 1: | 94 | if len(new_methods) > 1: |
| 92 | write_msg("-- WARNING: more than one new method for", object_name) | 95 | write_msg("-- WARNING: more than one new method for", object_name) |
| 93 | for method in new_methods: | 96 | for method in new_methods: |
| @@ -98,7 +101,8 @@ def generate_object_files(output_path): · 4 unmodified lines | |||
| 98 | for method in new_methods: | 101 | for method in new_methods: |
| 99 | write_msg(method) | 102 | write_msg(method) |
| 100 | 103 | ||
| 101 | del_methods = filter(lambda x: 'del_'+object_name in x, object_methods) | 104 | del_methods = list(filter( |
| 105 | lambda x: 'del_'+object_name in x, object_methods)) | ||
| 102 | if len(del_methods) > 1: | 106 | if len(del_methods) > 1: |
| 103 | write_msg("-- WARNING: more than one del method for", object_name) | 107 | write_msg("-- WARNING: more than one del method for", object_name) |
| 104 | for method in del_methods: | 108 | for method in del_methods: |
| @@ -106,7 +110,8 @@ def generate_object_files(output_path): · 1 unmodified line | |||
| 106 | elif len(del_methods) < 1: | 110 | elif len(del_methods) < 1: |
| 107 | write_msg("-- WARNING: no del method for", object_name) | 111 | write_msg("-- WARNING: no del method for", object_name) |
| 108 | 112 | ||
| 109 | do_methods = filter(lambda x: object_name+'_do' in x, object_methods) | 113 | do_methods = list(filter( |
| 114 | lambda x: object_name+'_do' in x, object_methods)) | ||
| 110 | if len(do_methods) > 1: | 115 | if len(do_methods) > 1: |
| 111 | pass | 116 | pass |
| 112 | #write_msg("-- WARNING: more than one do method for", object_name) | 117 | #write_msg("-- WARNING: more than one do method for", object_name) |
| @@ -135,6 +140,7 @@ def generate_object_files(output_path): · 22 unmodified lines | |||
| 135 | other_methods = filter(lambda x: x not in do_methods, other_methods) | 140 | other_methods = filter(lambda x: x not in do_methods, other_methods) |
| 136 | other_methods = filter(lambda x: x not in get_methods, other_methods) | 141 | other_methods = filter(lambda x: x not in get_methods, other_methods) |
| 137 | other_methods = filter(lambda x: x not in set_methods, other_methods) | 142 | other_methods = filter(lambda x: x not in set_methods, other_methods) |
| 143 | other_methods = list(other_methods) | ||
| 138 | 144 | ||
| 139 | if len(other_methods) > 0: | 145 | if len(other_methods) > 0: |
| 140 | write_msg("-- WARNING: some methods for", object_name, "were unidentified") | 146 | write_msg("-- WARNING: some methods for", object_name, "were unidentified") |