mirror of
https://github.com/sprockets/sprockets.http.git
synced 2024-11-14 11:19:26 +00:00
Use python 3 super
This commit is contained in:
parent
11bc7079c0
commit
a981861bf1
6 changed files with 21 additions and 21 deletions
|
@ -54,7 +54,7 @@ class instead of writing a ``make_app`` function:
|
||||||
handlers = [
|
handlers = [
|
||||||
# insert your handlers
|
# insert your handlers
|
||||||
]
|
]
|
||||||
super(Application, self).__init__(handlers, *args, **kwargs)
|
super().__init__(handlers, *args, **kwargs)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sprockets.http.run(Application)
|
sprockets.http.run(Application)
|
||||||
|
|
|
@ -43,7 +43,7 @@ when the application starts.
|
||||||
handlers = [
|
handlers = [
|
||||||
# insert your handlers here
|
# insert your handlers here
|
||||||
]
|
]
|
||||||
super(Application, self).__init__(handlers, *args, **kwargs)
|
super().__init__(handlers, *args, **kwargs)
|
||||||
self.ready_to_serve = locks.Event()
|
self.ready_to_serve = locks.Event()
|
||||||
self.ready_to_serve.clear()
|
self.ready_to_serve.clear()
|
||||||
self.on_start_callbacks.append(self._connect_to_database)
|
self.on_start_callbacks.append(self._connect_to_database)
|
||||||
|
@ -72,7 +72,7 @@ the event:
|
||||||
class StatusHandler(web.RequestHandler):
|
class StatusHandler(web.RequestHandler):
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
maybe_future = super(StatusHandler, self).prepare()
|
maybe_future = super().prepare()
|
||||||
if concurrent.is_future(maybe_future):
|
if concurrent.is_future(maybe_future):
|
||||||
yield maybe_future
|
yield maybe_future
|
||||||
if not self._finished and not self.application.ready_to_serve.is_set():
|
if not self._finished and not self.application.ready_to_serve.is_set():
|
||||||
|
@ -144,7 +144,7 @@ written the following instead:
|
||||||
|
|
||||||
class MyHandler(web.RequestHandler):
|
class MyHandler(web.RequestHandler):
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
super(MyHandler, self).initialize()
|
super().initialize()
|
||||||
self.logger = logging.getLogger('MyHandler')
|
self.logger = logging.getLogger('MyHandler')
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Application(app.Application):
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
kwargs['debug'] = True
|
kwargs['debug'] = True
|
||||||
super(Application, self).__init__(
|
super().__init__(
|
||||||
[web.url(r'/status/(?P<status_code>\d+)', StatusHandler)],
|
[web.url(r'/status/(?P<status_code>\d+)', StatusHandler)],
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ class CallbackManager:
|
||||||
|
|
||||||
def __init__(self, tornado_application, *args, **kwargs):
|
def __init__(self, tornado_application, *args, **kwargs):
|
||||||
self.runner_callbacks = kwargs.pop('runner_callbacks', {})
|
self.runner_callbacks = kwargs.pop('runner_callbacks', {})
|
||||||
super(CallbackManager, self).__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
self._tornado_application = tornado_application
|
self._tornado_application = tornado_application
|
||||||
self.logger = logging.getLogger(self.__class__.__name__)
|
self.logger = logging.getLogger(self.__class__.__name__)
|
||||||
|
@ -199,7 +199,7 @@ class Application(CallbackManager, web.Application):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Application, self).__init__(self, *args, **kwargs)
|
super().__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class _ApplicationAdapter(CallbackManager):
|
class _ApplicationAdapter(CallbackManager):
|
||||||
|
@ -220,7 +220,7 @@ class _ApplicationAdapter(CallbackManager):
|
||||||
def __init__(self, application):
|
def __init__(self, application):
|
||||||
self._application = application
|
self._application = application
|
||||||
self.settings = self._application.settings
|
self.settings = self._application.settings
|
||||||
super(_ApplicationAdapter, self).__init__(
|
super().__init__(
|
||||||
self._application,
|
self._application,
|
||||||
runner_callbacks=getattr(application, 'runner_callbacks', {}))
|
runner_callbacks=getattr(application, 'runner_callbacks', {}))
|
||||||
setattr(self._application, 'runner_callbacks', self.runner_callbacks)
|
setattr(self._application, 'runner_callbacks', self.runner_callbacks)
|
||||||
|
|
|
@ -32,7 +32,7 @@ class LoggingHandler:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
super(LoggingHandler, self).initialize()
|
super().initialize()
|
||||||
if not hasattr(self, 'logger'):
|
if not hasattr(self, 'logger'):
|
||||||
self.logger = logging.getLogger(self.__class__.__name__)
|
self.logger = logging.getLogger(self.__class__.__name__)
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ class ErrorLogger(LoggingHandler):
|
||||||
else:
|
else:
|
||||||
# Oh, and make non-standard HTTP status codes NOT explode!
|
# Oh, and make non-standard HTTP status codes NOT explode!
|
||||||
kwargs['reason'] = _get_http_reason(status_code)
|
kwargs['reason'] = _get_http_reason(status_code)
|
||||||
super(ErrorLogger, self).send_error(status_code, **kwargs)
|
super().send_error(status_code, **kwargs)
|
||||||
|
|
||||||
def write_error(self, status_code, **kwargs):
|
def write_error(self, status_code, **kwargs):
|
||||||
log_function = self.logger.debug
|
log_function = self.logger.debug
|
||||||
|
@ -71,7 +71,7 @@ class ErrorLogger(LoggingHandler):
|
||||||
log_function('%s %s failed with %s: %s', self.request.method,
|
log_function('%s %s failed with %s: %s', self.request.method,
|
||||||
self.request.uri, status_code,
|
self.request.uri, status_code,
|
||||||
kwargs.get('log_message', kwargs['reason']))
|
kwargs.get('log_message', kwargs['reason']))
|
||||||
super(ErrorLogger, self).write_error(status_code, **kwargs)
|
super().write_error(status_code, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ErrorWriter:
|
class ErrorWriter:
|
||||||
|
|
20
tests.py
20
tests.py
|
@ -18,7 +18,7 @@ import examples
|
||||||
class RecordingHandler(logging.Handler):
|
class RecordingHandler(logging.Handler):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(RecordingHandler, self).__init__()
|
super().__init__()
|
||||||
self.emitted = []
|
self.emitted = []
|
||||||
|
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
|
@ -37,11 +37,11 @@ class RaisingHandler(sprockets.http.mixins.ErrorLogger,
|
||||||
class MockHelper(unittest.TestCase):
|
class MockHelper(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(MockHelper, self).setUp()
|
super().setUp()
|
||||||
self._mocks = []
|
self._mocks = []
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(MockHelper, self).tearDown()
|
super().tearDown()
|
||||||
for mocker in self._mocks:
|
for mocker in self._mocks:
|
||||||
mocker.stop()
|
mocker.stop()
|
||||||
del self._mocks[:]
|
del self._mocks[:]
|
||||||
|
@ -69,13 +69,13 @@ def override_environment_variable(name, value):
|
||||||
class ErrorLoggerTests(testing.AsyncHTTPTestCase):
|
class ErrorLoggerTests(testing.AsyncHTTPTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ErrorLoggerTests, self).setUp()
|
super().setUp()
|
||||||
self.recorder = RecordingHandler()
|
self.recorder = RecordingHandler()
|
||||||
root_logger = logging.getLogger()
|
root_logger = logging.getLogger()
|
||||||
root_logger.addHandler(self.recorder)
|
root_logger.addHandler(self.recorder)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(ErrorLoggerTests, self).tearDown()
|
super().tearDown()
|
||||||
logging.getLogger().removeHandler(self.recorder)
|
logging.getLogger().removeHandler(self.recorder)
|
||||||
|
|
||||||
def get_app(self):
|
def get_app(self):
|
||||||
|
@ -129,7 +129,7 @@ class ErrorWriterTests(testing.AsyncHTTPTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self._application = None
|
self._application = None
|
||||||
super(ErrorWriterTests, self).setUp()
|
super().setUp()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def application(self):
|
def application(self):
|
||||||
|
@ -219,7 +219,7 @@ class ErrorWriterTests(testing.AsyncHTTPTestCase):
|
||||||
class RunTests(MockHelper, unittest.TestCase):
|
class RunTests(MockHelper, unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(RunTests, self).setUp()
|
super().setUp()
|
||||||
self.runner_cls = self.start_mock('sprockets.http.runner.Runner')
|
self.runner_cls = self.start_mock('sprockets.http.runner.Runner')
|
||||||
self.get_logging_config = self.start_mock(
|
self.get_logging_config = self.start_mock(
|
||||||
'sprockets.http._get_logging_config')
|
'sprockets.http._get_logging_config')
|
||||||
|
@ -293,7 +293,7 @@ class RunTests(MockHelper, unittest.TestCase):
|
||||||
class CallbackTests(MockHelper, unittest.TestCase):
|
class CallbackTests(MockHelper, unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(CallbackTests, self).setUp()
|
super().setUp()
|
||||||
self.shutdown_callback = mock.Mock()
|
self.shutdown_callback = mock.Mock()
|
||||||
self.before_run_callback = mock.Mock()
|
self.before_run_callback = mock.Mock()
|
||||||
self.application = self.make_application()
|
self.application = self.make_application()
|
||||||
|
@ -361,7 +361,7 @@ class CallbackTests(MockHelper, unittest.TestCase):
|
||||||
class RunnerTests(MockHelper, unittest.TestCase):
|
class RunnerTests(MockHelper, unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(RunnerTests, self).setUp()
|
super().setUp()
|
||||||
self.application = mock.Mock()
|
self.application = mock.Mock()
|
||||||
self.application.settings = {
|
self.application.settings = {
|
||||||
'xheaders': True,
|
'xheaders': True,
|
||||||
|
@ -498,7 +498,7 @@ class AsyncRunTests(unittest.TestCase):
|
||||||
class RunCommandTests(MockHelper, unittest.TestCase):
|
class RunCommandTests(MockHelper, unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(RunCommandTests, self).setUp()
|
super().setUp()
|
||||||
self.distribution = mock.Mock(spec=distutils.dist.Distribution,
|
self.distribution = mock.Mock(spec=distutils.dist.Distribution,
|
||||||
verbose=3)
|
verbose=3)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue