run-dev-proxy: Fix twisted py3 compatibility.

- All necessary strings was converted to bytestring
 - Added twisted as py3 dependency
 - Change type annotation for method getchild of class Resource
 - Remove activating python2 env section from run-dev.py script

Fixes #1256
This commit is contained in:
K.Kanakhin 2016-10-05 14:47:16 +06:00 committed by Tim Abbott
parent 78477ea071
commit 06e70e1fbd
3 changed files with 14 additions and 26 deletions

View File

@ -3,6 +3,9 @@
-r moto.txt
-r py3k.txt
# Needed for running tools/run-dev.py
-r twisted.txt
# Needed to compute test coverage
coverage==4.2

View File

@ -1,5 +1,2 @@
-r py2_common.txt
-r dev.txt
# Needed for running tools/run-dev.py
-r twisted.txt

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python
from __future__ import print_function
import optparse
@ -11,17 +11,6 @@ import os
if False: from typing import Any
# find out python version
major_version = int(subprocess.check_output(['python', '-c', 'import sys; print(sys.version_info[0])']))
if major_version != 2:
# use twisted from its python2 venv but use django, tornado, etc. from the python3 venv.
PATH = os.environ["PATH"]
activate_this = "/srv/zulip-venv/bin/activate_this.py"
if not os.path.exists(activate_this):
activate_this = "/srv/zulip-py2-twisted-venv/bin/activate_this.py"
exec(open(activate_this).read(), {}, dict(__file__=activate_this)) # type: ignore # https://github.com/python/mypy/issues/1577
os.environ["PATH"] = PATH
from twisted.internet import reactor
from twisted.web import proxy, server, resource
@ -139,23 +128,22 @@ for cmd in cmds:
class Resource(resource.Resource):
def getChild(self, name, request):
# type: (str, server.Request) -> resource.Resource
# type: (bytes, server.Request) -> resource.Resource
# Assume an HTTP 1.1 request
proxy_host = request.requestHeaders.getRawHeaders('Host')
request.requestHeaders.setRawHeaders('X-Forwarded-Host', proxy_host)
if (request.uri in [b'/json/get_events'] or
request.uri.startswith(b'/json/events') or
request.uri.startswith(b'/api/v1/events') or
request.uri.startswith(b'/sockjs')):
return proxy.ReverseProxyResource('127.0.0.1', tornado_port, b'/' + name)
if (request.uri in ['/json/get_events'] or
request.uri.startswith('/json/events') or
request.uri.startswith('/api/v1/events') or
request.uri.startswith('/sockjs')):
return proxy.ReverseProxyResource('127.0.0.1', tornado_port, '/'+name)
elif (request.uri.startswith(b'/webpack') or
request.uri.startswith(b'/socket.io')):
return proxy.ReverseProxyResource('127.0.0.1', webpack_port, b'/' + name)
elif (request.uri.startswith('/webpack') or
request.uri.startswith('/socket.io')):
return proxy.ReverseProxyResource('127.0.0.1', webpack_port, '/'+name)
return proxy.ReverseProxyResource('127.0.0.1', django_port, '/'+name)
return proxy.ReverseProxyResource('127.0.0.1', django_port, b'/'+name)
# log which services/ports will be started