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
dfa95c9a
Kaydet (Commit)
dfa95c9a
authored
Agu 09, 2015
tarafından
Robert Collins
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #20059: urllib.parse raises ValueError on all invalid ports.
Patch by Martin Panter.
üst
846a1487
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
26 deletions
+39
-26
urllib.parse.rst
Doc/library/urllib.parse.rst
+14
-4
3.6.rst
Doc/whatsnew/3.6.rst
+4
-1
test_urlparse.py
Lib/test/test_urlparse.py
+17
-19
parse.py
Lib/urllib/parse.py
+1
-2
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/urllib.parse.rst
Dosyayı görüntüle @
dfa95c9a
...
@@ -115,8 +115,9 @@ or on combining URL components into a URL string.
...
@@ -115,8 +115,9 @@ or on combining URL components into a URL string.
| | | if present | |
| | | if present | |
+------------------+-------+--------------------------+----------------------+
+------------------+-------+--------------------------+----------------------+
See section :ref:`urlparse-result-object` for more information on the result
Reading the :attr:`port` attribute will raise a :exc:`ValueError` if
object.
an invalid port is specified in the URL. See section
:ref:`urlparse-result-object` for more information on the result object.
.. versionchanged:: 3.2
.. versionchanged:: 3.2
Added IPv6 URL parsing capabilities.
Added IPv6 URL parsing capabilities.
...
@@ -126,6 +127,10 @@ or on combining URL components into a URL string.
...
@@ -126,6 +127,10 @@ or on combining URL components into a URL string.
false), in accordance with :rfc:`3986`. Previously, a whitelist of
false), in accordance with :rfc:`3986`. Previously, a whitelist of
schemes that support fragments existed.
schemes that support fragments existed.
.. versionchanged:: 3.6
Out-of-range port numbers now raise :exc:`ValueError`, instead of
returning :const:`None`.
.. function:: parse_qs(qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace')
.. function:: parse_qs(qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace')
...
@@ -228,8 +233,13 @@ or on combining URL components into a URL string.
...
@@ -228,8 +233,13 @@ or on combining URL components into a URL string.
| | | if present | |
| | | if present | |
+------------------+-------+-------------------------+----------------------+
+------------------+-------+-------------------------+----------------------+
See section :ref:`urlparse-result-object` for more information on the result
Reading the :attr:`port` attribute will raise a :exc:`ValueError` if
object.
an invalid port is specified in the URL. See section
:ref:`urlparse-result-object` for more information on the result object.
.. versionchanged:: 3.6
Out-of-range port numbers now raise :exc:`ValueError`, instead of
returning :const:`None`.
.. function:: urlunsplit(parts)
.. function:: urlunsplit(parts)
...
...
Doc/whatsnew/3.6.rst
Dosyayı görüntüle @
dfa95c9a
...
@@ -162,7 +162,10 @@ that may require changes to your code.
...
@@ -162,7 +162,10 @@ that may require changes to your code.
Changes in the Python API
Changes in the Python API
-------------------------
-------------------------
* None yet.
* Reading the :attr:`~urllib.parse.SplitResult.port` attribute of
:func:`urllib.parse.urlsplit` and :func:`~urllib.parse.urlparse` results
now raises :exc:`ValueError` for out-of-range values, rather than
returning :const:`None`. See :issue:`20059`.
Changes in the C API
Changes in the C API
...
...
Lib/test/test_urlparse.py
Dosyayı görüntüle @
dfa95c9a
...
@@ -554,29 +554,27 @@ class UrlParseTestCase(unittest.TestCase):
...
@@ -554,29 +554,27 @@ class UrlParseTestCase(unittest.TestCase):
self
.
assertEqual
(
p
.
port
,
80
)
self
.
assertEqual
(
p
.
port
,
80
)
self
.
assertEqual
(
p
.
geturl
(),
url
)
self
.
assertEqual
(
p
.
geturl
(),
url
)
# Verify an illegal port
is returned as None
# Verify an illegal port
raises ValueError
url
=
b
"HTTP://WWW.PYTHON.ORG:65536/doc/#frag"
url
=
b
"HTTP://WWW.PYTHON.ORG:65536/doc/#frag"
p
=
urllib
.
parse
.
urlsplit
(
url
)
p
=
urllib
.
parse
.
urlsplit
(
url
)
self
.
assertEqual
(
p
.
port
,
None
)
with
self
.
assertRaisesRegex
(
ValueError
,
"out of range"
):
p
.
port
def
test_attributes_bad_port
(
self
):
def
test_attributes_bad_port
(
self
):
"""Check handling of non-integer ports."""
"""Check handling of invalid ports."""
p
=
urllib
.
parse
.
urlsplit
(
"http://www.example.net:foo"
)
for
bytes
in
(
False
,
True
):
self
.
assertEqual
(
p
.
netloc
,
"www.example.net:foo"
)
for
parse
in
(
urllib
.
parse
.
urlsplit
,
urllib
.
parse
.
urlparse
):
self
.
assertRaises
(
ValueError
,
lambda
:
p
.
port
)
for
port
in
(
"foo"
,
"1.5"
,
"-1"
,
"0x10"
):
with
self
.
subTest
(
bytes
=
bytes
,
parse
=
parse
,
port
=
port
):
p
=
urllib
.
parse
.
urlparse
(
"http://www.example.net:foo"
)
netloc
=
"www.example.net:"
+
port
self
.
assertEqual
(
p
.
netloc
,
"www.example.net:foo"
)
url
=
"http://"
+
netloc
self
.
assertRaises
(
ValueError
,
lambda
:
p
.
port
)
if
bytes
:
netloc
=
netloc
.
encode
(
"ascii"
)
# Once again, repeat ourselves to test bytes
url
=
url
.
encode
(
"ascii"
)
p
=
urllib
.
parse
.
urlsplit
(
b
"http://www.example.net:foo"
)
p
=
parse
(
url
)
self
.
assertEqual
(
p
.
netloc
,
b
"www.example.net:foo"
)
self
.
assertEqual
(
p
.
netloc
,
netloc
)
self
.
assertRaises
(
ValueError
,
lambda
:
p
.
port
)
with
self
.
assertRaises
(
ValueError
):
p
.
port
p
=
urllib
.
parse
.
urlparse
(
b
"http://www.example.net:foo"
)
self
.
assertEqual
(
p
.
netloc
,
b
"www.example.net:foo"
)
self
.
assertRaises
(
ValueError
,
lambda
:
p
.
port
)
def
test_attributes_without_netloc
(
self
):
def
test_attributes_without_netloc
(
self
):
# This example is straight from RFC 3261. It looks like it
# This example is straight from RFC 3261. It looks like it
...
...
Lib/urllib/parse.py
Dosyayı görüntüle @
dfa95c9a
...
@@ -156,9 +156,8 @@ class _NetlocResultMixinBase(object):
...
@@ -156,9 +156,8 @@ class _NetlocResultMixinBase(object):
port
=
self
.
_hostinfo
[
1
]
port
=
self
.
_hostinfo
[
1
]
if
port
is
not
None
:
if
port
is
not
None
:
port
=
int
(
port
,
10
)
port
=
int
(
port
,
10
)
# Return None on an illegal port
if
not
(
0
<=
port
<=
65535
):
if
not
(
0
<=
port
<=
65535
):
r
eturn
None
r
aise
ValueError
(
"Port out of range 0-65535"
)
return
port
return
port
...
...
Misc/NEWS
Dosyayı görüntüle @
dfa95c9a
...
@@ -15,6 +15,9 @@ Core and Builtins
...
@@ -15,6 +15,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #20059: urllib.parse raises ValueError on all invalid ports.
Patch by Martin Panter.
- Issue #24824: Signatures of codecs.encode() and codecs.decode() now are
- Issue #24824: Signatures of codecs.encode() and codecs.decode() now are
compatible with pydoc.
compatible with pydoc.
...
...
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