diff --git a/docs/source/acknowledgment.md b/docs/source/acknowledgment.md new file mode 100644 index 00000000..a7e70120 --- /dev/null +++ b/docs/source/acknowledgment.md @@ -0,0 +1,13 @@ +This is a list of modules and snipped of codes taken from the wonderful +python open-source community. In order of inclusion into pulsar: + +* Python Http parser from [benoitc http-parser](http-parser: https://github.com/benoitc/http-parser) +* Autoreload utility [d6f0abf](https://github.com/quantmind/pulsar/commit/d6f0abf99bb4f539101f3badadba3d027eb1e295) +``` +# Autoreloading launcher. +# Borrowed from Peter Hunt and the CherryPy project (http://www.cherrypy.org). +# Some taken from Ian Bicking's Paste (http://pythonpaste.org/). +# +# Portions copyright (c) 2004, CherryPy Team (team@cherrypy.org) +# All rights reserved. +``` diff --git a/pulsar/apps/wsgi/middleware.py b/pulsar/apps/wsgi/middleware.py index 0104a475..bee98e74 100644 --- a/pulsar/apps/wsgi/middleware.py +++ b/pulsar/apps/wsgi/middleware.py @@ -52,7 +52,7 @@ from functools import wraps import pulsar -from pulsar import is_async, task, get_event_loop +from pulsar import isawaitable, task, get_event_loop from pulsar.utils.httpurl import BytesIO from .auth import parse_authorization_header @@ -103,7 +103,7 @@ def wait_for_body_middleware(environ, start_response=None): if environ['wsgi.input']: stream = environ['wsgi.input'] chunk = stream.read() - if is_async(chunk): + if isawaitable(chunk): chunk = yield from chunk environ['wsgi.input'] = BytesIO(chunk) diff --git a/pulsar/async/access.py b/pulsar/async/access.py index 5977356a..99f83b3b 100644 --- a/pulsar/async/access.py +++ b/pulsar/async/access.py @@ -1,20 +1,25 @@ import os import threading import logging +import asyncio +import warnings from collections import OrderedDict from threading import current_thread -import asyncio -from asyncio import iscoroutine, coroutine +from asyncio import iscoroutine, coroutine, Future from pulsar.utils.config import Global from pulsar.utils.system import current_process try: from asyncio import ensure_future + from inspect import isawaitable except ImportError: # pragma nocover ensure_future = asyncio.async + def isawaitable(c): + return isinstance(c, Future) or iscoroutine(c) + __all__ = ['get_event_loop', 'new_event_loop', @@ -30,31 +35,35 @@ 'Future', 'reraise', 'coroutine', - 'is_async', + 'isawaitable', 'ensure_future', - 'CANCELLED_ERRORS'] + 'CANCELLED_ERRORS', + # Deprecated + 'is_async'] _EVENT_LOOP_CLASSES = (asyncio.AbstractEventLoop,) CANCELLED_ERRORS = (asyncio.CancelledError,) +def is_async(x): # pragma nocover + # TODO: remove in pulsar 1.2 + warnings.warn("pulsar.is_async is deprecated and will be removed in " + "pulsar 1.2, use pulsar.isawaitable instead", + SyntaxWarning) + return isawaitable(x) + + def reraise(tp, value, tb=None): if value.__traceback__ is not tb: raise value.with_traceback(tb) raise value -Future = asyncio.Future - def isfuture(x): return isinstance(x, Future) -def is_async(c): - return isfuture(c) or iscoroutine(c) - - LOGGER = logging.getLogger('pulsar') NOTHING = object() SELECTORS = OrderedDict() diff --git a/pulsar/async/mailbox.py b/pulsar/async/mailbox.py index 4e614b6f..7584ab83 100644 --- a/pulsar/async/mailbox.py +++ b/pulsar/async/mailbox.py @@ -60,7 +60,7 @@ def example(): from pulsar.utils.websocket import frame_parser from pulsar.utils.string import gen_unique_id -from .access import get_actor, is_async +from .access import get_actor, isawaitable from .futures import Future, task from .proxy import actor_identity, get_proxy, get_command, ActorProxy from .protocols import Protocol @@ -81,7 +81,7 @@ def command_in_context(command, caller, target, args, kwargs, connection=None): raise CommandError('unknown %s' % command) request = CommandRequest(target, caller, connection) result = cmnd(request, args, kwargs) - if is_async(result): + if isawaitable(result): result = yield from result return result diff --git a/pulsar/utils/autoreload.py b/pulsar/utils/autoreload.py index 19207fcd..bdda860d 100644 --- a/pulsar/utils/autoreload.py +++ b/pulsar/utils/autoreload.py @@ -4,32 +4,6 @@ # # Portions copyright (c) 2004, CherryPy Team (team@cherrypy.org) # All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, -# this list of conditions and the following disclaimer in the -# documentation -# and/or other materials provided with the distribution. -# * Neither the name of the CherryPy Team nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import os import signal