# Path: airy/core/conf.py
# class Settings(object):
#     def __init__(self, **entries):
#     def __getattribute__(self, name):
# def _ensure_defaults(dsettings, options, project_root, config_filename):
# def _preconfigure(project_root, config_filename='settings.py', argv=[]):
# 
# Path: airy/core/exceptions.py
# class ImproperlyConfigured(Exception):
#     "Django is somehow improperly configured"
#     pass
# 
# Path: airy/core/mail/backends/console.py
# class EmailBackend(BaseEmailBackend):
#     def __init__(self, *args, **kwargs):
#         self.stream = kwargs.pop('stream', sys.stdout)
#         self._lock = threading.RLock()
#         super(EmailBackend, self).__init__(*args, **kwargs)
# 
#     def send_messages(self, email_messages):
#         """Write all messages to the stream in a thread-safe way."""
#         if not email_messages:
#             return
#         self._lock.acquire()
#         try:
#             stream_created = self.open()
#             for message in email_messages:
#                 self.stream.write('%s\n' % message.message().as_string())
#                 self.stream.write('-'*79)
#                 self.stream.write('\n')
#                 self.stream.flush()  # flush after each message
#             if stream_created:
#                 self.close()
#         except:
#             if not self.fail_silently:
#                 raise
#         finally:
#             self._lock.release()
#         return len(email_messages)


import datetime
import os
from airy.core.conf import settings
from airy.core.exceptions import ImproperlyConfigured
from airy.core.mail.backends.console import EmailBackend as ConsoleEmailBackend
"""Email backend that writes messages to a file."""



class EmailBackend(ConsoleEmailBackend):
    def __init__(self, *args, **kwargs):
        self._fname = None
        if 'file_path' in kwargs:
            self.file_path = kwargs.pop('file_path')
        else:
            self.file_path = getattr(settings, 'EMAIL_FILE_PATH',None)
        # Make sure self.file_path is a string.
        if not isinstance(self.file_path, basestring):
            raise ImproperlyConfigured('Path for saving emails is invalid: %r' % self.file_path)
        self.file_path = os.path.abspath(self.file_path)
        # Make sure that self.file_path is an directory if it exists.
        if os.path.exists(self.file_path) and not os.path.isdir(self.file_path):

# Path: airy/core/conf.py
# class Settings(object):
#     def __init__(self, **entries):
#     def __getattribute__(self, name):
# def _ensure_defaults(dsettings, options, project_root, config_filename):
# def _preconfigure(project_root, config_filename='settings.py', argv=[]):
# 
# Path: airy/core/exceptions.py
# class ImproperlyConfigured(Exception):
#     "Django is somehow improperly configured"
#     pass
# 
# Path: airy/core/mail/backends/console.py
# class EmailBackend(BaseEmailBackend):
#     def __init__(self, *args, **kwargs):
#         self.stream = kwargs.pop('stream', sys.stdout)
#         self._lock = threading.RLock()
#         super(EmailBackend, self).__init__(*args, **kwargs)
# 
#     def send_messages(self, email_messages):
#         """Write all messages to the stream in a thread-safe way."""
#         if not email_messages:
#             return
#         self._lock.acquire()
#         try:
#             stream_created = self.open()
#             for message in email_messages:
#                 self.stream.write('%s\n' % message.message().as_string())
#                 self.stream.write('-'*79)
#                 self.stream.write('\n')
#                 self.stream.flush()  # flush after each message
#             if stream_created:
#                 self.close()
#         except:
#             if not self.fail_silently:
#                 raise
#         finally:
#             self._lock.release()
#         return len(email_messages)


# Path: airy/core/mail/backends/filebased.py
import datetime
import os
from airy.core.conf import settings
from airy.core.exceptions import ImproperlyConfigured
from airy.core.mail.backends.console import EmailBackend as ConsoleEmailBackend

"""Email backend that writes messages to a file."""



class EmailBackend(ConsoleEmailBackend):
    def __init__(self, *args, **kwargs):
        self._fname = None
        if 'file_path' in kwargs:
            self.file_path = kwargs.pop('file_path')
        else:
            self.file_path = getattr(settings, 'EMAIL_FILE_PATH',None)
        # Make sure self.file_path is a string.
        if not isinstance(self.file_path, basestring):
            raise ImproperlyConfigured('Path for saving emails is invalid: %r' % self.file_path)
        self.file_path = os.path.abspath(self.file_path)
        # Make sure that self.file_path is an directory if it exists.
        if os.path.exists(self.file_path) and not os.path.isdir(self.file_path):

            raise ImproperlyConfigured('Path for saving email messages exists, but is not a directory: %s' % self.file_path)