Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format more files with Ruff #246

Merged
merged 1 commit into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", "powa/powa.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
)
Loading