Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed some type checks in the development server. Fixed #6063.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6780 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4262765649014b58b6e07c1934f970aa7da9e5d6 1 parent 8de4ed9
Malcolm Tredinnick authored

Showing 1 changed file with 6 additions and 7 deletions. Show diff stats Hide diff stats

  1. 13  django/core/servers/basehttp.py
13  django/core/servers/basehttp.py
@@ -8,7 +8,6 @@
8 8
 """
9 9
 
10 10
 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
11  
-from types import ListType, StringType
12 11
 import mimetypes
13 12
 import os
14 13
 import re
@@ -72,7 +71,7 @@ def _formatparam(param, value=None, quote=1):
72 71
 class Headers(object):
73 72
     """Manage a collection of HTTP response headers"""
74 73
     def __init__(self,headers):
75  
-        if type(headers) is not ListType:
  74
+        if not isinstance(headers, list):
76 75
             raise TypeError("Headers must be a list of name/value tuples")
77 76
         self._headers = headers
78 77
 
@@ -327,7 +326,7 @@ def set_content_length(self):
327 326
         """Compute Content-Length or switch to chunked encoding if possible"""
328 327
         try:
329 328
             blocks = len(self.result)
330  
-        except (TypeError,AttributeError,NotImplementedError):
  329
+        except (TypeError, AttributeError, NotImplementedError):
331 330
             pass
332 331
         else:
333 332
             if blocks==1:
@@ -356,14 +355,14 @@ def start_response(self, status, headers,exc_info=None):
356 355
         elif self.headers is not None:
357 356
             raise AssertionError("Headers already set!")
358 357
 
359  
-        assert type(status) is StringType,"Status must be a string"
  358
+        assert isinstance(status, str),"Status must be a string"
360 359
         assert len(status)>=4,"Status must be at least 4 characters"
361 360
         assert int(status[:3]),"Status message must begin w/3-digit code"
362 361
         assert status[3]==" ", "Status message must have a space after code"
363 362
         if __debug__:
364 363
             for name,val in headers:
365  
-                assert type(name) is StringType,"Header names must be strings"
366  
-                assert type(val) is StringType,"Header values must be strings"
  364
+                assert isinstance(name, str),"Header names must be strings"
  365
+                assert isinstance(val, str),"Header values must be strings"
367 366
                 assert not is_hop_by_hop(name),"Hop-by-hop headers not allowed"
368 367
         self.status = status
369 368
         self.headers = self.headers_class(headers)
@@ -386,7 +385,7 @@ def send_preamble(self):
386 385
     def write(self, data):
387 386
         """'write()' callable as specified by PEP 333"""
388 387
 
389  
-        assert type(data) is StringType,"write() argument must be string"
  388
+        assert isinstance(data, str), "write() argument must be string"
390 389
 
391 390
         if not self.status:
392 391
             raise AssertionError("write() before start_response()")

0 notes on commit 4262765

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