FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-132099: Accept an integer as the address for BTPROTO_HCI on Linux by serhiy-storchaka · Pull Request #132525 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (2) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 4 additions & 2 deletions Doc/library/socket.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ created. Socket addresses are represented as follows:

- :const:`BTPROTO_HCI` accepts a format that depends on your OS.

- On Linux it accepts a tuple ``(device_id, [channel])`` where ``device_id``
is an integer specifying the number of the Bluetooth device,
- On Linux it accepts an integer ``device_id`` or a tuple
``(device_id, [channel])`` where ``device_id``
specifies the number of the Bluetooth device,
and ``channel`` is an optional integer specifying the HCI channel

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
and ``channel`` is an optional integer specifying the HCI channel
and ``channel`` is an optional integer specifying the HCI channel.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No, it is not the end of the sentence.

(:const:`HCI_CHANNEL_RAW` by default).
- On FreeBSD, NetBSD and DragonFly BSD it accepts ``bdaddr``
Expand All @@ -171,6 +172,7 @@ created. Socket addresses are represented as follows:

.. versionchanged:: next
Added ``channel`` field.
``device_id`` not packed in a tuple is now accepted.

- :const:`BTPROTO_SCO` accepts ``bdaddr`` where ``bdaddr`` is
the Bluetooth address as a string or a :class:`bytes` object.
Expand Down
8 changes: 6 additions & 2 deletions Lib/test/test_socket.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2745,6 +2745,12 @@ def testBindHciSocket(self):
addr = s.getsockname()
self.assertEqual(addr, dev)

with (self.subTest('integer'),
socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI) as s):
s.bind(dev)
addr = s.getsockname()
self.assertEqual(addr, dev)

with (self.subTest('channel=HCI_CHANNEL_RAW'),
socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI) as s):
channel = socket.HCI_CHANNEL_RAW
Expand Down Expand Up @@ -2789,8 +2795,6 @@ def testBadHciAddr(self):
s.bind(())
with self.assertRaises(OSError):
s.bind((dev, socket.HCI_CHANNEL_RAW, 0, 0))
with self.assertRaises(OSError):
s.bind(dev)
with self.assertRaises(OSError):
s.bind(socket.BDADDR_ANY)
with self.assertRaises(OSError):
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The Bluetooth socket with the :data:`~socket.BTPROTO_HCI` protocol on Linux
now accepts an address in the format of an integer ``device_id``, not only a
tuple ``(device_id,)``.
7 changes: 6 additions & 1 deletion Modules/socketmodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2147,7 +2147,12 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
unsigned short dev;
unsigned short channel = HCI_CHANNEL_RAW;
if (!PyArg_ParseTuple(args, "H|H", &dev, &channel)) {
if (PyLong_Check(args)) {
if (!PyArg_Parse(args, "H", &dev)) {
return 0;
}
}
else if (!PyArg_ParseTuple(args, "H|H", &dev, &channel)) {
PyErr_Format(PyExc_OSError,
"%s(): wrong format", caller);
return 0;
Expand Down

Back | FazBrowse Home | New Git URL