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
9a982d5c
Kaydet (Commit)
9a982d5c
authored
10 years ago
tarafından
Ramiro Morales
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Moved ServerHandler helper class to tests.
It has been only used in the builtin_servers tests since Django 1.4.
üst
cb5dd99b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
50 deletions
+49
-50
basehttp.py
django/core/servers/basehttp.py
+1
-49
tests.py
tests/builtin_server/tests.py
+48
-1
No files found.
django/core/servers/basehttp.py
Dosyayı görüntüle @
9a982d5c
...
...
@@ -9,10 +9,8 @@ been reviewed for security issues. DON'T USE IT FOR PRODUCTION USE!
from
__future__
import
unicode_literals
from
io
import
BytesIO
import
socket
import
sys
import
traceback
from
wsgiref
import
simple_server
from
wsgiref.util
import
FileWrapper
# NOQA: for backwards compatibility
...
...
@@ -23,13 +21,7 @@ from django.utils import six
from
django.utils.module_loading
import
import_string
from
django.utils.six.moves
import
socketserver
__all__
=
(
'WSGIServer'
,
'WSGIRequestHandler'
,
'MAX_SOCKET_CHUNK_SIZE'
)
# If data is too large, socket will choke, so write chunks no larger than 32MB
# at a time. The rationale behind the 32MB can be found on Django's Trac:
# https://code.djangoproject.com/ticket/5596#comment:4
MAX_SOCKET_CHUNK_SIZE
=
32
*
1024
*
1024
# 32 MB
__all__
=
(
'WSGIServer'
,
'WSGIRequestHandler'
)
def
get_internal_wsgi_application
():
...
...
@@ -66,46 +58,6 @@ def get_internal_wsgi_application():
sys
.
exc_info
()[
2
])
class
ServerHandler
(
simple_server
.
ServerHandler
,
object
):
error_status
=
str
(
"500 INTERNAL SERVER ERROR"
)
def
write
(
self
,
data
):
"""'write()' callable as specified by PEP 3333"""
assert
isinstance
(
data
,
bytes
),
"write() argument must be bytestring"
if
not
self
.
status
:
raise
AssertionError
(
"write() before start_response()"
)
elif
not
self
.
headers_sent
:
# Before the first output, send the stored headers
self
.
bytes_sent
=
len
(
data
)
# make sure we know content-length
self
.
send_headers
()
else
:
self
.
bytes_sent
+=
len
(
data
)
# XXX check Content-Length and truncate if too many bytes written?
data
=
BytesIO
(
data
)
for
chunk
in
iter
(
lambda
:
data
.
read
(
MAX_SOCKET_CHUNK_SIZE
),
b
''
):
self
.
_write
(
chunk
)
self
.
_flush
()
def
error_output
(
self
,
environ
,
start_response
):
super
(
ServerHandler
,
self
)
.
error_output
(
environ
,
start_response
)
return
[
'
\n
'
.
join
(
traceback
.
format_exception
(
*
sys
.
exc_info
()))]
# Backport of http://hg.python.org/cpython/rev/d5af1b235dab. See #16241.
# This can be removed when support for Python <= 2.7.3 is deprecated.
def
finish_response
(
self
):
try
:
if
not
self
.
result_is_file
()
or
not
self
.
sendfile
():
for
data
in
self
.
result
:
self
.
write
(
data
)
self
.
finish_content
()
finally
:
self
.
close
()
class
WSGIServer
(
simple_server
.
WSGIServer
,
object
):
"""BaseHTTPServer that implements the Python WSGI protocol"""
...
...
This diff is collapsed.
Click to expand it.
tests/builtin_server/tests.py
Dosyayı görüntüle @
9a982d5c
from
__future__
import
unicode_literals
from
io
import
BytesIO
import
sys
import
traceback
from
unittest
import
TestCase
from
wsgiref
import
simple_server
from
django.core.servers.basehttp
import
ServerHandler
,
MAX_SOCKET_CHUNK_SIZE
# If data is too large, socket will choke, so write chunks no larger than 32MB
# at a time. The rationale behind the 32MB can be found on Django's Trac:
# https://code.djangoproject.com/ticket/5596#comment:4
MAX_SOCKET_CHUNK_SIZE
=
32
*
1024
*
1024
# 32 MB
class
ServerHandler
(
simple_server
.
ServerHandler
,
object
):
error_status
=
str
(
"500 INTERNAL SERVER ERROR"
)
def
write
(
self
,
data
):
"""'write()' callable as specified by PEP 3333"""
assert
isinstance
(
data
,
bytes
),
"write() argument must be bytestring"
if
not
self
.
status
:
raise
AssertionError
(
"write() before start_response()"
)
elif
not
self
.
headers_sent
:
# Before the first output, send the stored headers
self
.
bytes_sent
=
len
(
data
)
# make sure we know content-length
self
.
send_headers
()
else
:
self
.
bytes_sent
+=
len
(
data
)
# XXX check Content-Length and truncate if too many bytes written?
data
=
BytesIO
(
data
)
for
chunk
in
iter
(
lambda
:
data
.
read
(
MAX_SOCKET_CHUNK_SIZE
),
b
''
):
self
.
_write
(
chunk
)
self
.
_flush
()
def
error_output
(
self
,
environ
,
start_response
):
super
(
ServerHandler
,
self
)
.
error_output
(
environ
,
start_response
)
return
[
'
\n
'
.
join
(
traceback
.
format_exception
(
*
sys
.
exc_info
()))]
# Backport of http://hg.python.org/cpython/rev/d5af1b235dab. See #16241.
# This can be removed when support for Python <= 2.7.3 is deprecated.
def
finish_response
(
self
):
try
:
if
not
self
.
result_is_file
()
or
not
self
.
sendfile
():
for
data
in
self
.
result
:
self
.
write
(
data
)
self
.
finish_content
()
finally
:
self
.
close
()
class
DummyHandler
(
object
):
...
...
This diff is collapsed.
Click to expand it.
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