/usr/lib/python2.7/dist-packages/mido/py2.py is in python-mido 1.2.7-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import sys
PY2 = (sys.version_info.major == 2)
def convert_py2_bytes(data):
"""Convert bytes object to bytearray in Python 2.
Many parts of Mido such as ``Parser.feed()`` and
``Message.from_bytes()`` accept an iterable of integers.
In Python 3 you can pass a byte string::
>>> list(b'\x01\x02\x03')
[1, 2, 3]
while in Python 2 this happens::
>>> list(b'\x01\x02\x03')
['\x01', '\x02', '\x03']
This function patches over the difference::
>>> list(convert_py2_bytes(b'\x01\x02\x03'))
[1, 2, 3]
"""
if PY2 and isinstance(data, bytes):
return bytearray(data)
else:
return data
|