ó
P'—^c           @@  sU   d  Z  d d l m Z d d l m Z d d g Z d e f d „  ƒ  YZ d „  Z d S(	   s/  
celery.contrib.methods
======================

Task decorator that supports creating tasks out of methods.

Examples
--------

.. code-block:: python

    from celery.contrib.methods import task

    class X(object):

        @task()
        def add(self, x, y):
                return x + y

or with any task decorator:

.. code-block:: python

    from celery.contrib.methods import task_method

    class X(object):

        @app.task(filter=task_method)
        def add(self, x, y):
            return x + y

.. note::

    The task must use the new Task base class (:class:`celery.Task`),
    and the old base class using classmethods (``celery.task.Task``,
    ``celery.task.base.Task``).

    This means that you have to use the task decorator from a Celery app
    instance, and not the old-API:

    .. code-block:: python


        from celery import task       # BAD
        from celery.task import task  # ALSO BAD

        # GOOD:
        app = Celery(...)

        @app.task(filter=task_method)
        def foo(self): pass

        # ALSO GOOD:
        from celery import current_app

        @current_app.task(filter=task_method)
        def foo(self): pass

        # ALSO GOOD:
        from celery import shared_task

        @shared_task(filter=task_method)
        def foo(self): pass

Caveats
-------

- Automatic naming won't be able to know what the class name is.

    The name will still be module_name + task_name,
    so two methods with the same name in the same module will collide
    so that only one task can run:

    .. code-block:: python

        class A(object):

            @task()
            def add(self, x, y):
                return x + y

        class B(object):

            @task()
            def add(self, x, y):
                return x + y

    would have to be written as:

    .. code-block:: python

        class A(object):
            @task(name='A.add')
            def add(self, x, y):
                return x + y

        class B(object):
            @task(name='B.add')
            def add(self, x, y):
                return x + y

i    (   t   absolute_import(   t   current_appt   task_methodt   taskc           B@  s   e  Z d  „  Z d d „ Z RS(   c         O@  s   | |  _  d  S(   N(   R   (   t   selfR   t   argst   kwargs(    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/contrib/methods.pyt   __init__r   s    c         C@  s/   | d  k r |  j S|  j j ƒ  } | | _ | S(   N(   t   NoneR   t	   __class__t   __self__(   R   t   objt   typeR   (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/contrib/methods.pyt   __get__u   s
    	N(   t   __name__t
   __module__R   R   R   (    (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/contrib/methods.pyR   p   s   	c          O@  s   t  j |  t | d t ƒŽ  S(   Nt   filter(   R   R   t   dictR   (   R   R   (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/contrib/methods.pyR   }   s    N(	   t   __doc__t
   __future__R    t   celeryR   t   __all__t   objectR   R   (    (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/contrib/methods.pyt   <module>g   s
   