annotate MoinMoin/support/flup/client/scgi_app.py @ 5804:2e7f76626b58

update flup to repo tip (no release since 1.0.2 / 2.5y)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 01 Dec 2011 02:38:57 +0100
parents eb463542664e
children
rev   line source
4263
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
1 # Copyright (c) 2006 Allan Saddi <allan@saddi.com>
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
2 # All rights reserved.
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
3 #
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
4 # Redistribution and use in source and binary forms, with or without
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
5 # modification, are permitted provided that the following conditions
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
6 # are met:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
7 # 1. Redistributions of source code must retain the above copyright
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
8 # notice, this list of conditions and the following disclaimer.
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
9 # 2. Redistributions in binary form must reproduce the above copyright
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
10 # notice, this list of conditions and the following disclaimer in the
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
11 # documentation and/or other materials provided with the distribution.
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
12 #
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
13 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
14 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
15 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
16 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
17 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
18 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
19 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
20 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
21 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
22 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
23 # SUCH DAMAGE.
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
24 #
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
25 # $Id$
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
26
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
27 __author__ = 'Allan Saddi <allan@saddi.com>'
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
28 __version__ = '$Revision$'
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
29
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
30 import select
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
31 import struct
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
32 import socket
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
33 import errno
5804
2e7f76626b58 update flup to repo tip (no release since 1.0.2 / 2.5y)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4303
diff changeset
34 import types
4263
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
35
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
36 __all__ = ['SCGIApp']
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
37
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
38 def encodeNetstring(s):
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
39 return ''.join([str(len(s)), ':', s, ','])
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
40
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
41 class SCGIApp(object):
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
42 def __init__(self, connect=None, host=None, port=None,
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
43 filterEnviron=True):
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
44 if host is not None:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
45 assert port is not None
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
46 connect=(host, port)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
47
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
48 assert connect is not None
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
49 self._connect = connect
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
50
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
51 self._filterEnviron = filterEnviron
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
52
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
53 def __call__(self, environ, start_response):
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
54 sock = self._getConnection()
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
55
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
56 outfile = sock.makefile('w')
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
57 infile = sock.makefile('r')
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
58
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
59 sock.close()
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
60
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
61 # Filter WSGI environ and send as request headers
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
62 if self._filterEnviron:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
63 headers = self._defaultFilterEnviron(environ)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
64 else:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
65 headers = self._lightFilterEnviron(environ)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
66 # TODO: Anything not from environ that needs to be sent also?
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
67
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
68 content_length = int(environ.get('CONTENT_LENGTH') or 0)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
69 if headers.has_key('CONTENT_LENGTH'):
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
70 del headers['CONTENT_LENGTH']
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
71
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
72 headers_out = ['CONTENT_LENGTH', str(content_length), 'SCGI', '1']
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
73 for k,v in headers.items():
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
74 headers_out.append(k)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
75 headers_out.append(v)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
76 headers_out.append('') # For trailing NUL
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
77 outfile.write(encodeNetstring('\x00'.join(headers_out)))
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
78
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
79 # Transfer wsgi.input to outfile
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
80 while True:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
81 chunk_size = min(content_length, 4096)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
82 s = environ['wsgi.input'].read(chunk_size)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
83 content_length -= len(s)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
84 outfile.write(s)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
85
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
86 if not s: break
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
87
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
88 outfile.close()
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
89
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
90 # Read result from SCGI server
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
91 result = []
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
92 while True:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
93 buf = infile.read(4096)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
94 if not buf: break
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
95
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
96 result.append(buf)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
97
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
98 infile.close()
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
99
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
100 result = ''.join(result)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
101
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
102 # Parse response headers
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
103 status = '200 OK'
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
104 headers = []
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
105 pos = 0
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
106 while True:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
107 eolpos = result.find('\n', pos)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
108 if eolpos < 0: break
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
109 line = result[pos:eolpos-1]
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
110 pos = eolpos + 1
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
111
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
112 # strip in case of CR. NB: This will also strip other
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
113 # whitespace...
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
114 line = line.strip()
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
115
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
116 # Empty line signifies end of headers
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
117 if not line: break
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
118
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
119 # TODO: Better error handling
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
120 header, value = line.split(':', 1)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
121 header = header.strip().lower()
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
122 value = value.strip()
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
123
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
124 if header == 'status':
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
125 # Special handling of Status header
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
126 status = value
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
127 if status.find(' ') < 0:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
128 # Append a dummy reason phrase if one was not provided
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
129 status += ' SCGIApp'
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
130 else:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
131 headers.append((header, value))
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
132
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
133 result = result[pos:]
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
134
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
135 # Set WSGI status, headers, and return result.
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
136 start_response(status, headers)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
137 return [result]
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
138
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
139 def _getConnection(self):
5804
2e7f76626b58 update flup to repo tip (no release since 1.0.2 / 2.5y)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4303
diff changeset
140 if isinstance(self._connect, types.StringTypes):
4263
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
141 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
5804
2e7f76626b58 update flup to repo tip (no release since 1.0.2 / 2.5y)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4303
diff changeset
142 sock.connect(self._connect)
2e7f76626b58 update flup to repo tip (no release since 1.0.2 / 2.5y)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4303
diff changeset
143 elif hasattr(socket, 'create_connection'):
2e7f76626b58 update flup to repo tip (no release since 1.0.2 / 2.5y)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4303
diff changeset
144 sock = socket.create_connection(self._connect)
4263
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
145 else:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
146 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
5804
2e7f76626b58 update flup to repo tip (no release since 1.0.2 / 2.5y)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4303
diff changeset
147 sock.connect(self._connect)
4263
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
148 return sock
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
149
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
150 _environPrefixes = ['SERVER_', 'HTTP_', 'REQUEST_', 'REMOTE_', 'PATH_',
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
151 'CONTENT_']
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
152 _environCopies = ['SCRIPT_NAME', 'QUERY_STRING', 'AUTH_TYPE']
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
153 _environRenames = {}
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
154
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
155 def _defaultFilterEnviron(self, environ):
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
156 result = {}
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
157 for n in environ.keys():
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
158 for p in self._environPrefixes:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
159 if n.startswith(p):
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
160 result[n] = environ[n]
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
161 if n in self._environCopies:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
162 result[n] = environ[n]
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
163 if n in self._environRenames:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
164 result[self._environRenames[n]] = environ[n]
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
165
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
166 return result
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
167
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
168 def _lightFilterEnviron(self, environ):
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
169 result = {}
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
170 for n in environ.keys():
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
171 if n.upper() == n:
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
172 result[n] = environ[n]
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
173 return result
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
174
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
175 if __name__ == '__main__':
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
176 from flup.server.ajp import WSGIServer
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
177 app = SCGIApp(connect=('localhost', 4000))
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
178 #import paste.lint
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
179 #app = paste.lint.middleware(app)
d40461b9ee6c Imported a current flup with single-thread server patch applied
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
180 WSGIServer(app).run()