From 0eb779185db3cb38999e3811df77c2c64aa585ac Mon Sep 17 00:00:00 2001 From: Raphael Deem Date: Fri, 27 Jan 2017 17:59:08 -0800 Subject: [PATCH] fix deprecation warnings --- sanic/sanic.py | 32 ++++++++++++++++++++++---------- sanic/server.py | 9 ++++++--- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/sanic/sanic.py b/sanic/sanic.py index 1ed14b7f..ea2e8bef 100644 --- a/sanic/sanic.py +++ b/sanic/sanic.py @@ -4,6 +4,7 @@ from collections import deque from functools import partial from inspect import isawaitable, stack, getmodulename from traceback import format_exc +import warnings from .config import Config from .exceptions import Handler @@ -175,9 +176,12 @@ class Sanic: def register_blueprint(self, *args, **kwargs): # TODO: deprecate 1.0 - log.warning("Use of register_blueprint will be deprecated in " - "version 1.0. Please use the blueprint method instead", - DeprecationWarning) + if self.debug: + warnings.simplefilter('default') + warnings.warn("Use of register_blueprint will be deprecated in " + "version 1.0. Please use the blueprint method" + " instead", + DeprecationWarning) return self.blueprint(*args, **kwargs) # -------------------------------------------------------------------- # @@ -296,12 +300,16 @@ class Sanic: """ self.error_handler.debug = debug self.debug = debug - if loop is not None: - log.warning("Passing a loop will be deprecated in version 0.4.0" - " https://github.com/channelcat/sanic/pull/335" - " has more information.", DeprecationWarning) self.loop = loop + if loop is not None: + if self.debug: + warnings.simplefilter('default') + warnings.warn("Passing a loop will be deprecated in version" + " 0.4.0 https://github.com/channelcat/sanic/" + "pull/335 has more information.", + DeprecationWarning) + server_settings = { 'protocol': protocol, 'host': host, @@ -375,9 +383,13 @@ class Sanic: Asynchronous version of `run`. """ if loop is not None: - log.warning("Passing a loop will be deprecated in version 0.4.0" - " https://github.com/channelcat/sanic/pull/335" - " has more information.", DeprecationWarning) + if self.debug: + warnings.simplefilter('default') + warnings.warn("Passing a loop will be deprecated in version" + " 0.4.0 https://github.com/channelcat/sanic/" + "pull/335 has more information.", + DeprecationWarning) + loop = get_event_loop() server_settings = { 'protocol': protocol, diff --git a/sanic/server.py b/sanic/server.py index dc3acc42..48c3827e 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -9,6 +9,7 @@ from signal import SIGTERM, SIGINT from signal import signal as signal_func from socket import socket, SOL_SOCKET, SO_REUSEADDR from time import time +import warnings from httptools import HttpRequestParser from httptools.parser.errors import HttpParserError @@ -384,9 +385,11 @@ def serve_multiple(server_settings, workers, stop_event=None): :return: """ if server_settings.get('loop', None) is not None: - log.warning("Passing a loop will be deprecated in version 0.4.0" - " https://github.com/channelcat/sanic/pull/335" - " has more information.", DeprecationWarning) + if server_settings.get('debug', False): + warnings.simplefilter('default') + warnings.warn("Passing a loop will be deprecated in version 0.4.0" + " https://github.com/channelcat/sanic/pull/335" + " has more information.", DeprecationWarning) server_settings['reuse_port'] = True sock = socket()