Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
072b1e14
Commit
072b1e14
authored
May 26, 2012
by
Hynek Schlawack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#14814: Some PEP8 adjustments and dead code weeding
parent
039b01d0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
27 deletions
+17
-27
Lib/ipaddress.py
Lib/ipaddress.py
+17
-27
No files found.
Lib/ipaddress.py
View file @
072b1e14
...
@@ -284,7 +284,8 @@ def summarize_address_range(first, last):
...
@@ -284,7 +284,8 @@ def summarize_address_range(first, last):
If the version is not 4 or 6.
If the version is not 4 or 6.
"""
"""
if
not
(
isinstance
(
first
,
_BaseAddress
)
and
isinstance
(
last
,
_BaseAddress
)):
if
(
not
(
isinstance
(
first
,
_BaseAddress
)
and
isinstance
(
last
,
_BaseAddress
))):
raise
TypeError
(
'first and last must be IP addresses, not networks'
)
raise
TypeError
(
'first and last must be IP addresses, not networks'
)
if
first
.
version
!=
last
.
version
:
if
first
.
version
!=
last
.
version
:
raise
TypeError
(
"%s and %s are not of the same version"
%
(
raise
TypeError
(
"%s and %s are not of the same version"
%
(
...
@@ -292,8 +293,6 @@ def summarize_address_range(first, last):
...
@@ -292,8 +293,6 @@ def summarize_address_range(first, last):
if
first
>
last
:
if
first
>
last
:
raise
ValueError
(
'last IP address must be greater than first'
)
raise
ValueError
(
'last IP address must be greater than first'
)
networks
=
[]
if
first
.
version
==
4
:
if
first
.
version
==
4
:
ip
=
IPv4Network
ip
=
IPv4Network
elif
first
.
version
==
6
:
elif
first
.
version
==
6
:
...
@@ -316,7 +315,6 @@ def summarize_address_range(first, last):
...
@@ -316,7 +315,6 @@ def summarize_address_range(first, last):
prefix
=
_get_prefix_length
(
first_int
,
current
,
ip_bits
)
prefix
=
_get_prefix_length
(
first_int
,
current
,
ip_bits
)
net
=
ip
(
'%s/%d'
%
(
str
(
first
),
prefix
))
net
=
ip
(
'%s/%d'
%
(
str
(
first
),
prefix
))
yield
net
yield
net
#networks.append(net)
if
current
==
ip
.
_ALL_ONES
:
if
current
==
ip
.
_ALL_ONES
:
break
break
first_int
=
current
+
1
first_int
=
current
+
1
...
@@ -599,7 +597,7 @@ class _BaseAddress(_IPAddressBase):
...
@@ -599,7 +597,7 @@ class _BaseAddress(_IPAddressBase):
return
'%s(%r)'
%
(
self
.
__class__
.
__name__
,
str
(
self
))
return
'%s(%r)'
%
(
self
.
__class__
.
__name__
,
str
(
self
))
def
__str__
(
self
):
def
__str__
(
self
):
return
'%s'
%
self
.
_string_from_ip_int
(
self
.
_ip
)
return
str
(
self
.
_string_from_ip_int
(
self
.
_ip
)
)
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
hex
(
int
(
self
.
_ip
)))
return
hash
(
hex
(
int
(
self
.
_ip
)))
...
@@ -719,8 +717,7 @@ class _BaseNetwork(_IPAddressBase):
...
@@ -719,8 +717,7 @@ class _BaseNetwork(_IPAddressBase):
return
not
eq
return
not
eq
def
__str__
(
self
):
def
__str__
(
self
):
return
'%s/%s'
%
(
str
(
self
.
ip
),
return
'%s/%s'
%
(
self
.
ip
,
self
.
_prefixlen
)
str
(
self
.
_prefixlen
))
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
int
(
self
.
network_address
)
^
int
(
self
.
netmask
))
return
hash
(
int
(
self
.
network_address
)
^
int
(
self
.
netmask
))
...
@@ -838,13 +835,10 @@ class _BaseNetwork(_IPAddressBase):
...
@@ -838,13 +835,10 @@ class _BaseNetwork(_IPAddressBase):
if
not
(
other
.
network_address
>=
self
.
network_address
and
if
not
(
other
.
network_address
>=
self
.
network_address
and
other
.
broadcast_address
<=
self
.
broadcast_address
):
other
.
broadcast_address
<=
self
.
broadcast_address
):
raise
ValueError
(
'%s not contained in %s'
%
(
str
(
other
),
str
(
self
)))
raise
ValueError
(
'%s not contained in %s'
%
(
other
,
self
))
if
other
==
self
:
if
other
==
self
:
raise
StopIteration
raise
StopIteration
ret_addrs
=
[]
# Make sure we're comparing the network of other.
# Make sure we're comparing the network of other.
other
=
ip_network
(
'%s/%s'
%
(
str
(
other
.
network_address
),
other
=
ip_network
(
'%s/%s'
%
(
str
(
other
.
network_address
),
str
(
other
.
prefixlen
)),
str
(
other
.
prefixlen
)),
...
@@ -1013,8 +1007,8 @@ class _BaseNetwork(_IPAddressBase):
...
@@ -1013,8 +1007,8 @@ class _BaseNetwork(_IPAddressBase):
An IPv4 network object.
An IPv4 network object.
Raises:
Raises:
ValueError: If self.prefixlen - prefixlen_diff < 0. I.e., you have
a
ValueError: If self.prefixlen - prefixlen_diff < 0. I.e., you have
negative prefix length.
a
negative prefix length.
OR
OR
If prefixlen_diff and new_prefix are both set or new_prefix is a
If prefixlen_diff and new_prefix are both set or new_prefix is a
larger number than the current prefix (larger number means a
larger number than the current prefix (larger number means a
...
@@ -1031,7 +1025,6 @@ class _BaseNetwork(_IPAddressBase):
...
@@ -1031,7 +1025,6 @@ class _BaseNetwork(_IPAddressBase):
raise
ValueError
(
'cannot set prefixlen_diff and new_prefix'
)
raise
ValueError
(
'cannot set prefixlen_diff and new_prefix'
)
prefixlen_diff
=
self
.
_prefixlen
-
new_prefix
prefixlen_diff
=
self
.
_prefixlen
-
new_prefix
if
self
.
prefixlen
-
prefixlen_diff
<
0
:
if
self
.
prefixlen
-
prefixlen_diff
<
0
:
raise
ValueError
(
raise
ValueError
(
'current prefixlen is %d, cannot have a prefixlen_diff of %d'
%
'current prefixlen is %d, cannot have a prefixlen_diff of %d'
%
...
@@ -1302,7 +1295,6 @@ class IPv4Interface(IPv4Address):
...
@@ -1302,7 +1295,6 @@ class IPv4Interface(IPv4Address):
self
.
netmask
=
self
.
network
.
netmask
self
.
netmask
=
self
.
network
.
netmask
self
.
hostmask
=
self
.
network
.
hostmask
self
.
hostmask
=
self
.
network
.
hostmask
def
__str__
(
self
):
def
__str__
(
self
):
return
'%s/%d'
%
(
self
.
_string_from_ip_int
(
self
.
_ip
),
return
'%s/%d'
%
(
self
.
_string_from_ip_int
(
self
.
_ip
),
self
.
network
.
prefixlen
)
self
.
network
.
prefixlen
)
...
@@ -1364,7 +1356,6 @@ class IPv4Interface(IPv4Address):
...
@@ -1364,7 +1356,6 @@ class IPv4Interface(IPv4Address):
return
True
return
True
return
False
return
False
@
property
@
property
def
prefixlen
(
self
):
def
prefixlen
(
self
):
return
self
.
_prefixlen
return
self
.
_prefixlen
...
@@ -1381,6 +1372,7 @@ class IPv4Interface(IPv4Address):
...
@@ -1381,6 +1372,7 @@ class IPv4Interface(IPv4Address):
def
with_netmask
(
self
):
def
with_netmask
(
self
):
return
'%s/%s'
%
(
self
.
_string_from_ip_int
(
self
.
_ip
),
return
'%s/%s'
%
(
self
.
_string_from_ip_int
(
self
.
_ip
),
self
.
netmask
)
self
.
netmask
)
@
property
@
property
def
with_hostmask
(
self
):
def
with_hostmask
(
self
):
return
'%s/%s'
%
(
self
.
_string_from_ip_int
(
self
.
_ip
),
return
'%s/%s'
%
(
self
.
_string_from_ip_int
(
self
.
_ip
),
...
@@ -1652,8 +1644,9 @@ class _BaseV6(object):
...
@@ -1652,8 +1644,9 @@ class _BaseV6(object):
if
parts_skipped
<
1
:
if
parts_skipped
<
1
:
raise
AddressValueError
(
ip_str
)
raise
AddressValueError
(
ip_str
)
else
:
else
:
# Otherwise, allocate the entire address to parts_hi. The endpoints
# Otherwise, allocate the entire address to parts_hi. The
# could still be empty, but _parse_hextet() will check for that.
# endpoints could still be empty, but _parse_hextet() will check
# for that.
if
len
(
parts
)
!=
self
.
_HEXTET_COUNT
:
if
len
(
parts
)
!=
self
.
_HEXTET_COUNT
:
raise
AddressValueError
(
ip_str
)
raise
AddressValueError
(
ip_str
)
parts_hi
=
len
(
parts
)
parts_hi
=
len
(
parts
)
...
@@ -1684,7 +1677,8 @@ class _BaseV6(object):
...
@@ -1684,7 +1677,8 @@ class _BaseV6(object):
The hextet as an integer.
The hextet as an integer.
Raises:
Raises:
ValueError: if the input isn't strictly a hex number from [0..FFFF].
ValueError: if the input isn't strictly a hex number from
[0..FFFF].
"""
"""
# Whitelist the characters, since int() allows a lot of bizarre stuff.
# Whitelist the characters, since int() allows a lot of bizarre stuff.
...
@@ -1893,7 +1887,6 @@ class _BaseV6(object):
...
@@ -1893,7 +1887,6 @@ class _BaseV6(object):
return
(
self
.
network_address
in
private_network
and
return
(
self
.
network_address
in
private_network
and
self
.
broadcast_address
in
private_network
)
self
.
broadcast_address
in
private_network
)
@
property
@
property
def
ipv4_mapped
(
self
):
def
ipv4_mapped
(
self
):
"""Return the IPv4 mapped address.
"""Return the IPv4 mapped address.
...
@@ -2029,7 +2022,6 @@ class IPv6Interface(IPv6Address):
...
@@ -2029,7 +2022,6 @@ class IPv6Interface(IPv6Address):
self
.
_prefixlen
=
self
.
network
.
_prefixlen
self
.
_prefixlen
=
self
.
network
.
_prefixlen
self
.
hostmask
=
self
.
network
.
hostmask
self
.
hostmask
=
self
.
network
.
hostmask
def
__str__
(
self
):
def
__str__
(
self
):
return
'%s/%d'
%
(
self
.
_string_from_ip_int
(
self
.
_ip
),
return
'%s/%d'
%
(
self
.
_string_from_ip_int
(
self
.
_ip
),
self
.
network
.
prefixlen
)
self
.
network
.
prefixlen
)
...
@@ -2047,6 +2039,7 @@ class IPv6Interface(IPv6Address):
...
@@ -2047,6 +2039,7 @@ class IPv6Interface(IPv6Address):
@
property
@
property
def
prefixlen
(
self
):
def
prefixlen
(
self
):
return
self
.
_prefixlen
return
self
.
_prefixlen
@
property
@
property
def
ip
(
self
):
def
ip
(
self
):
return
IPv6Address
(
self
.
_ip
)
return
IPv6Address
(
self
.
_ip
)
...
@@ -2058,6 +2051,7 @@ class IPv6Interface(IPv6Address):
...
@@ -2058,6 +2051,7 @@ class IPv6Interface(IPv6Address):
@
property
@
property
def
with_netmask
(
self
):
def
with_netmask
(
self
):
return
self
.
with_prefixlen
return
self
.
with_prefixlen
@
property
@
property
def
with_hostmask
(
self
):
def
with_hostmask
(
self
):
return
'%s/%s'
%
(
self
.
_string_from_ip_int
(
self
.
_ip
),
return
'%s/%s'
%
(
self
.
_string_from_ip_int
(
self
.
_ip
),
...
@@ -2081,8 +2075,8 @@ class IPv6Network(_BaseV6, _BaseNetwork):
...
@@ -2081,8 +2075,8 @@ class IPv6Network(_BaseV6, _BaseNetwork):
"""Instantiate a new IPv6 Network object.
"""Instantiate a new IPv6 Network object.
Args:
Args:
address: A string or integer representing the IPv6 network or the
IP
address: A string or integer representing the IPv6 network or the
and prefix/netmask.
IP
and prefix/netmask.
'2001:db8::/128'
'2001:db8::/128'
'2001:db8:0000:0000:0000:0000:0000:0000/128'
'2001:db8:0000:0000:0000:0000:0000:0000/128'
'2001:db8::'
'2001:db8::'
...
@@ -2190,10 +2184,6 @@ class IPv6Network(_BaseV6, _BaseNetwork):
...
@@ -2190,10 +2184,6 @@ class IPv6Network(_BaseV6, _BaseNetwork):
return
False
return
False
return
0
<=
prefixlen
<=
self
.
_max_prefixlen
return
0
<=
prefixlen
<=
self
.
_max_prefixlen
@
property
def
with_netmask
(
self
):
return
self
.
with_prefixlen
@
property
@
property
def
with_prefixlen
(
self
):
def
with_prefixlen
(
self
):
return
'%s/%d'
%
(
str
(
self
.
network_address
),
self
.
_prefixlen
)
return
'%s/%d'
%
(
str
(
self
.
network_address
),
self
.
_prefixlen
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment