py, str: Replace enum with actual function pointer.

This way, it's slightly more efficient, uses less ROM (60 bytes less
for stmhal), and doesn't require to raise exception if bad operation
given.