run the code formatter over all
This commit is contained in:
@ -7,7 +7,9 @@ class Controller(object):
|
||||
self.request = request
|
||||
self.options = options
|
||||
|
||||
def send_response(self, content, code=200, content_type="text/html", last_modified: datetime = None, max_age=None, headers=None):
|
||||
def send_response(
|
||||
self, content, code=200, content_type="text/html", last_modified: datetime = None, max_age=None, headers=None
|
||||
):
|
||||
self.handler.send_response(code)
|
||||
if headers is None:
|
||||
headers = {}
|
||||
@ -27,7 +29,7 @@ class Controller(object):
|
||||
def send_redirect(self, location, code=303, cookies=None):
|
||||
self.handler.send_response(code)
|
||||
if cookies is not None:
|
||||
self.handler.send_header("Set-Cookie", cookies.output(header=''))
|
||||
self.handler.send_header("Set-Cookie", cookies.output(header=""))
|
||||
self.handler.send_header("Location", location)
|
||||
self.handler.end_headers()
|
||||
|
||||
|
@ -13,9 +13,9 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GzipMixin(object):
|
||||
def send_response(self, content, headers=None, content_type="text/html", *args, **kwargs):
|
||||
def send_response(self, content, headers=None, content_type="text/html", *args, **kwargs):
|
||||
if self.zipable(content_type) and "accept-encoding" in self.request.headers:
|
||||
accepted = [s.strip().lower() for s in self.request.headers['accept-encoding'].split(",")]
|
||||
accepted = [s.strip().lower() for s in self.request.headers["accept-encoding"].split(",")]
|
||||
if "gzip" in accepted:
|
||||
if type(content) == str:
|
||||
content = content.encode()
|
||||
@ -26,11 +26,7 @@ class GzipMixin(object):
|
||||
super().send_response(content, headers=headers, content_type=content_type, *args, **kwargs)
|
||||
|
||||
def zipable(self, content_type):
|
||||
types = [
|
||||
"application/javascript",
|
||||
"text/css",
|
||||
"text/html"
|
||||
]
|
||||
types = ["application/javascript", "text/css", "text/html"]
|
||||
return content_type in types
|
||||
|
||||
def gzip(self, content):
|
||||
@ -41,11 +37,11 @@ class ModificationAwareController(Controller, metaclass=ABCMeta):
|
||||
@abstractmethod
|
||||
def getModified(self, file):
|
||||
pass
|
||||
|
||||
|
||||
def wasModified(self, file):
|
||||
try:
|
||||
modified = self.getModified(file).replace(microsecond=0)
|
||||
|
||||
|
||||
if modified is not None and "If-Modified-Since" in self.handler.headers:
|
||||
client_modified = datetime.strptime(
|
||||
self.handler.headers["If-Modified-Since"], "%a, %d %b %Y %H:%M:%S %Z"
|
||||
@ -54,7 +50,7 @@ class ModificationAwareController(Controller, metaclass=ABCMeta):
|
||||
return False
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@ -143,7 +139,7 @@ class CompiledAssetsController(GzipMixin, ModificationAwareController):
|
||||
"lib/settings/Input.js",
|
||||
"lib/settings/SdrDevice.js",
|
||||
"settings.js",
|
||||
]
|
||||
],
|
||||
}
|
||||
|
||||
def indexAction(self):
|
||||
|
@ -8,15 +8,19 @@ class ReceiverIdController(Controller):
|
||||
super().__init__(handler, request, options)
|
||||
self.authHeader = None
|
||||
|
||||
def send_response(self, content, code=200, content_type="text/html", last_modified: datetime = None, max_age=None, headers=None):
|
||||
def send_response(
|
||||
self, content, code=200, content_type="text/html", last_modified: datetime = None, max_age=None, headers=None
|
||||
):
|
||||
if self.authHeader is not None:
|
||||
if headers is None:
|
||||
headers = {}
|
||||
headers['Authorization'] = self.authHeader
|
||||
super().send_response(content, code=code, content_type=content_type, last_modified=last_modified, max_age=max_age, headers=headers)
|
||||
headers["Authorization"] = self.authHeader
|
||||
super().send_response(
|
||||
content, code=code, content_type=content_type, last_modified=last_modified, max_age=max_age, headers=headers
|
||||
)
|
||||
pass
|
||||
|
||||
def handle_request(self):
|
||||
if "Authorization" in self.request.headers:
|
||||
self.authHeader = ReceiverId.getResponseHeader(self.request.headers['Authorization'])
|
||||
self.authHeader = ReceiverId.getResponseHeader(self.request.headers["Authorization"])
|
||||
super().handle_request()
|
||||
|
@ -69,12 +69,16 @@ class SdrSettingsController(AdminController):
|
||||
{form}
|
||||
</div>
|
||||
</div>
|
||||
""".format(device_name=config["name"], form=self.render_form(device_id, config))
|
||||
""".format(
|
||||
device_name=config["name"], form=self.render_form(device_id, config)
|
||||
)
|
||||
|
||||
def render_form(self, device_id, config):
|
||||
return """
|
||||
<form class="sdrdevice" data-config="{formdata}"></form>
|
||||
""".format(device_id=device_id, formdata=quote(json.dumps(config)))
|
||||
""".format(
|
||||
device_id=device_id, formdata=quote(json.dumps(config))
|
||||
)
|
||||
|
||||
def indexAction(self):
|
||||
self.serve_template("sdrsettings.html", **self.template_variables())
|
||||
@ -119,12 +123,18 @@ class GeneralSettingsController(AdminController):
|
||||
DropdownInput(
|
||||
"audio_compression",
|
||||
"Audio compression",
|
||||
options=[Option("adpcm", "ADPCM"), Option("none", "None"),],
|
||||
options=[
|
||||
Option("adpcm", "ADPCM"),
|
||||
Option("none", "None"),
|
||||
],
|
||||
),
|
||||
DropdownInput(
|
||||
"fft_compression",
|
||||
"Waterfall compression",
|
||||
options=[Option("adpcm", "ADPCM"), Option("none", "None"),],
|
||||
options=[
|
||||
Option("adpcm", "ADPCM"),
|
||||
Option("none", "None"),
|
||||
],
|
||||
),
|
||||
),
|
||||
Section(
|
||||
@ -196,10 +206,7 @@ class GeneralSettingsController(AdminController):
|
||||
"Js8Call decoding depth",
|
||||
infotext="A higher decoding depth will allow more results, but will also consume more cpu",
|
||||
),
|
||||
Js8ProfileCheckboxInput(
|
||||
"js8_enabled_profiles",
|
||||
"Js8Call enabled modes"
|
||||
),
|
||||
Js8ProfileCheckboxInput("js8_enabled_profiles", "Js8Call enabled modes"),
|
||||
),
|
||||
Section(
|
||||
"Background decoding",
|
||||
@ -269,9 +276,7 @@ class GeneralSettingsController(AdminController):
|
||||
|
||||
def processFormData(self):
|
||||
data = parse_qs(self.get_body().decode("utf-8"))
|
||||
data = {
|
||||
k: v for i in GeneralSettingsController.sections for k, v in i.parse(data).items()
|
||||
}
|
||||
data = {k: v for i in GeneralSettingsController.sections for k, v in i.parse(data).items()}
|
||||
config = Config.get()
|
||||
for k, v in data.items():
|
||||
config[k] = v
|
||||
|
@ -22,7 +22,7 @@ class StatusController(ReceiverIdController):
|
||||
"name": receiver.getName(),
|
||||
# TODO would be better to have types from the config here
|
||||
"type": type(receiver).__name__,
|
||||
"profiles": [self.getProfileStats(p) for p in receiver.getProfiles().values()]
|
||||
"profiles": [self.getProfileStats(p) for p in receiver.getProfiles().values()],
|
||||
}
|
||||
return stats
|
||||
|
||||
@ -38,6 +38,6 @@ class StatusController(ReceiverIdController):
|
||||
},
|
||||
"max_clients": pm["max_clients"],
|
||||
"version": openwebrx_version,
|
||||
"sdrs": [self.getReceiverStats(r) for r in SdrService.getSources().values()]
|
||||
"sdrs": [self.getReceiverStats(r) for r in SdrService.getSources().values()],
|
||||
}
|
||||
self.send_response(json.dumps(status), content_type="application/json")
|
||||
|
Reference in New Issue
Block a user