Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
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
django
Commits
544b2ef2
Kaydet (Commit)
544b2ef2
authored
Ara 27, 2016
tarafından
roboslone
Kaydeden (comit)
Tim Graham
Ara 27, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27640 -- Fixed HttpResponse's __repr__() without a 'Content-Type' header.
üst
4701abd5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
6 deletions
+24
-6
response.py
django/http/response.py
+10
-6
tests.py
tests/httpwrappers/tests.py
+9
-0
tests.py
tests/responses/tests.py
+5
-0
No files found.
django/http/response.py
Dosyayı görüntüle @
544b2ef2
...
...
@@ -107,6 +107,10 @@ class HttpResponseBase(six.Iterator):
else
:
__str__
=
serialize_headers
@property
def
_content_type_for_repr
(
self
):
return
', "
%
s"'
%
self
[
'Content-Type'
]
if
'Content-Type'
in
self
else
''
def
_convert_to_charset
(
self
,
value
,
charset
,
mime_encode
=
False
):
"""Converts headers key/value to ascii/latin-1 native strings.
...
...
@@ -299,10 +303,10 @@ class HttpResponse(HttpResponseBase):
self
.
content
=
content
def
__repr__
(
self
):
return
'<
%(cls)
s status_code=
%(status_code)
d
, "
%(content_type)
s"
>'
%
{
return
'<
%(cls)
s status_code=
%(status_code)
d
%(content_type)
s
>'
%
{
'cls'
:
self
.
__class__
.
__name__
,
'status_code'
:
self
.
status_code
,
'content_type'
:
self
[
'Content-Type'
]
,
'content_type'
:
self
.
_content_type_for_repr
,
}
def
serialize
(
self
):
...
...
@@ -429,10 +433,10 @@ class HttpResponseRedirectBase(HttpResponse):
url
=
property
(
lambda
self
:
self
[
'Location'
])
def
__repr__
(
self
):
return
'<
%(cls)
s status_code=
%(status_code)
d
, "
%(content_type)
s"
, url="
%(url)
s">'
%
{
return
'<
%(cls)
s status_code=
%(status_code)
d
%(content_type)
s
, url="
%(url)
s">'
%
{
'cls'
:
self
.
__class__
.
__name__
,
'status_code'
:
self
.
status_code
,
'content_type'
:
self
[
'Content-Type'
]
,
'content_type'
:
self
.
_content_type_for_repr
,
'url'
:
self
.
url
,
}
...
...
@@ -479,10 +483,10 @@ class HttpResponseNotAllowed(HttpResponse):
self
[
'Allow'
]
=
', '
.
join
(
permitted_methods
)
def
__repr__
(
self
):
return
'<
%(cls)
s [
%(methods)
s] status_code=
%(status_code)
d
, "
%(content_type)
s"
>'
%
{
return
'<
%(cls)
s [
%(methods)
s] status_code=
%(status_code)
d
%(content_type)
s
>'
%
{
'cls'
:
self
.
__class__
.
__name__
,
'status_code'
:
self
.
status_code
,
'content_type'
:
self
[
'Content-Type'
]
,
'content_type'
:
self
.
_content_type_for_repr
,
'methods'
:
self
[
'Allow'
],
}
...
...
tests/httpwrappers/tests.py
Dosyayı görüntüle @
544b2ef2
...
...
@@ -536,6 +536,10 @@ class HttpResponseSubclassesTests(SimpleTestCase):
response
.
content
=
"Hello dear"
self
.
assertNotIn
(
'content-type'
,
response
)
def
test_not_modified_repr
(
self
):
response
=
HttpResponseNotModified
()
self
.
assertEqual
(
repr
(
response
),
'<HttpResponseNotModified status_code=304>'
)
def
test_not_allowed
(
self
):
response
=
HttpResponseNotAllowed
([
'GET'
])
self
.
assertEqual
(
response
.
status_code
,
405
)
...
...
@@ -548,6 +552,11 @@ class HttpResponseSubclassesTests(SimpleTestCase):
expected
=
'<HttpResponseNotAllowed [GET, OPTIONS] status_code=405, "text/plain">'
self
.
assertEqual
(
repr
(
response
),
expected
)
def
test_not_allowed_repr_no_content_type
(
self
):
response
=
HttpResponseNotAllowed
((
'GET'
,
'POST'
))
del
response
[
'Content-Type'
]
self
.
assertEqual
(
repr
(
response
),
'<HttpResponseNotAllowed [GET, POST] status_code=405>'
)
class
JsonResponseTests
(
SimpleTestCase
):
def
test_json_response_non_ascii
(
self
):
...
...
tests/responses/tests.py
Dosyayı görüntüle @
544b2ef2
...
...
@@ -136,6 +136,11 @@ class HttpResponseTests(SimpleTestCase):
expected
=
'<HttpResponse status_code=201, "text/html; charset=utf-8">'
self
.
assertEqual
(
repr
(
response
),
expected
)
def
test_repr_no_content_type
(
self
):
response
=
HttpResponse
(
status
=
204
)
del
response
[
'Content-Type'
]
self
.
assertEqual
(
repr
(
response
),
'<HttpResponse status_code=204>'
)
def
test_wrap_textiowrapper
(
self
):
content
=
"Café :)"
r
=
HttpResponse
()
...
...
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