from google.appengine.api import users
from django.contrib.auth.models import User

def set_trace():
    import pdb, sys
    debugger = pdb.Pdb(stdin=sys.__stdin__, stdout=sys.__stdout__)
    debugger.set_trace(sys._getframe().f_back)

class GAEFederatedBackend:
    def authenticate(self, gae_user):
        if gae_user and gae_user == users.get_current_user():
            django_user, created = User.objects.get_or_create(username = gae_user.nickname(), email = gae_user.email())
        else:
            django_user = None
        return django_user
    
    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None

    def supports_anonymous_user():
        return False

    def supports_object_permissions():
        return False
