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
788fa9ff
Kaydet (Commit)
788fa9ff
authored
Kas 20, 2014
tarafından
Berker Peksag
Kaydeden (comit)
Tim Graham
Kas 20, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #12098 -- Simplified HttpRequest.__repr__().
üst
d6e2bbe7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
6 deletions
+27
-6
request.py
django/http/request.py
+5
-1
1.8.txt
docs/releases/1.8.txt
+4
-0
tests.py
tests/requests/tests.py
+18
-5
No files found.
django/http/request.py
Dosyayı görüntüle @
788fa9ff
...
...
@@ -64,7 +64,11 @@ class HttpRequest(object):
self
.
_post_parse_error
=
False
def
__repr__
(
self
):
return
build_request_repr
(
self
)
if
self
.
method
is
None
or
not
self
.
get_full_path
():
return
force_str
(
'<
%
s>'
%
self
.
__class__
.
__name__
)
return
force_str
(
'<
%
s:
%
s
%
r>'
%
(
self
.
__class__
.
__name__
,
self
.
method
,
force_str
(
self
.
get_full_path
()))
)
def
get_host
(
self
):
"""Returns the HTTP host using the environment or request headers."""
...
...
docs/releases/1.8.txt
Dosyayı görüntüle @
788fa9ff
...
...
@@ -777,6 +777,10 @@ Miscellaneous
* Warnings from the MySQL database backend are no longer converted to
exceptions when :setting:`DEBUG` is ``True``.
* :class:`~django.http.HttpRequest` now has a simplified ``repr`` (e.g.
``<WSGIRequest: GET '/somepath/'>``). This won't change the behavior of
the :class:`~django.views.debug.SafeExceptionReporterFilter` class.
.. _deprecated-features-1.8:
Features deprecated in 1.8
...
...
tests/requests/tests.py
Dosyayı görüntüle @
788fa9ff
...
...
@@ -51,15 +51,26 @@ class RequestsTests(SimpleTestCase):
def
test_httprequest_repr
(
self
):
request
=
HttpRequest
()
request
.
path
=
'/somepath/'
request
.
method
=
'GET'
request
.
GET
=
{
'get-key'
:
'get-value'
}
request
.
POST
=
{
'post-key'
:
'post-value'
}
request
.
COOKIES
=
{
'post-key'
:
'post-value'
}
request
.
META
=
{
'post-key'
:
'post-value'
}
self
.
assertEqual
(
repr
(
request
),
str_prefix
(
"<HttpRequest
\n
path:/somepath/,
\n
GET:{
%(_)
s'get-key':
%(_)
s'get-value'},
\n
POST:{
%(_)
s'post-key':
%(_)
s'post-value'},
\n
COOKIES:{
%(_)
s'post-key':
%(_)
s'post-value'},
\n
META:{
%(_)
s'post-key':
%(_)
s'post-value'}
>"
))
self
.
assertEqual
(
build_request_repr
(
request
),
repr
(
request
))
self
.
assertEqual
(
repr
(
request
),
str_prefix
(
"<HttpRequest
: GET '/somepath/'
>"
))
self
.
assertEqual
(
build_request_repr
(
request
),
str_prefix
(
"<HttpRequest
\n
path:/somepath/,
\n
GET:{
%(_)
s'get-key':
%(_)
s'get-value'},
\n
POST:{
%(_)
s'post-key':
%(_)
s'post-value'},
\n
COOKIES:{
%(_)
s'post-key':
%(_)
s'post-value'},
\n
META:{
%(_)
s'post-key':
%(_)
s'post-value'}>"
))
self
.
assertEqual
(
build_request_repr
(
request
,
path_override
=
'/otherpath/'
,
GET_override
=
{
'a'
:
'b'
},
POST_override
=
{
'c'
:
'd'
},
COOKIES_override
=
{
'e'
:
'f'
},
META_override
=
{
'g'
:
'h'
}),
str_prefix
(
"<HttpRequest
\n
path:/otherpath/,
\n
GET:{
%(_)
s'a':
%(_)
s'b'},
\n
POST:{
%(_)
s'c':
%(_)
s'd'},
\n
COOKIES:{
%(_)
s'e':
%(_)
s'f'},
\n
META:{
%(_)
s'g':
%(_)
s'h'}>"
))
def
test_httprequest_repr_invalid_method_and_path
(
self
):
request
=
HttpRequest
()
self
.
assertEqual
(
repr
(
request
),
str_prefix
(
"<HttpRequest>"
))
request
=
HttpRequest
()
request
.
method
=
"GET"
self
.
assertEqual
(
repr
(
request
),
str_prefix
(
"<HttpRequest>"
))
request
=
HttpRequest
()
request
.
path
=
""
self
.
assertEqual
(
repr
(
request
),
str_prefix
(
"<HttpRequest>"
))
def
test_bad_httprequest_repr
(
self
):
"""
If an exception occurs when parsing GET, POST, COOKIES, or META, the
...
...
@@ -74,7 +85,7 @@ class RequestsTests(SimpleTestCase):
for
attr
in
[
'GET'
,
'POST'
,
'COOKIES'
,
'META'
]:
request
=
HttpRequest
()
setattr
(
request
,
attr
,
{
'bomb'
:
bomb
})
self
.
assertIn
(
'
%
s:<could not parse>'
%
attr
,
repr
(
request
))
self
.
assertIn
(
'
%
s:<could not parse>'
%
attr
,
build_request_
repr
(
request
))
def
test_wsgirequest
(
self
):
request
=
WSGIRequest
({
'PATH_INFO'
:
'bogus'
,
'REQUEST_METHOD'
:
'bogus'
,
'wsgi.input'
:
BytesIO
(
b
''
)})
...
...
@@ -125,13 +136,15 @@ class RequestsTests(SimpleTestCase):
self
.
assertEqual
(
request
.
path
,
'/FORCED_PREFIX/somepath/'
)
def
test_wsgirequest_repr
(
self
):
request
=
WSGIRequest
({
'REQUEST_METHOD'
:
'get'
,
'wsgi.input'
:
BytesIO
(
b
''
)})
self
.
assertEqual
(
repr
(
request
),
str_prefix
(
"<WSGIRequest: GET '/'>"
))
request
=
WSGIRequest
({
'PATH_INFO'
:
'/somepath/'
,
'REQUEST_METHOD'
:
'get'
,
'wsgi.input'
:
BytesIO
(
b
''
)})
request
.
GET
=
{
'get-key'
:
'get-value'
}
request
.
POST
=
{
'post-key'
:
'post-value'
}
request
.
COOKIES
=
{
'post-key'
:
'post-value'
}
request
.
META
=
{
'post-key'
:
'post-value'
}
self
.
assertEqual
(
repr
(
request
),
str_prefix
(
"<WSGIRequest
\n
path:/somepath/,
\n
GET:{
%(_)
s'get-key':
%(_)
s'get-value'},
\n
POST:{
%(_)
s'post-key':
%(_)
s'post-value'},
\n
COOKIES:{
%(_)
s'post-key':
%(_)
s'post-value'},
\n
META:{
%(_)
s'post-key':
%(_)
s'post-value'}
>"
))
self
.
assertEqual
(
build_request_repr
(
request
),
repr
(
request
))
self
.
assertEqual
(
repr
(
request
),
str_prefix
(
"<WSGIRequest
: GET '/somepath/'
>"
))
self
.
assertEqual
(
build_request_repr
(
request
),
str_prefix
(
"<WSGIRequest
\n
path:/somepath/,
\n
GET:{
%(_)
s'get-key':
%(_)
s'get-value'},
\n
POST:{
%(_)
s'post-key':
%(_)
s'post-value'},
\n
COOKIES:{
%(_)
s'post-key':
%(_)
s'post-value'},
\n
META:{
%(_)
s'post-key':
%(_)
s'post-value'}>"
))
self
.
assertEqual
(
build_request_repr
(
request
,
path_override
=
'/otherpath/'
,
GET_override
=
{
'a'
:
'b'
},
POST_override
=
{
'c'
:
'd'
},
COOKIES_override
=
{
'e'
:
'f'
},
META_override
=
{
'g'
:
'h'
}),
str_prefix
(
"<WSGIRequest
\n
path:/otherpath/,
\n
GET:{
%(_)
s'a':
%(_)
s'b'},
\n
POST:{
%(_)
s'c':
%(_)
s'd'},
\n
COOKIES:{
%(_)
s'e':
%(_)
s'f'},
\n
META:{
%(_)
s'g':
%(_)
s'h'}>"
))
...
...
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