Re: [Python-Dev] bitwise operations for bytes and bytearray

2016-01-09 Thread Andrew Barnert via Python-Dev
On Jan 9, 2016, at 16:17, Blake Griffith wrote: > > A little update, I got ^, &, and | working for bytearrays. You can view the > diff here: > https://github.com/python/cpython/compare/master...cowlicks:bitwise-bytes?expand=1 If you upload the diff to the issue on

Re: [Python-Dev] bitwise operations for bytes and bytearray

2016-01-09 Thread Blake Griffith
A little update, I got ^, &, and | working for bytearrays. You can view the diff here: https://github.com/python/cpython/compare/master...cowlicks:bitwise-bytes?expand=1 How does it look? Joe, is this how I should allocate the arrays? Am I freeing them properly? Am I checking the input enough?

Re: [Python-Dev] bitwise operations for bytes and bytearray

2016-01-09 Thread Martin Panter
On 10 January 2016 at 00:17, Blake Griffith wrote: > A little update, I got ^, &, and | working for bytearrays. You can view the > diff here: > https://github.com/python/cpython/compare/master...cowlicks:bitwise-bytes?expand=1 > > How does it look? I left some

Re: [Python-Dev] bitwise operations for bytes and bytearray

2016-01-07 Thread Joe Jevnik
You want to put the `xor` method in the `nb_xor` field of the `PyNumberMethods` structure that lives in the `tp_as_number` field of the bytes type object. Two things I noticed in a quick pass: you might want to add some type checking around the case where `a` or `b` is not a `PyByteArray` object.

Re: [Python-Dev] bitwise operations for bytes and bytearray

2016-01-07 Thread Andrew Barnert via Python-Dev
On Jan 7, 2016, at 15:57, Martin Panter wrote: > >> On 7 January 2016 at 22:26, Blake Griffith >> wrote: >> I'm interested in adding the functionality to do something like: >> > b'a' ^ b'b' >> b'\x03' >> >> >> Instead of the good ol'

Re: [Python-Dev] bitwise operations for bytes and bytearray

2016-01-07 Thread Blake Griffith
Thanks for the quick responses y'all. I have something compiling on my branch, which is enough for me tonight. I asked a question about this on stackoverflow a while ago, it wasn't very popular https://stackoverflow.com/questions/32658420/why-cant-you-xor-bytes-objects-in-python Someone there

Re: [Python-Dev] bitwise operations for bytes and bytearray

2016-01-07 Thread Martin Panter
On 7 January 2016 at 22:26, Blake Griffith wrote: > I'm interested in adding the functionality to do something like: > b'a' ^ b'b' > b'\x03' > > > Instead of the good ol' TypeError. > > I think both bytes and bytearray should support all the bitwise operations.

Re: [Python-Dev] bitwise operations for bytes and bytearray

2016-01-07 Thread Cameron Simpson
On 07Jan2016 16:12, Python-Dev wrote: On Jan 7, 2016, at 15:57, Martin Panter wrote: On 7 January 2016 at 22:26, Blake Griffith wrote: I'm interested in adding the functionality to do something like: b'a' ^ b'b'

[Python-Dev] bitwise operations for bytes and bytearray

2016-01-07 Thread Blake Griffith
Hi! I'm interested in adding the functionality to do something like: >>> b'a' ^ b'b' b'\x03' Instead of the good ol' TypeError. I think both bytes and bytearray should support all the bitwise operations. I've never hacked on cpython before. I'm starting by just trying to add xor to

Re: [Python-Dev] bitwise operations for bytes and bytearray

2016-01-07 Thread Brett Cannon
On Thu, 7 Jan 2016 at 14:29 Blake Griffith wrote: > Hi! > > I'm interested in adding the functionality to do something like: > > >>> b'a' ^ b'b' > b'\x03' > > > Instead of the good ol' TypeError. > > I think both bytes and bytearray should support all the bitwise