History

Merge pull request #40 from nphilipp/develop--py3k-fixes

Miscellaneous fixes for Python, mostly version 3

Paul Brossier committed 10 years ago

Commit 4041a6d2 parents 7c785e6 b8ed85e10 files · +34 −20Browse files

Showing the changes to python/lib (3 of 10 files). Show all

Unified · Split

3 files
  1. python/lib/aubio/midiconv.py +11 −8
  2. python/lib/gen_pyobject.py +1 −1
  3. python/lib/generator.py +10 −4
python/lib/aubio/midiconv.py+11−8
@@ -6,9 +6,11 @@ def note2midi(note): · 5 unmodified lines
66 _valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, 'b': -1, u'♭': -1, u'\ufffd': -2}
77 _valid_octaves = range(-1, 10)
88 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)
1010 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))
1214 notename, modifier, octave = [None]*3
1315
1416 if len(note) == 4:
@@ -26,23 +28,24 @@ def note2midi(note): · 11 unmodified lines
2628 octave = int(octave)
2729
2830 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)
3032 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)
3234 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)
3436
3537 midi = 12 + octave * 12 + _valid_notenames[notename] + _valid_modifiers[modifier]
3638 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)
3840 return midi
3941
4042 def midi2note(midi):
4143 " convert midi note number to note name, e.g. [0, 127] -> [C-1, G9] "
4244 if type(midi) != int:
43− raise TypeError, "an integer is required, got %s" % midi
45+ raise TypeError("an integer is required, got %s" % midi)
4446 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)
4649 midi = int(midi)
4750 _valid_notenames = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
4851 return _valid_notenames[midi % 12] + str( midi / 12 - 1)
python/lib/gen_pyobject.py+1−1
@@ -70,7 +70,7 @@ def get_params_types_names(proto): · 69 unmodified lines
7070 example: proto = "int main (int argc, char ** argv)"
7171 returns: [['int', 'argc'], ['char **','argv']]
7272 """
73− return map(split_type, get_params(proto))
73+ return list(map(split_type, get_params(proto)))
7474
7575 def get_return_type(proto):
7676 import re
python/lib/generator.py+10−4
@@ -3,7 +3,7 @@ · 2 unmodified lines
33 """ This file generates a c file from a list of cpp prototypes. """
44
55 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
77
88 def get_cpp_objects():
99
@@ -11,6 +11,7 @@ def get_cpp_objects(): · 1 unmodified line
1111
1212 cpp_output = filter(lambda y: len(y) > 1, cpp_output)
1313 cpp_output = filter(lambda y: not y.startswith('#'), cpp_output)
14+ cpp_output = list(cpp_output)
1415
1516 i = 1
1617 while 1:
@@ -85,9 +86,11 @@ def generate_object_files(output_path): · 68 unmodified lines
8586 object_methods = filter(lambda x: this_object in x, cpp_output)
8687 object_methods = [a.strip() for a in object_methods]
8788 object_methods = filter(lambda x: not x.startswith('typedef'), object_methods)
89+ object_methods = list(object_methods)
8890 #for method in object_methods:
8991 # 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))
9194 if len(new_methods) > 1:
9295 write_msg("-- WARNING: more than one new method for", object_name)
9396 for method in new_methods:
@@ -98,7 +101,8 @@ def generate_object_files(output_path): · 4 unmodified lines
98101 for method in new_methods:
99102 write_msg(method)
100103
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))
102106 if len(del_methods) > 1:
103107 write_msg("-- WARNING: more than one del method for", object_name)
104108 for method in del_methods:
@@ -106,7 +110,8 @@ def generate_object_files(output_path): · 1 unmodified line
106110 elif len(del_methods) < 1:
107111 write_msg("-- WARNING: no del method for", object_name)
108112
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))
110115 if len(do_methods) > 1:
111116 pass
112117 #write_msg("-- WARNING: more than one do method for", object_name)
@@ -135,6 +140,7 @@ def generate_object_files(output_path): · 22 unmodified lines
135140 other_methods = filter(lambda x: x not in do_methods, other_methods)
136141 other_methods = filter(lambda x: x not in get_methods, other_methods)
137142 other_methods = filter(lambda x: x not in set_methods, other_methods)
143+ other_methods = list(other_methods)
138144
139145 if len(other_methods) > 0:
140146 write_msg("-- WARNING: some methods for", object_name, "were unidentified")

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t