[issue34465] ipaddress should accept bytearray in addition to bytes

2018-09-11 Thread Jörn Heissler

Jörn Heissler  added the comment:

> Maybe add a special purposed named constructor IPv4Address.from_bytes() that 
> will accept any objects supporting the buffer protocol?

That would work for me.
I wonder if there should be something like ipaddress.ip_address_from_bytes too 
that can construct IPv4Adress or IPv6Address.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34465] ipaddress should accept bytearray in addition to bytes

2018-09-11 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

See issue27572 for moving in opposite direction. Supporting the buffer protocol 
rather of just bytes and bytearray complicates the code, and can be considered 
as a feature creep, especially if an input is a text encoded as bytes.

But in this case the bytes argument of IPv4Address() is not a text 
representation like b'127.0.0.1', but a packed array of bytes like bytes([127, 
0, 0, 1]). Accepting bytearray and memoryview makes more sense for it. Yet I'm 
not sure that supporting them is worth adding an overhead. This will affect 
every call of the IPv4Address constructor, and I think that this is not the 
most common case.

Maybe add a special purposed named constructor IPv4Address.from_bytes() that 
will accept any objects supporting the buffer protocol?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34465] ipaddress should accept bytearray in addition to bytes

2018-09-10 Thread Gregory P. Smith


Gregory P. Smith  added the comment:

This isn't limited to just IPv4Address, the Network classes and the IPv6 
classes that accept bytes should also be updated for consistency if we're going 
to do this.

(bytes, bytearray, memoryview) make sense to support, and explicitly test in 
unittests.

Until then, the workaround is to call bytes on the relevant slice of those.

--
nosy: +gregory.p.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34465] ipaddress should accept bytearray in addition to bytes

2018-08-31 Thread Xiang Zhang


Xiang Zhang  added the comment:

I'm -1 on this change. I think the workaround is easy and direct.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34465] ipaddress should accept bytearray in addition to bytes

2018-08-25 Thread Jörn Heissler

Jörn Heissler  added the comment:

That's what I'm doing now.
But it would be more convenient if I could pass a bytearray.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34465] ipaddress should accept bytearray in addition to bytes

2018-08-25 Thread Xiang Zhang


Xiang Zhang  added the comment:

Why not just bytes(buf[:4]) before passing?

--
nosy: +xiang.zhang

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34465] ipaddress should accept bytearray in addition to bytes

2018-08-25 Thread Jörn Heissler

Jörn Heissler  added the comment:

My use case is parsing binary data. For that I use a bytearray as a buffer. 
buf[:4] gets me another bytearray which I'd want to convert to an ipaddress.

I can't think of a usecase for list-of-int.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34465] ipaddress should accept bytearray in addition to bytes

2018-08-25 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

What is your use case?

New features can be added only in the developed version.

--
nosy: +ncoghlan, pmoody, serhiy.storchaka
versions:  -Python 3.4, Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34465] ipaddress should accept bytearray in addition to bytes

2018-08-24 Thread Prudvi RajKumar Maddala


Change by Prudvi RajKumar Maddala :


--
keywords: +patch
pull_requests: +8379
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34465] ipaddress should accept bytearray in addition to bytes

2018-08-23 Thread Prudvi RajKumar Maddala


Prudvi RajKumar Maddala  added the comment:

I think it should be supported too. How about a list of bytes? eg : 
[127,0,0,1].. Should that be supported as well?

--
nosy: +prudvinit

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34465] ipaddress should accept bytearray in addition to bytes

2018-08-22 Thread Jörn Heissler

New submission from Jörn Heissler :

Hi,

the ipaddress module accepts `bytes' objects in the constructors.
`bytearray' however is not supported, see paste below.

Should this be supported too?


>>> import ipaddress

>>> ipaddress.IPv4Address(bytes([127, 0, 0, 1]))
IPv4Address('127.0.0.1')

>>> ipaddress.IPv4Address(bytearray([127, 0, 0, 1]))
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.7/ipaddress.py", line 1301, in __init__
self._ip = self._ip_int_from_string(addr_str)
  File "/usr/lib/python3.7/ipaddress.py", line 1135, in _ip_int_from_string
raise AddressValueError("Expected 4 octets in %r" % ip_str)
ipaddress.AddressValueError: Expected 4 octets in 
"bytearray(b'\\x7f\\x00\\x00\\x01')"

--
components: Library (Lib)
messages: 323906
nosy: joernheissler
priority: normal
severity: normal
status: open
title: ipaddress should accept bytearray in addition to bytes
type: enhancement
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com