# Path: pypeman/channels.py
# class Dropped(Exception):
#     """ Used to stop process as message is processed. Default success should be returned.
#     """
# 
# Path: pypeman/persistence.py
# async def get_backend(loop):
#     """
#     Return the configured backend instance.
# 
#     :param loop: Asyncio loop to use. Passed backend instance.
#     """
#     global _backend
#     if not _backend:
#         # Load backend on first use
#         if not settings.PERSISTENCE_BACKEND:
#             raise Exception("Persistence backend not configured.")
# 
#         module, _, class_ = settings.PERSISTENCE_BACKEND.rpartition('.')
#         loaded_module = importlib.import_module(module)
#         _backend = getattr(loaded_module, class_)(loop=loop, **settings.PERSISTENCE_CONFIG)
# 
#         await _backend.start()
# 
#     return _backend
# 
# Path: pypeman/helpers/lazyload.py
# def load_class(module, class_, deps):
# def load(selfmodname, module, class_, dep=None):
#     def init(*args, **kwargs):
#     def __init__(self, wrapped):
#     def add_lazy(self, module, name, deps):
#     def __getattr__(self, name):
#         C = load_class(module, class_, dep)
# class Wrapper(object):


import asyncio
import base64
import json
import logging
import os
import smtplib
import types
import warnings
from datetime import datetime
from collections import OrderedDict
from fnmatch import fnmatch
from email.mime.text import MIMEText
from urllib import parse
from concurrent.futures import ThreadPoolExecutor
from pypeman.message import Message
from pypeman.channels import Dropped
from pypeman.persistence import get_backend
from pypeman.helpers import lazyload  # noqa: E402
        result = self.process(msg)
        return result

    def process(self, msg):
        """ Implement this function in child classes to create
        a new Node.

        :param msg: The incoming message
        :return: The processed message
        """
        return msg

    async def save_data(self, key, value):
        """
        Save data in configured persistence backend for next usage.

        :param key: Key of saved data.
        :param value: Value saved.
        """
        await (await get_backend(self.channel.loop)).store(self.fullpath(), key, value)

    async def restore_data(self, key, default=SENTINEL):
        """
        Restore previously saved data from configured persistence backend.

        :param key: Key of restored data.
        :param default: if key is missing, don't raise exception and return this value instead.
        :return: Saved data if exist or default value if specified.
        """
        if default is not SENTINEL:

# Path: pypeman/channels.py
# class Dropped(Exception):
#     """ Used to stop process as message is processed. Default success should be returned.
#     """
# 
# Path: pypeman/persistence.py
# async def get_backend(loop):
#     """
#     Return the configured backend instance.
# 
#     :param loop: Asyncio loop to use. Passed backend instance.
#     """
#     global _backend
#     if not _backend:
#         # Load backend on first use
#         if not settings.PERSISTENCE_BACKEND:
#             raise Exception("Persistence backend not configured.")
# 
#         module, _, class_ = settings.PERSISTENCE_BACKEND.rpartition('.')
#         loaded_module = importlib.import_module(module)
#         _backend = getattr(loaded_module, class_)(loop=loop, **settings.PERSISTENCE_CONFIG)
# 
#         await _backend.start()
# 
#     return _backend
# 
# Path: pypeman/helpers/lazyload.py
# def load_class(module, class_, deps):
# def load(selfmodname, module, class_, dep=None):
#     def init(*args, **kwargs):
#     def __init__(self, wrapped):
#     def add_lazy(self, module, name, deps):
#     def __getattr__(self, name):
#         C = load_class(module, class_, dep)
# class Wrapper(object):


# Path: pypeman/nodes.py
import asyncio
import base64
import json
import logging
import os
import smtplib
import types
import warnings
from datetime import datetime
from collections import OrderedDict
from fnmatch import fnmatch
from email.mime.text import MIMEText
from urllib import parse
from concurrent.futures import ThreadPoolExecutor
from pypeman.message import Message
from pypeman.channels import Dropped
from pypeman.persistence import get_backend
from pypeman.helpers import lazyload  # noqa: E402

        result = self.process(msg)
        return result

    def process(self, msg):
        """ Implement this function in child classes to create
        a new Node.

        :param msg: The incoming message
        :return: The processed message
        """
        return msg

    async def save_data(self, key, value):
        """
        Save data in configured persistence backend for next usage.

        :param key: Key of saved data.
        :param value: Value saved.
        """
        await (await get_backend(self.channel.loop)).store(self.fullpath(), key, value)

    async def restore_data(self, key, default=SENTINEL):
        """
        Restore previously saved data from configured persistence backend.

        :param key: Key of restored data.
        :param default: if key is missing, don't raise exception and return this value instead.
        :return: Saved data if exist or default value if specified.
        """
        if default is not SENTINEL:

            return await (await get_backend(self.channel.loop)).get(self.fullpath(), key, default)