Skip to content

Commit

Permalink
Format more files with Ruff
Browse files Browse the repository at this point in the history
powa-web and powa.wsgi were not checked by Ruff because the extension
for those files don't match default inclusions.
  • Loading branch information
pgiraud committed Dec 31, 2024
1 parent 92eb058 commit acaeb17
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
1 change: 1 addition & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
line-length = 79
extend-include = ["powa-web", "**/*.wsgi"]

[lint]
# Default `select` is: "E4", "E7", "E9", "F"
Expand Down
38 changes: 25 additions & 13 deletions powa-web
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
#!/usr/bin/env python
import logging
import os
import sys
from powa import make_app
import tornado.ioloop
import logging
from powa import make_app
from tornado.options import options

if __name__ == "__main__":
application = make_app(debug=False, gzip=True, compress_response=True)
logger = logging.getLogger("tornado.application")

if (options.certfile and not options.keyfile or
not options.certfile and options.keyfile):
logger.error("Invalid SSL configuration: you need to provide both "
"certfile and keyfile")
if (
options.certfile
and not options.keyfile
or not options.certfile
and options.keyfile
):
logger.error(
"Invalid SSL configuration: you need to provide both "
"certfile and keyfile"
)
sys.exit(1)

server = application
protocol = "http"
if (options.certfile and options.keyfile):
if options.certfile and options.keyfile:
if not os.path.isfile(options.certfile):
logger.error("Certificate file %s not found", options.certfile)
sys.exit(1)
Expand All @@ -27,14 +33,20 @@ if __name__ == "__main__":
sys.exit(1)

ssl_options = {
'certfile': options.certfile,
'keyfile': options.keyfile,
"certfile": options.certfile,
"keyfile": options.keyfile,
}
server = tornado.httpserver.HTTPServer(application,
ssl_options=ssl_options)
server = tornado.httpserver.HTTPServer(
application, ssl_options=ssl_options
)
protocol = "https"

server.listen(options.port, address=options.address)
logger.info("Starting powa-web on %s://%s:%s%s",
protocol, options.address, options.port, options.url_prefix)
logger.info(
"Starting powa-web on %s://%s:%s%s",
protocol,
options.address,
options.port,
options.url_prefix,
)
tornado.ioloop.IOLoop.instance().start()
11 changes: 7 additions & 4 deletions powa/powa.wsgi
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#!/usr/bin/env python
from powa import make_app
import sys
import tornado
from powa import make_app

if tornado.version > '4':
if tornado.version > "4":
from tornado.wsgi import WSGIAdapter

application = make_app(debug=False, gzip=True, compress_response=True)
application = WSGIAdapter(application)
else:
# Wrap sys.stderr because certain versions of mod_wsgi don't
# implement isatty for the log file, and certain versions
# of tornado don't check for the existence of isatty
if not hasattr(sys.stderr, "isatty"):
class StdErrWrapper(object):

class StdErrWrapper(object):
def __init__(self, wrapped):
super(StdErrWrapper, self).__setattr__("wrapped", wrapped)

Expand All @@ -29,4 +30,6 @@ else:
return setattr(self.wrapped, att, value)

sys.stderr = StdErrWrapper(sys.stderr)
application = make_app(debug=False, gzip=True, compress_response=True, legacy_wsgi=True)
application = make_app(
debug=False, gzip=True, compress_response=True, legacy_wsgi=True
)

0 comments on commit acaeb17

Please sign in to comment.