Commit d630a237 authored by Levin Zimmermann's avatar Levin Zimmermann

fix for py3

parent 9f9294a8
...@@ -95,7 +95,6 @@ def app_wrapper(large_file_threshold=10<<20, webdav_ports=()): ...@@ -95,7 +95,6 @@ def app_wrapper(large_file_threshold=10<<20, webdav_ports=()):
else path_info): else path_info):
start_response('200 OK', (('Content-type', 'text/plain'),)) start_response('200 OK', (('Content-type', 'text/plain'),))
return [dump_threads()] return [dump_threads()]
original_wsgi_input = environ['wsgi.input'] original_wsgi_input = environ['wsgi.input']
if not hasattr(original_wsgi_input, 'seek'): if not hasattr(original_wsgi_input, 'seek'):
# Convert environ['wsgi.input'] to a file-like object. # Convert environ['wsgi.input'] to a file-like object.
...@@ -123,7 +122,6 @@ def app_wrapper(large_file_threshold=10<<20, webdav_ports=()): ...@@ -123,7 +122,6 @@ def app_wrapper(large_file_threshold=10<<20, webdav_ports=()):
) )
return [msg] return [msg]
new_wsgi_input.seek(0) new_wsgi_input.seek(0)
if int(environ['SERVER_PORT']) in webdav_ports: if int(environ['SERVER_PORT']) in webdav_ports:
# Munge the request to ensure that we call manage_FTPGet. # Munge the request to ensure that we call manage_FTPGet.
...@@ -137,7 +135,6 @@ def app_wrapper(large_file_threshold=10<<20, webdav_ports=()): ...@@ -137,7 +135,6 @@ def app_wrapper(large_file_threshold=10<<20, webdav_ports=()):
path_info = posixpath.join(path_info, 'manage_DAVget') path_info = posixpath.join(path_info, 'manage_DAVget')
path_info = posixpath.normpath(path_info) path_info = posixpath.normpath(path_info)
environ['PATH_INFO'] = path_info environ['PATH_INFO'] = path_info
return publish_module(environ, start_response) return publish_module(environ, start_response)
return app return app
...@@ -256,9 +253,10 @@ def runwsgi(): ...@@ -256,9 +253,10 @@ def runwsgi():
from twisted.web.wsgi import WSGIResource from twisted.web.wsgi import WSGIResource
from twisted.internet import protocol, reactor, endpoints from twisted.internet import protocol, reactor, endpoints
from twisted.web import server as twisted_server from twisted.web import server as twisted_server
from io import StringIO
import urllib import urllib
from Products.ERP5Type.Log import log
# I modified runwsgi() without thinking carefully. # I modified runwsgi() without thinking carefully.
# Very dirty code. # Very dirty code.
def runwsgitw(): def runwsgitw():
...@@ -370,10 +368,11 @@ def runwsgitw(): ...@@ -370,10 +368,11 @@ def runwsgitw():
# Make env for a dummy wsgi request # Make env for a dummy wsgi request
# But I really do not know how env should be. # But I really do not know how env should be.
# it is just a workaround. # it is just a workaround.
data = data.decode() # data is b"", we want normal str
# Please check PEP for wsgi. # Please check PEP for wsgi.
env = {} env = {}
stdin = StringIO() stdin = BytesIO()
stderr = StringIO() stderr = BytesIO()
env['wsgi.input'] = stdin env['wsgi.input'] = stdin
env['wsgi.errors'] = stderr env['wsgi.errors'] = stderr
env['wsgi.version'] = (1, 0) env['wsgi.version'] = (1, 0)
...@@ -383,11 +382,13 @@ def runwsgitw(): ...@@ -383,11 +382,13 @@ def runwsgitw():
env['wsgi.url_schema'] = 'http' env['wsgi.url_schema'] = 'http'
env['REQUEST_METHOD'] = 'GET' env['REQUEST_METHOD'] = 'GET'
env['PATH_INFO'] = '/erp5/' + data[:-2]# data has \r\n env['PATH_INFO'] = '/erp5/' + data[:-2]# data has \r\n
env['SERVER_NAME'] = 'localhost'
env['SERVER_PORT'] = '2261' env['SERVER_PORT'] = '2261'
env['SERVER_NAME'] = 'localhost'
env['REMOTE_ADDR'] = ip
env['SERVER_PROTOCOL'] = 'HTTP/1.0' env['SERVER_PROTOCOL'] = 'HTTP/1.0'
result = translogger(env, start_response) result = translogger(env, start_response)
self.transport.write('\n'.join(result)) # We need to send b"" to transport
self.transport.write(b"\n".join(result))
class EchoFactory(protocol.Factory): class EchoFactory(protocol.Factory):
def buildProtocol(self, addr): def buildProtocol(self, addr):
...@@ -397,7 +398,9 @@ def runwsgitw(): ...@@ -397,7 +398,9 @@ def runwsgitw():
endpoints.serverFromString(reactor, "tcp:%s:interface=%s" % (port, ip)).listen(twisted_server.Site(resource)) endpoints.serverFromString(reactor, "tcp:%s:interface=%s" % (port, ip)).listen(twisted_server.Site(resource))
# Add a echo server, this is the key of the POC. # Add a echo server, this is the key of the POC.
endpoints.serverFromString(reactor, "tcp:2261:interface=10.0.244.187").listen(EchoFactory()) # We use the same IP as normal erp5 server, but we switch
# to a different port.
endpoints.serverFromString(reactor, "tcp:2261:interface=%s" % ip).listen(EchoFactory())
# Start main loop. # Start main loop.
reactor.run() reactor.run()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment