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
9f8dc444
Kaydet (Commit)
9f8dc444
authored
Agu 02, 2010
tarafından
Senthil Kumaran
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix Issue8572 - httplib getheader() throws error instead of default
üst
aed05eb6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
3 deletions
+45
-3
http.client.rst
Doc/library/http.client.rst
+2
-1
client.py
Lib/http/client.py
+5
-1
test_httplib.py
Lib/test/test_httplib.py
+38
-1
No files found.
Doc/library/http.client.rst
Dosyayı görüntüle @
9f8dc444
...
...
@@ -466,7 +466,8 @@ statement.
.. method:: HTTPResponse.getheader(name, default=None)
Get the contents of the header *name*, or *default* if there is no matching
header.
header. If *default* is an iterator other than a string, then the return
value will be a string consisting of items of the iterator joined by comma.
.. method:: HTTPResponse.getheaders()
...
...
Lib/http/client.py
Dosyayı görüntüle @
9f8dc444
...
...
@@ -602,7 +602,11 @@ class HTTPResponse(io.RawIOBase):
def
getheader
(
self
,
name
,
default
=
None
):
if
self
.
headers
is
None
:
raise
ResponseNotReady
()
return
', '
.
join
(
self
.
headers
.
get_all
(
name
,
default
))
headers
=
self
.
headers
.
get_all
(
name
)
or
default
if
isinstance
(
headers
,
str
)
or
not
hasattr
(
headers
,
'__iter__'
):
return
headers
else
:
return
', '
.
join
(
headers
)
def
getheaders
(
self
):
"""Return list of (header, value) tuples."""
...
...
Lib/test/test_httplib.py
Dosyayı görüntüle @
9f8dc444
...
...
@@ -442,9 +442,46 @@ class RequestBodyTest(TestCase):
self
.
assertEqual
(
"5"
,
message
.
get
(
"content-length"
))
self
.
assertEqual
(
b
'body
\xc1
'
,
f
.
read
())
class
HTTPResponseTest
(
TestCase
):
def
setUp
(
self
):
body
=
"HTTP/1.1 200 Ok
\r\n
My-Header: first-value
\r\n
My-Header:
\
second-value
\r\n\r\n
Text"
sock
=
FakeSocket
(
body
)
self
.
resp
=
client
.
HTTPResponse
(
sock
)
self
.
resp
.
begin
()
def
test_getting_header
(
self
):
header
=
self
.
resp
.
getheader
(
'My-Header'
)
self
.
assertEqual
(
header
,
'first-value, second-value'
)
header
=
self
.
resp
.
getheader
(
'My-Header'
,
'some default'
)
self
.
assertEqual
(
header
,
'first-value, second-value'
)
def
test_getting_nonexistent_header_with_string_default
(
self
):
header
=
self
.
resp
.
getheader
(
'No-Such-Header'
,
'default-value'
)
self
.
assertEqual
(
header
,
'default-value'
)
def
test_getting_nonexistent_header_with_iterable_default
(
self
):
header
=
self
.
resp
.
getheader
(
'No-Such-Header'
,
[
'default'
,
'values'
])
self
.
assertEqual
(
header
,
'default, values'
)
header
=
self
.
resp
.
getheader
(
'No-Such-Header'
,
(
'default'
,
'values'
))
self
.
assertEqual
(
header
,
'default, values'
)
def
test_getting_nonexistent_header_without_default
(
self
):
header
=
self
.
resp
.
getheader
(
'No-Such-Header'
)
self
.
assertEqual
(
header
,
None
)
def
test_getting_header_defaultint
(
self
):
header
=
self
.
resp
.
getheader
(
'No-Such-Header'
,
default
=
42
)
self
.
assertEqual
(
header
,
42
)
def
test_main
(
verbose
=
None
):
support
.
run_unittest
(
HeaderTests
,
OfflineTest
,
BasicTest
,
TimeoutTest
,
HTTPSTimeoutTest
,
RequestBodyTest
,
SourceAddressTest
)
HTTPSTimeoutTest
,
RequestBodyTest
,
SourceAddressTest
,
HTTPResponseTest
)
if
__name__
==
'__main__'
:
test_main
()
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