from . import app_settings

_render_method = None
def get_render_method():
    global _render_method

    if _render_method is None:
        _render_method = from_dotted_path(app_settings.EMAIL_RENDER_METHOD)

    return _render_method

_context_processors = None
def get_context_processors():
    global _context_processors

    if _context_processors is None:
        _context_processors = [
            from_dotted_path(x) for x in app_settings.EMAIL_CONTEXT_PROCESSORS
        ]

    return _context_processors

def from_dotted_path(fullpath):
    """
    Returns the specified attribute of a module, specified by a string.

    ``from_dotted_path('a.b.c.d')`` is roughly equivalent to::

        from a.b.c import d

    except that ``d`` is returned and not entered into the current namespace.
    """

    module, attr = fullpath.rsplit('.', 1)

    return getattr(__import__(module, {}, {}, (attr,)), attr)

from django.utils.functional import memoize

from . import app_settings

def get_render_method():
    return from_dotted_path(app_settings.EMAIL_RENDER_METHOD)
get_render_method = memoize(get_render_method, {}, 0)

def get_context_processors():
    return [from_dotted_path(x) for x in app_settings.EMAIL_CONTEXT_PROCESSORS]
get_context_processors = memoize(get_context_processors, {}, 0)

def from_dotted_path(fullpath):
    """
    Returns the specified attribute of a module, specified by a string.

    ``from_dotted_path('a.b.c.d')`` is roughly equivalent to::

        from a.b.c import d

    except that ``d`` is returned and not entered into the current namespace.
    """

    module, attr = fullpath.rsplit('.', 1)

    return getattr(__import__(module, {}, {}, (attr,)), attr)

Use Django's memoize over a custom one.
Use Django's memoize over a custom one.

Signed-off-by: Chris Lamb <711c73f64afdce07b7e38039a96d2224209e9a6c@playfire.com>
