Adam-Langley / pybleno

A direct port of the Bleno bluetooth LE peripheral role library to Python2/3
MIT License
68 stars 34 forks source link

Invalid mode: 'rU' while trying to fdopen (porting to Python 3.11) #58

Open k-neo opened 1 year ago

k-neo commented 1 year ago

The U file mode was removed in Python 3.11 because it had no effect so the U can merely be removed.

open(), io.open(), codecs.open() and fileinput.FileInput no longer accept 'U' (“universal newline”) in the file mode. In Python 3, “universal newline” mode is used by default whenever a file is opened in text mode, and the 'U' flag has been deprecated since Python 3.3. The newline parameter to these functions controls how universal newlines work. (Contributed by Victor Stinner in bpo-37330.)

Execution log

$ python3 main.py 
Traceback (most recent call last):
  File "/home/pi/Dev/peripheral/main.py", line 99, in <module>
    bleno = Bleno()
            ^^^^^^^
  File "/home/pi/.pyenv/versions/3.11.1/lib/python3.11/site-packages/pybleno/hci_socket/Emit.py", line 39, in new_init
    old_init(self, *k, **kw)
  File "/home/pi/.pyenv/versions/3.11.1/lib/python3.11/site-packages/pybleno/Bleno.py", line 41, in __init__
    self._bindings = BlenoBindings()
                     ^^^^^^^^^^^^^^^
  File "/home/pi/.pyenv/versions/3.11.1/lib/python3.11/site-packages/pybleno/hci_socket/Emit.py", line 39, in new_init
    old_init(self, *k, **kw)
  File "/home/pi/.pyenv/versions/3.11.1/lib/python3.11/site-packages/pybleno/hci_socket/Bindings.py", line 16, in __init__
    self._hci = Hci()
                ^^^^^
  File "/home/pi/.pyenv/versions/3.11.1/lib/python3.11/site-packages/pybleno/hci_socket/Emit.py", line 39, in new_init
    old_init(self, *k, **kw)
  File "/home/pi/.pyenv/versions/3.11.1/lib/python3.11/site-packages/pybleno/hci_socket/Hci.py", line 20, in __init__
    self._socket = BluetoothHCI(auto_start=False)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/.pyenv/versions/3.11.1/lib/python3.11/site-packages/pybleno/hci_socket/BluetoothHCI/BluetoothHCI.py", line 239, in __init__
    self.hci = BluetoothHCISocketProvider(device_id)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/.pyenv/versions/3.11.1/lib/python3.11/site-packages/pybleno/hci_socket/BluetoothHCI/BluetoothHCI.py", line 69, in __init__
    self._r = os.fdopen(self.__r, 'rU')
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen os>", line 1031, in fdopen
ValueError: invalid mode: 'rU'
RoyBellingan commented 9 months ago

Yes tried just now and is working fine with this fix.

benjaminwp18 commented 1 month ago

@Adam-Langley Are there any plans to release a version with this fix to pip? I know there haven't been any other changes recently, but it would be great if the PyPi release of this package worked on 3.11.

bodiroga commented 2 weeks ago

@Adam-Langley Are there any plans to release a version with this fix to pip? I know there haven't been any other changes recently, but it would be great if the PyPi release of this package worked on 3.11.

+1 (Thank you very much, @Adam-Langley, for all the work you have done!)