changeset 84:71ddbf14ae2b

Support strings from application.
author Allan Saddi <allan@saddi.com>
date Thu, 04 Dec 2008 13:55:03 -0800
parents 32cc618c009a
children 59dd8f5b2d07
files flup/server/ajp_base.py
diffstat 1 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/flup/server/ajp_base.py	Thu Dec 04 13:47:17 2008 -0800
     1.2 +++ b/flup/server/ajp_base.py	Thu Dec 04 13:55:03 2008 -0800
     1.3 @@ -846,7 +846,10 @@
     1.4          result = None
     1.5  
     1.6          def write(data):
     1.7 -            assert type(data) is bytes, 'write() argument must be string'
     1.8 +            if type(data) is str:
     1.9 +                data = data.encode('latin-1')
    1.10 +
    1.11 +            assert type(data) is bytes, 'write() argument must be bytes'
    1.12              assert headers_set, 'write() before start_response()'
    1.13  
    1.14              if not headers_sent:
    1.15 @@ -880,17 +883,27 @@
    1.16              else:
    1.17                  assert not headers_set, 'Headers already set!'
    1.18  
    1.19 -            assert type(status) is bytes, 'Status must be a string'
    1.20 -            assert len(status) >= 4, 'Status must be at least 4 characters'
    1.21 +            if type(status) is str:
    1.22 +                status = status.encode('latin-1')
    1.23 +
    1.24 +            assert type(status) is bytes, 'Status must be bytes'
    1.25 +            assert len(status) >= 4, 'Status must be at least 4 bytes'
    1.26              assert int(status[:3]), 'Status must begin with 3-digit code'
    1.27              assert status[3] == 0x20, 'Status must have a space after code'
    1.28              assert type(response_headers) is list, 'Headers must be a list'
    1.29 -            if __debug__:
    1.30 -                for name,val in response_headers:
    1.31 -                    assert type(name) is bytes, 'Header name "%s" must be a string' % name
    1.32 -                    assert type(val) is bytes, 'Value of header "%s" must be a string' % name
    1.33 +            new_response_headers = []
    1.34 +            for name,val in response_headers:
    1.35 +                if type(name) is str:
    1.36 +                    name = name.encode('latin-1')
    1.37 +                if type(val) is str:
    1.38 +                    val = val.encode('latin-1')
    1.39  
    1.40 -            headers_set[:] = [status, response_headers]
    1.41 +                assert type(name) is bytes, 'Header name "%s" must be bytes' % name
    1.42 +                assert type(val) is bytes, 'Value of header "%s" must be bytes' % name
    1.43 +
    1.44 +                new_response_headers.append((name, val))
    1.45 +
    1.46 +            headers_set[:] = [status, new_response_headers]
    1.47              return write
    1.48  
    1.49          if not self.multithreaded: