mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
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:
@@ -3,6 +3,9 @@
|
|||||||
-r moto.txt
|
-r moto.txt
|
||||||
-r py3k.txt
|
-r py3k.txt
|
||||||
|
|
||||||
|
# Needed for running tools/run-dev.py
|
||||||
|
-r twisted.txt
|
||||||
|
|
||||||
# Needed to compute test coverage
|
# Needed to compute test coverage
|
||||||
coverage==4.2
|
coverage==4.2
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,2 @@
|
|||||||
-r py2_common.txt
|
-r py2_common.txt
|
||||||
-r dev.txt
|
-r dev.txt
|
||||||
|
|
||||||
# Needed for running tools/run-dev.py
|
|
||||||
-r twisted.txt
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import optparse
|
import optparse
|
||||||
@@ -11,17 +11,6 @@ import os
|
|||||||
|
|
||||||
if False: from typing import Any
|
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.internet import reactor
|
||||||
from twisted.web import proxy, server, resource
|
from twisted.web import proxy, server, resource
|
||||||
|
|
||||||
@@ -139,23 +128,22 @@ for cmd in cmds:
|
|||||||
|
|
||||||
class Resource(resource.Resource):
|
class Resource(resource.Resource):
|
||||||
def getChild(self, name, request):
|
def getChild(self, name, request):
|
||||||
# type: (str, server.Request) -> resource.Resource
|
# type: (bytes, server.Request) -> resource.Resource
|
||||||
|
|
||||||
# Assume an HTTP 1.1 request
|
# Assume an HTTP 1.1 request
|
||||||
proxy_host = request.requestHeaders.getRawHeaders('Host')
|
proxy_host = request.requestHeaders.getRawHeaders('Host')
|
||||||
request.requestHeaders.setRawHeaders('X-Forwarded-Host', proxy_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
|
elif (request.uri.startswith(b'/webpack') or
|
||||||
request.uri.startswith('/json/events') or
|
request.uri.startswith(b'/socket.io')):
|
||||||
request.uri.startswith('/api/v1/events') or
|
return proxy.ReverseProxyResource('127.0.0.1', webpack_port, b'/' + name)
|
||||||
request.uri.startswith('/sockjs')):
|
|
||||||
return proxy.ReverseProxyResource('127.0.0.1', tornado_port, '/'+name)
|
|
||||||
|
|
||||||
elif (request.uri.startswith('/webpack') or
|
return proxy.ReverseProxyResource('127.0.0.1', django_port, b'/'+name)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
# log which services/ports will be started
|
# log which services/ports will be started
|
||||||
|
|||||||
Reference in New Issue
Block a user