[issue32820] Add bits method to ipaddress

2018-02-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: And Eric, please avoid including the quote of previous message in your messages. This makes hard to read your messages and the whole discussion. -- ___ Python tracker

[issue32820] Add bits method to ipaddress

2018-02-20 Thread Eric Osborne
Eric Osborne added the comment: Yeah, bits() is dead. The thread has the same title, but I changed the PR a while ago. The diffs in the PR are for format(). I'll go over the code and clean it up. The docstring in particular is probably lousy. Thanks! eric On Tue, Feb 20,

[issue32820] Add bits method to ipaddress

2018-02-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I the bits() method is a dead end. The conclusion was to add __format__(). -- ___ Python tracker

[issue32820] Add bits method to ipaddress

2018-02-19 Thread Nick Coghlan
Nick Coghlan added the comment: The python-ideas discussion didn't turn up any major concerns we hadn't already considered, so you're in "wait for PR review" mode now. If you wanted to do a self-review in the meantime, then

[issue32820] Add bits method to ipaddress

2018-02-19 Thread Eric Osborne
Eric Osborne added the comment: I brought it up on python-ideas. Since I've not been through this process before - what happens now? Do I wait for code review on github, or is there more I need to do? eric On Tue, Feb 13, 2018 at 11:56 PM Nick Coghlan

[issue32820] Add bits method to ipaddress

2018-02-14 Thread Eric Osborne
Eric Osborne added the comment: Cool, I will kick it over to python-ideas. I checked in some code to handle the format string and it's a lot like what you're suggesting, so I'll leave that in there and see what happens. Thanks! eric On Tue, Feb 13, 2018 at 11:56 PM Nick

[issue32820] Add bits method to ipaddress

2018-02-13 Thread Nick Coghlan
Nick Coghlan added the comment: Aye, definitely worth a thread on python-ideas. My rationale for suggesting something based on the built-in numeric codes is that it makes it straightforward for *users* to transfer knowledge from that mini-language. As far as parsing goes,

[issue32820] Add bits method to ipaddress

2018-02-13 Thread Eric V. Smith
Eric V. Smith added the comment: If you don't recognize the format string, you want to fall back to: return super().__format__(fmt) Since that will call object.__format__, it will generate an error if fmt is not the empty string, which is what it does currently for IP

[issue32820] Add bits method to ipaddress

2018-02-13 Thread Berker Peksag
Change by Berker Peksag : -- nosy: -berker.peksag ___ Python tracker ___ ___

[issue32820] Add bits method to ipaddress

2018-02-13 Thread Berker Peksag
Berker Peksag added the comment: Eric, please delete the previous message when you reply by email. Keeping the previous message makes your comment harder to read. See https://bugs.python.org/issue32820#msg312050 on browser for example. -- nosy: +berker.peksag

[issue32820] Add bits method to ipaddress

2018-02-13 Thread Eric Osborne
Eric Osborne added the comment: This is an interesting idea. I hacked together something to handle IPv4 and pushed it to the repository. It works, but I'm afraid it may be kinda ugly. Do you have any examples of good, pythonic ways to parse the format string or otherwise

[issue32820] Add bits method to ipaddress

2018-02-12 Thread Nick Coghlan
Nick Coghlan added the comment: I think the aspect that makes this potentially worthy of a helper function is the need to dynamically adjust the field width based on whether you're printing an IPv4 address or an IPv6 one, whether you're printing it in binary or

[issue32820] Add bits method to ipaddress

2018-02-12 Thread Eric Osborne
Eric Osborne added the comment: IPv6 is nasty no matter how you do it (cf. https://tools.ietf.org/html/rfc1924). And the ipaddr library already has hex (packed()). Binary's not about direct readabilty, but about ease of comparison. It's much easier to show the reader

[issue32820] Add bits method to ipaddress

2018-02-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I wouldn't say that "0b00011101101110001101101000111000101000101110001101110111001100110100" is a very human readable. For more readability it is better to group digits

[issue32820] Add bits method to ipaddress

2018-02-12 Thread Eric Osborne via Python-bugs-list
Eric Osborne added the comment: It is often useful to have non-decimal representations of IP addresses. Hex shows up a lot in sniffer traces, which is why I wanted to provide __index__, but that's not going to happen. I use binary a lot when teaching subnet masking and address

[issue32820] Add bits method to ipaddress

2018-02-12 Thread Christian Heimes
Christian Heimes added the comment: I agree with Serhiy and Eric. It's a needless complication of the module. What's the actual use case of printing a human readable bit representation of an IP address? -- nosy: +christian.heimes

[issue32820] Add bits method to ipaddress

2018-02-12 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- nosy: +ncoghlan -nick ___ Python tracker ___

[issue32820] Add bits method to ipaddress

2018-02-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The usefulness of this feature looks questionable to me. -- nosy: +nick, serhiy.storchaka ___ Python tracker

[issue32820] Add bits method to ipaddress

2018-02-11 Thread Eric Osborne
Eric Osborne added the comment: Faster, too. My way: In [7]: %timeit bits(a) 1.67 µs ± 7.31 ns per loop (mean ± std. dev. of 7 runs, 100 loops each) Your way: In [11]: %timeit b2(a) 1.2 µs ± 5.93 ns per loop (mean ± std. dev. of 7 runs, 100 loops each) I was a little

[issue32820] Add bits method to ipaddress

2018-02-11 Thread Eric V. Smith
Eric V. Smith added the comment: Without commenting on how useful or desirable this would be, I'll point out the string can be computed as: return f'{int(self):#0{IPV4LENGTH+2}b}' -- nosy: +eric.smith ___ Python tracker

[issue32820] Add bits method to ipaddress

2018-02-11 Thread Eric Osborne
Change by Eric Osborne : -- keywords: +patch pull_requests: +5434 stage: -> patch review ___ Python tracker ___

[issue32820] Add bits method to ipaddress

2018-02-11 Thread Eric Osborne
Eric Osborne added the comment: redoing with a bits() property method to return a string, a la: def bits(self): fstr = '0' + str(IPV4LENGTH) + 'b' return '0b' + format(int(self), fstr) Works thusly: import ipaddress as ip a = ip.IPv4Address('0.0.0.42')