Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
b53f0fbf
Kaydet (Commit)
b53f0fbf
authored
Ock 18, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #23266: Restore the performance of ipaddress.collapse_addresses() whith
duplicated addresses and simplify the code.
üst
1202a473
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
25 deletions
+25
-25
ipaddress.py
Lib/ipaddress.py
+16
-20
test_ipaddress.py
Lib/test/test_ipaddress.py
+9
-5
No files found.
Lib/ipaddress.py
Dosyayı görüntüle @
b53f0fbf
...
...
@@ -164,25 +164,23 @@ def _split_optional_netmask(address):
def
_find_address_range
(
addresses
):
"""Find a sequence of IPv#Address.
"""Find a sequence of
sorted deduplicated
IPv#Address.
Args:
addresses: a list of IPv#Address objects.
Returns:
A tuple containing the first and last IP addresses in the sequence,
and the number of distinct IP addresses in the sequence.
Yields:
A tuple containing the first and last IP addresses in the sequence.
"""
first
=
last
=
addresses
[
0
]
i
=
1
for
ip
in
addresses
[
1
:]:
if
ip
.
_ip
==
last
.
_ip
+
1
:
last
=
ip
i
+=
1
else
:
break
return
(
first
,
last
,
i
)
it
=
iter
(
addresses
)
first
=
last
=
next
(
it
)
for
ip
in
it
:
if
ip
.
_ip
!=
last
.
_ip
+
1
:
yield
first
,
last
first
=
ip
last
=
ip
yield
first
,
last
def
_count_righthand_zero_bits
(
number
,
bits
):
...
...
@@ -323,7 +321,6 @@ def collapse_addresses(addresses):
TypeError: If passed a list of mixed version objects.
"""
i
=
0
addrs
=
[]
ips
=
[]
nets
=
[]
...
...
@@ -349,14 +346,13 @@ def collapse_addresses(addresses):
ip
,
nets
[
-
1
]))
nets
.
append
(
ip
)
# sort
ips
=
sorted
(
ips
)
# sort
and dedup
ips
=
sorted
(
set
(
ips
)
)
# find consecutive address ranges in the sorted sequence and summarize them
while
i
<
len
(
ips
):
(
first
,
last
,
items
)
=
_find_address_range
(
ips
[
i
:])
i
=
items
+
i
addrs
.
extend
(
summarize_address_range
(
first
,
last
))
if
ips
:
for
first
,
last
in
_find_address_range
(
ips
):
addrs
.
extend
(
summarize_address_range
(
first
,
last
))
return
_collapse_addresses_internal
(
addrs
+
nets
)
...
...
Lib/test/test_ipaddress.py
Dosyayı görüntüle @
b53f0fbf
...
...
@@ -790,11 +790,15 @@ class IpaddrUnitTest(unittest.TestCase):
2
**
ipaddress
.
IPV6LENGTH
)
def
testInternals
(
self
):
first
,
last
,
nitems
=
ipaddress
.
_find_address_range
([
ipaddress
.
IPv4Address
(
'10.10.10.10'
),
ipaddress
.
IPv4Address
(
'10.10.10.12'
)])
self
.
assertEqual
(
first
,
last
)
self
.
assertEqual
(
nitems
,
1
)
ip1
=
ipaddress
.
IPv4Address
(
'10.10.10.10'
)
ip2
=
ipaddress
.
IPv4Address
(
'10.10.10.11'
)
ip3
=
ipaddress
.
IPv4Address
(
'10.10.10.12'
)
self
.
assertEqual
(
list
(
ipaddress
.
_find_address_range
([
ip1
])),
[(
ip1
,
ip1
)])
self
.
assertEqual
(
list
(
ipaddress
.
_find_address_range
([
ip1
,
ip3
])),
[(
ip1
,
ip1
),
(
ip3
,
ip3
)])
self
.
assertEqual
(
list
(
ipaddress
.
_find_address_range
([
ip1
,
ip2
,
ip3
])),
[(
ip1
,
ip3
)])
self
.
assertEqual
(
128
,
ipaddress
.
_count_righthand_zero_bits
(
0
,
128
))
self
.
assertEqual
(
"IPv4Network('1.2.3.0/24')"
,
repr
(
self
.
ipv4_network
))
...
...
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