Skip to content

Commit

Permalink
Merge pull request #359 from r0fls/fix-warnings
Browse files Browse the repository at this point in the history
fix deprecation warnings
  • Loading branch information
seemethere committed Jan 28, 2017
2 parents 3d790a7 + 0eb7791 commit 7257e57
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
32 changes: 22 additions & 10 deletions sanic/sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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
Expand Down Expand Up @@ -175,9 +176,12 @@ def blueprint(self, blueprint, **options):

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)

# -------------------------------------------------------------------- #
Expand Down Expand Up @@ -296,12 +300,16 @@ def run(self, host="127.0.0.1", port=8000, debug=False, before_start=None,
"""
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,
Expand Down Expand Up @@ -375,9 +383,13 @@ async def create_server(self, host="127.0.0.1", port=8000, debug=False,
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,
Expand Down
9 changes: 6 additions & 3 deletions sanic/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 7257e57

Please sign in to comment.