mirror of
https://github.com/EDCD/EDDN.git
synced 2025-06-17 15:51:01 +03:00
python3: Gateway now working
Now I'm actually trying to run the code I'm finding more that needs changing in order to run under python3
This commit is contained in:
parent
257d3e880a
commit
fdee2c054f
@ -258,7 +258,7 @@ class EnableCors(object):
|
|||||||
name = 'enable_cors'
|
name = 'enable_cors'
|
||||||
api = 2
|
api = 2
|
||||||
|
|
||||||
def apply(self, fn: Callable, context: str):
|
def apply(self, fn: Callable):
|
||||||
"""
|
"""
|
||||||
Apply CORS headers to the calling bottle app.
|
Apply CORS headers to the calling bottle app.
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ class CustomLogging(object):
|
|||||||
name = 'custom_logging'
|
name = 'custom_logging'
|
||||||
api = 2
|
api = 2
|
||||||
|
|
||||||
def apply(self, fn: Callable, context: str):
|
def apply(self, fn: Callable):
|
||||||
"""
|
"""
|
||||||
Apply custom logging to bottle request.
|
Apply custom logging to bottle request.
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ def configure() -> None:
|
|||||||
for binding in Settings.GATEWAY_SENDER_BINDINGS:
|
for binding in Settings.GATEWAY_SENDER_BINDINGS:
|
||||||
sender.bind(binding)
|
sender.bind(binding)
|
||||||
|
|
||||||
for schema_ref, schema_file in Settings.GATEWAY_JSON_SCHEMAS.iteritems():
|
for schema_ref, schema_file in Settings.GATEWAY_JSON_SCHEMAS.items():
|
||||||
validator.add_schema_resource(schema_ref, resource_string('eddn.Gateway', schema_file))
|
validator.add_schema_resource(schema_ref, resource_string('eddn.Gateway', schema_file))
|
||||||
|
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ def push_message(parsed_message: Dict, topic: str) -> None:
|
|||||||
# announcers with schema as topic
|
# announcers with schema as topic
|
||||||
compressed_msg = zlib.compress(string_message)
|
compressed_msg = zlib.compress(string_message)
|
||||||
|
|
||||||
send_message = f"{str(topic)!r} |-| {compressed_msg!r}"
|
send_message = f"{str(topic)!r} |-| {compressed_msg!r}".encode('utf8')
|
||||||
|
|
||||||
sender.send(send_message)
|
sender.send(send_message)
|
||||||
stats_collector.tally("outbound")
|
stats_collector.tally("outbound")
|
||||||
@ -345,34 +345,26 @@ class MalformedUploadError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class EnableCors(object):
|
def apply_cors() -> None:
|
||||||
"""Handle enabling CORS headers in all responses."""
|
"""
|
||||||
|
Apply CORS headers to the calling bottle app.
|
||||||
name = 'enable_cors'
|
|
||||||
api = 2
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def apply(self, fn: Callable, context: str):
|
|
||||||
"""
|
|
||||||
Apply CORS headers to the calling bottle app.
|
|
||||||
|
|
||||||
:param fn:
|
|
||||||
:param context:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
def _enable_cors(*args, **kwargs):
|
|
||||||
# set CORS headers
|
|
||||||
response.headers['Access-Control-Allow-Origin'] = '*'
|
|
||||||
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'
|
|
||||||
response.headers['Access-Control-Allow-Headers'] = \
|
|
||||||
'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
|
|
||||||
|
|
||||||
if request.method != 'OPTIONS':
|
|
||||||
# actual request; reply with the actual response
|
|
||||||
return fn(*args, **kwargs)
|
|
||||||
|
|
||||||
return _enable_cors
|
|
||||||
|
|
||||||
|
:param fn:
|
||||||
|
:param context:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
response.set_header(
|
||||||
|
'Access-Control-Allow-Origin',
|
||||||
|
'*'
|
||||||
|
)
|
||||||
|
response.set_header(
|
||||||
|
'Access-Control-Allow-Methods',
|
||||||
|
'GET, POST, PUT, OPTIONS'
|
||||||
|
)
|
||||||
|
response.set_header(
|
||||||
|
'Access-Control-Allow-Headers',
|
||||||
|
'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
|
||||||
|
)
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""Handle setting up and running the bottle app."""
|
"""Handle setting up and running the bottle app."""
|
||||||
@ -383,7 +375,7 @@ def main() -> None:
|
|||||||
load_config(cl_args)
|
load_config(cl_args)
|
||||||
configure()
|
configure()
|
||||||
|
|
||||||
app.install(EnableCors())
|
app.add_hook('after_request', apply_cors)
|
||||||
app.run(
|
app.run(
|
||||||
host=Settings.GATEWAY_HTTP_BIND_ADDRESS,
|
host=Settings.GATEWAY_HTTP_BIND_ADDRESS,
|
||||||
port=Settings.GATEWAY_HTTP_PORT,
|
port=Settings.GATEWAY_HTTP_PORT,
|
||||||
|
@ -285,7 +285,7 @@ class EnableCors(object):
|
|||||||
api = 2
|
api = 2
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def apply(self, fn: Callable, context: str):
|
def apply(self, fn: Callable):
|
||||||
"""
|
"""
|
||||||
Apply a CORS handler.
|
Apply a CORS handler.
|
||||||
|
|
||||||
|
@ -118,9 +118,9 @@ class Relay(Thread):
|
|||||||
|
|
||||||
# Filters on topics or not...
|
# Filters on topics or not...
|
||||||
if Settings.RELAY_RECEIVE_ONLY_GATEWAY_EXTRA_JSON is True:
|
if Settings.RELAY_RECEIVE_ONLY_GATEWAY_EXTRA_JSON is True:
|
||||||
for schema_ref, schema_file in Settings.GATEWAY_JSON_SCHEMAS.iteritems():
|
for schema_ref, schema_file in Settings.GATEWAY_JSON_SCHEMAS.items():
|
||||||
receiver.setsockopt(zmq.SUBSCRIBE, schema_ref)
|
receiver.setsockopt(zmq.SUBSCRIBE, schema_ref)
|
||||||
for schema_ref, schema_file in Settings.RELAY_EXTRA_JSON_SCHEMAS.iteritems():
|
for schema_ref, schema_file in Settings.RELAY_EXTRA_JSON_SCHEMAS.items():
|
||||||
receiver.setsockopt(zmq.SUBSCRIBE, schema_ref)
|
receiver.setsockopt(zmq.SUBSCRIBE, schema_ref)
|
||||||
else:
|
else:
|
||||||
receiver.setsockopt(zmq.SUBSCRIBE, '')
|
receiver.setsockopt(zmq.SUBSCRIBE, '')
|
||||||
@ -195,7 +195,7 @@ class EnableCors(object):
|
|||||||
api = 2
|
api = 2
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def apply(self, fn: Callable, context: str):
|
def apply(self, fn: Callable):
|
||||||
"""
|
"""
|
||||||
Apply a CORS handler.
|
Apply a CORS handler.
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ class _Settings(object):
|
|||||||
def load_from(self, file_name: str) -> None:
|
def load_from(self, file_name: str) -> None:
|
||||||
f = open(file_name, 'r')
|
f = open(file_name, 'r')
|
||||||
conf = simplejson.load(f)
|
conf = simplejson.load(f)
|
||||||
for key, value in conf.iteritems():
|
for key, value in conf.items():
|
||||||
if key in dir(self):
|
if key in dir(self):
|
||||||
self.__setattr__(key, value)
|
self.__setattr__(key, value)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user