# Path: lazysignup/constants.py
# USER_AGENT_BLACKLIST = []
# 
# Path: lazysignup/exceptions.py
# class NotLazyError(TypeError):
#     """ Raised when an operation is attempted on a non-lazy user """
# 
# Path: lazysignup/utils.py
# def is_lazy_user(user):
#     """ Return True if the passed user is a lazy user. """
#     # Anonymous users are not lazy.
# 
#     if user.is_anonymous:
#         return False
# 
#     # Check the user backend. If the lazy signup backend
#     # authenticated them, then the user is lazy.
#     backend = getattr(user, 'backend', None)
#     if backend == 'lazysignup.backends.LazySignupBackend':
#         return True
# 
#     # Otherwise, we have to fall back to checking the database.
#     from lazysignup.models import LazyUser
#     return bool(LazyUser.objects.filter(user=user).count() > 0)
# 
# Path: lazysignup/signals.py

# 
# Path: lazysignup/constants.py
# LAZYSIGNUP_USER_MODEL = getattr(settings, 'LAZYSIGNUP_USER_MODEL', settings.AUTH_USER_MODEL)
# LAZYSIGNUP_CUSTOM_USER_CREATION_FORM = getattr(
#     settings,
#     'LAZYSIGNUP_CUSTOM_USER_CREATION_FORM',
#     None
# )
# DEFAULT_BLACKLIST = (
#     'slurp',
#     'googlebot',
#     'yandex',
#     'msnbot',
#     'baiduspider',
# )
# USER_AGENT_BLACKLIST = []


import re
import uuid
import six
from django.conf import settings
from django.db import models
from django.utils.timezone import now
from lazysignup.constants import USER_AGENT_BLACKLIST
from lazysignup.exceptions import NotLazyError
from lazysignup.utils import is_lazy_user
from lazysignup.signals import converted
from lazysignup import constants
from django.contrib.auth import get_user_model

class LazyUserManager(models.Manager):

    def __hash__(self):
        """
        Implemented so signal can be sent in .convert() for Django 1.8
        """
        return hash(str(self))

    username_field = get_user_model().USERNAME_FIELD

    def create_lazy_user(self):
        """ Create a lazy user. Returns a 2-tuple of the underlying User
        object (which may be of a custom class), and the username.
        """
        user_class = self.model.get_user_class()
        username = self.generate_username(user_class)
        user = user_class.objects.create_user(username, '')
        self.create(user=user)
        return user, username

    def convert(self, form):
        """ Convert a lazy user to a non-lazy one. The form passed
        in is expected to be a ModelForm instance, bound to the user
        to be converted.

        The converted ``User`` object is returned.

        Raises a TypeError if the user is not lazy.
        """

# Path: lazysignup/constants.py
# USER_AGENT_BLACKLIST = []
# 
# Path: lazysignup/exceptions.py
# class NotLazyError(TypeError):
#     """ Raised when an operation is attempted on a non-lazy user """
# 
# Path: lazysignup/utils.py
# def is_lazy_user(user):
#     """ Return True if the passed user is a lazy user. """
#     # Anonymous users are not lazy.
# 
#     if user.is_anonymous:
#         return False
# 
#     # Check the user backend. If the lazy signup backend
#     # authenticated them, then the user is lazy.
#     backend = getattr(user, 'backend', None)
#     if backend == 'lazysignup.backends.LazySignupBackend':
#         return True
# 
#     # Otherwise, we have to fall back to checking the database.
#     from lazysignup.models import LazyUser
#     return bool(LazyUser.objects.filter(user=user).count() > 0)
# 
# Path: lazysignup/signals.py

# 
# Path: lazysignup/constants.py
# LAZYSIGNUP_USER_MODEL = getattr(settings, 'LAZYSIGNUP_USER_MODEL', settings.AUTH_USER_MODEL)
# LAZYSIGNUP_CUSTOM_USER_CREATION_FORM = getattr(
#     settings,
#     'LAZYSIGNUP_CUSTOM_USER_CREATION_FORM',
#     None
# )
# DEFAULT_BLACKLIST = (
#     'slurp',
#     'googlebot',
#     'yandex',
#     'msnbot',
#     'baiduspider',
# )
# USER_AGENT_BLACKLIST = []


# Path: lazysignup/models.py
import re
import uuid
import six
from django.conf import settings
from django.db import models
from django.utils.timezone import now
from lazysignup.constants import USER_AGENT_BLACKLIST
from lazysignup.exceptions import NotLazyError
from lazysignup.utils import is_lazy_user
from lazysignup.signals import converted
from lazysignup import constants
from django.contrib.auth import get_user_model


class LazyUserManager(models.Manager):

    def __hash__(self):
        """
        Implemented so signal can be sent in .convert() for Django 1.8
        """
        return hash(str(self))

    username_field = get_user_model().USERNAME_FIELD

    def create_lazy_user(self):
        """ Create a lazy user. Returns a 2-tuple of the underlying User
        object (which may be of a custom class), and the username.
        """
        user_class = self.model.get_user_class()
        username = self.generate_username(user_class)
        user = user_class.objects.create_user(username, '')
        self.create(user=user)
        return user, username

    def convert(self, form):
        """ Convert a lazy user to a non-lazy one. The form passed
        in is expected to be a ModelForm instance, bound to the user
        to be converted.

        The converted ``User`` object is returned.

        Raises a TypeError if the user is not lazy.
        """

        if not is_lazy_user(form.instance):