Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[py3] Ported django.core.servers.

  • Loading branch information...
commit fcc8de0598f5a2024ad8a49e9bc38912b9511ca7 1 parent 8c356ac
Aymeric Augustin aaugustin authored
8 django/core/servers/basehttp.py
View
@@ -7,6 +7,8 @@
been reviewed for security issues. DON'T USE IT FOR PRODUCTION USE!
"""
+from __future__ import unicode_literals

Breaks the usage of type() and strings in python 2.7

Traceback (most recent call last):
  File "/django/core/management/commands/runserver.py", line 111, in inner_run
    ipv6=self.use_ipv6, threading=threading)
  File "/django/core/servers/basehttp.py", line 205, in run
    httpd_cls = type('WSGIServer', (socketserver.ThreadingMixIn, WSGIServer), {})
TypeError: type() argument 1 must be string, not unicode
Aymeric Augustin Owner

Fixed in d739d53. Good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
import os
import socket
import sys
@@ -71,12 +73,12 @@ class WSGIServerException(Exception):
class ServerHandler(simple_server.ServerHandler, object):
- error_status = "500 INTERNAL SERVER ERROR"
+ error_status = str("500 INTERNAL SERVER ERROR")
def write(self, data):
- """'write()' callable as specified by PEP 333"""
+ """'write()' callable as specified by PEP 3333"""
- assert isinstance(data, str), "write() argument must be string"
+ assert isinstance(data, bytes), "write() argument must be bytestring"
if not self.status:
raise AssertionError("write() before start_response()")
24 tests/regressiontests/builtin_server/tests.py
View
@@ -1,5 +1,8 @@
+from __future__ import unicode_literals
+
+from io import BytesIO
+
from django.core.servers.basehttp import ServerHandler
-from django.utils.six import StringIO
from django.utils.unittest import TestCase
#
@@ -23,12 +26,12 @@ def sendfile(self):
return True
def wsgi_app(environ, start_response):
- start_response('200 OK', [('Content-Type', 'text/plain')])
- return ['Hello World!']
+ start_response(str('200 OK'), [(str('Content-Type'), str('text/plain'))])
+ return [b'Hello World!']
def wsgi_app_file_wrapper(environ, start_response):
- start_response('200 OK', [('Content-Type', 'text/plain')])
- return environ['wsgi.file_wrapper'](StringIO('foo'))
+ start_response(str('200 OK'), [(str('Content-Type'), str('text/plain'))])
+ return environ['wsgi.file_wrapper'](BytesIO(b'foo'))
class WSGIFileWrapperTests(TestCase):
"""
@@ -37,15 +40,16 @@ class WSGIFileWrapperTests(TestCase):
def test_file_wrapper_uses_sendfile(self):
env = {'SERVER_PROTOCOL': 'HTTP/1.0'}
- err = StringIO()
- handler = FileWrapperHandler(None, StringIO(), err, env)
+ handler = FileWrapperHandler(None, BytesIO(), BytesIO(), env)
handler.run(wsgi_app_file_wrapper)
self.assertTrue(handler._used_sendfile)
+ self.assertEqual(handler.stdout.getvalue(), b'')
+ self.assertEqual(handler.stderr.getvalue(), b'')
def test_file_wrapper_no_sendfile(self):
env = {'SERVER_PROTOCOL': 'HTTP/1.0'}
- err = StringIO()
- handler = FileWrapperHandler(None, StringIO(), err, env)
+ handler = FileWrapperHandler(None, BytesIO(), BytesIO(), env)
handler.run(wsgi_app)
self.assertFalse(handler._used_sendfile)
- self.assertEqual(handler.stdout.getvalue().splitlines()[-1],'Hello World!')
+ self.assertEqual(handler.stdout.getvalue().splitlines()[-1], b'Hello World!')
+ self.assertEqual(handler.stderr.getvalue(), b'')
George Marshall

Breaks the usage of type() and strings in python 2.7

Traceback (most recent call last):
  File "/django/core/management/commands/runserver.py", line 111, in inner_run
    ipv6=self.use_ipv6, threading=threading)
  File "/django/core/servers/basehttp.py", line 205, in run
    httpd_cls = type('WSGIServer', (socketserver.ThreadingMixIn, WSGIServer), {})
TypeError: type() argument 1 must be string, not unicode
Aymeric Augustin

Fixed in d739d53. Good catch!

Please sign in to comment.
Something went wrong with that request. Please try again.