Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-30987 - Support for ISO-TP protocol in SocketCAN #2956

Merged
merged 13 commits into from
Aug 28, 2017
Merged

bpo-30987 - Support for ISO-TP protocol in SocketCAN #2956

merged 13 commits into from
Aug 28, 2017

Conversation

pylessard
Copy link
Contributor

@pylessard pylessard commented Jul 31, 2017

This Pull Request add the support of CAN ISO-TP address extensions in the socket module by enhancing getsockaddrarg and getsockname.

Note to core developpers : I believe this pull request should be backported back to Python 3.3 where SocketCAN support have been added.

https://bugs.python.org/issue30987

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@pylessard pylessard changed the title Fix issue 30987 bpo-30987 Jul 31, 2017
@pylessard pylessard changed the title bpo-30987 bpo-30987 - Support for ISO-TP protocol in SocketCAN Jul 31, 2017
@pylessard
Copy link
Contributor Author

After second thoughts, only the getsockaddress interface should be included in Python.
The constant in can-isotp should com from a third party module.
Will do the change and reopen the pull request

@pylessard pylessard reopened this Aug 3, 2017
@pylessard
Copy link
Contributor Author

pylessard commented Aug 3, 2017

Pull request is re-open. All dependencies over the third party project have been removed.
getsockname interface has been enhanced with ISO-TP protocol support to be consistent with the bind method input format.

Copy link
Member

@tiran tiran left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. Your patch looks mostly fine, good work! I added notes for some style nit picks and a missing ifdef check.

@@ -6993,6 +7055,8 @@ PyInit__socket(void)
PyModule_AddIntMacro(m, CAN_SFF_MASK);
PyModule_AddIntMacro(m, CAN_EFF_MASK);
PyModule_AddIntMacro(m, CAN_ERR_MASK);

PyModule_AddIntMacro(m, CAN_ISOTP);
Copy link
Member

Choose a reason for hiding this comment

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

This needs a #ifdef CAN_ISOTP.

@@ -1913,6 +1927,54 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
Py_DECREF(interfaceName);
return 1;
}
#endif

#if defined(CAN_ISOTP)
Copy link
Member

Choose a reason for hiding this comment

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

#ifdef CAN_ISOTP

@@ -1869,7 +1882,9 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
}
#endif

#if defined(AF_CAN) && defined(CAN_RAW) && defined(CAN_BCM)
#if defined(AF_CAN)
Copy link
Member

Choose a reason for hiding this comment

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

Please use ifdef for simple checks: #ifdef AF_CAN

def testBind(self):
try:
with socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_ISOTP) as s:
addr = (self.interface,0x123,0x456)
Copy link
Member

Choose a reason for hiding this comment

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

Style nit pick: addr = self.interface, 0x123, 0x456

# most systems limit IFNAMSIZ to 16, take 1024 to be sure
with socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_ISOTP) as s:
self.assertRaisesRegex(OSError, 'interface name too long',
s.bind, ('x' * 1024,1,2))
Copy link
Member

Choose a reason for hiding this comment

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

Please use

with self.assertRaisesRegex(OSError, 'interface name too long'):
    s.bind(('x' * 1024, 1, 2))

to make it more readable.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I didn't expect the Spanish Inquisition!. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@pylessard
Copy link
Contributor Author

I didn't expect the Spanish Inquisition!

@bedevere-bot
Copy link

Nobody expects the Spanish Inquisition!

@tiran: please review the changes made to this pull request.

@tiran
Copy link
Member

tiran commented Aug 27, 2017

Your PR is still missing a space after comma in test_socket.py, 280141c#diff-30065f853d7944a19b3e17b55db67733 . Let's follow PEP 8 for new code.

@pylessard
Copy link
Contributor Author

pylessard commented Aug 27, 2017

@tiran Changes done sir!

Copy link
Member

@tiran tiran left a comment

Choose a reason for hiding this comment

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

perfect! 🥇

@tiran tiran merged commit a30f6d4 into python:master Aug 28, 2017
GadgetSteve pushed a commit to GadgetSteve/cpython that referenced this pull request Sep 10, 2017
* Added support for CAN_ISOTP protocol

* Added unit tests for CAN ISOTP

* Updated documentation for ISO-TP protocol

* Removed trailing whitespace in documentation

* Added blurb NEWS.d file

* updated Misc/ACKS

* Fixed broken unit test that was using isotp const outside of skippable section

* Removed dependecy over third party project

* Added implementation for getsockname + unit tests

* Missing newline at end of ACKS file

* Accidentally inserted a type in ACKS file

* Followed tiran changes review #1 recommendations

* Added spaces after comma
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants