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:
Athanasius 2021-11-04 18:14:01 +00:00
parent 257d3e880a
commit fdee2c054f
No known key found for this signature in database
GPG Key ID: 8C392035DD80FD62
5 changed files with 29 additions and 37 deletions

View File

@ -258,7 +258,7 @@ class EnableCors(object):
name = 'enable_cors'
api = 2
def apply(self, fn: Callable, context: str):
def apply(self, fn: Callable):
"""
Apply CORS headers to the calling bottle app.
@ -286,7 +286,7 @@ class CustomLogging(object):
name = 'custom_logging'
api = 2
def apply(self, fn: Callable, context: str):
def apply(self, fn: Callable):
"""
Apply custom logging to bottle request.

View File

@ -119,7 +119,7 @@ def configure() -> None:
for binding in Settings.GATEWAY_SENDER_BINDINGS:
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))
@ -137,7 +137,7 @@ def push_message(parsed_message: Dict, topic: str) -> None:
# announcers with schema as topic
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)
stats_collector.tally("outbound")
@ -345,14 +345,7 @@ class MalformedUploadError(Exception):
pass
class EnableCors(object):
"""Handle enabling CORS headers in all responses."""
name = 'enable_cors'
api = 2
@staticmethod
def apply(self, fn: Callable, context: str):
def apply_cors() -> None:
"""
Apply CORS headers to the calling bottle app.
@ -360,19 +353,18 @@ class EnableCors(object):
: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'] = \
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'
if request.method != 'OPTIONS':
# actual request; reply with the actual response
return fn(*args, **kwargs)
return _enable_cors
)
def main() -> None:
"""Handle setting up and running the bottle app."""
@ -383,7 +375,7 @@ def main() -> None:
load_config(cl_args)
configure()
app.install(EnableCors())
app.add_hook('after_request', apply_cors)
app.run(
host=Settings.GATEWAY_HTTP_BIND_ADDRESS,
port=Settings.GATEWAY_HTTP_PORT,

View File

@ -285,7 +285,7 @@ class EnableCors(object):
api = 2
@staticmethod
def apply(self, fn: Callable, context: str):
def apply(self, fn: Callable):
"""
Apply a CORS handler.

View File

@ -118,9 +118,9 @@ class Relay(Thread):
# Filters on topics or not...
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)
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)
else:
receiver.setsockopt(zmq.SUBSCRIBE, '')
@ -195,7 +195,7 @@ class EnableCors(object):
api = 2
@staticmethod
def apply(self, fn: Callable, context: str):
def apply(self, fn: Callable):
"""
Apply a CORS handler.

View File

@ -140,7 +140,7 @@ class _Settings(object):
def load_from(self, file_name: str) -> None:
f = open(file_name, 'r')
conf = simplejson.load(f)
for key, value in conf.iteritems():
for key, value in conf.items():
if key in dir(self):
self.__setattr__(key, value)