<commit_before># coding: utf-8
#
# Copyright 2014 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Provides a seam for user-related services."""

__author__ = '<NAME>'

import urlparse

from google.appengine.api import users
from google.appengine.ext import ndb


def create_login_url(slug):
    """Creates a login url."""
    return users.create_login_url(slug)


def create_logout_url(slug):
    """Creates a logout url."""
    # Extract the relative path from slug.
    # Example: slug="http://www.example.com/gallery" path="/gallery".
    path = list(urlparse.urlparse(slug))[2]
    return '/logout?url=%s' % path


def get_current_user(request):
    """Returns the current user."""
    return users.get_current_user()


def is_super_admin(user_id, request):
    """Checks whether the user with the given user_id owns this app.

    For GAE, the user in question is also required to be the current user.
    """
    user = users.get_current_user()
    if user is None:
        return False

    return user.user_id() == user_id and users.is_current_user_admin()


def get_user_id_from_email(email):
    """Given an email address, returns a user id.

    Returns None if the email address does not correspond to a valid user id.
    """
    class _FakeUser(ndb.Model):
        _use_memcache = False
        _use_cache = False
        user = ndb.UserProperty(required=True)

    try:
        u = users.User(email)
    except users.UserNotFoundError:
        raise utils.InvalidInputException(
            'User with email address %s not found' % email)

    key = _FakeUser(id=email, user=u).put()
    obj = _FakeUser.get_by_id(key.id())
    user_id = obj.user.user_id()
    if user_id:
        return unicode(user_id)
    else:
        return None


def get_user_id(user):
    """ Given an user object, get the user id. """
    return user.user_id()<commit_msg>Fix an import error in gae_current_user_services.<commit_after># coding: utf-8
#
# Copyright 2014 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Provides a seam for user-related services."""

__author__ = '<NAME>'

import logging

import urlparse

from google.appengine.api import users
from google.appengine.ext import ndb


def create_login_url(slug):
    """Creates a login url."""
    return users.create_login_url(slug)


def create_logout_url(slug):
    """Creates a logout url."""
    # Extract the relative path from slug.
    # Example: slug="http://www.example.com/gallery" path="/gallery".
    path = list(urlparse.urlparse(slug))[2]
    return '/logout?url=%s' % path


def get_current_user(request):
    """Returns the current user."""
    return users.get_current_user()


def is_super_admin(user_id, request):
    """Checks whether the user with the given user_id owns this app.

    For GAE, the user in question is also required to be the current user.
    """
    user = users.get_current_user()
    if user is None:
        return False

    return user.user_id() == user_id and users.is_current_user_admin()


def get_user_id_from_email(email):
    """Given an email address, returns a user id.

    Returns None if the email address does not correspond to a valid user id.
    """
    class _FakeUser(ndb.Model):
        _use_memcache = False
        _use_cache = False
        user = ndb.UserProperty(required=True)

    try:
        u = users.User(email)
    except users.UserNotFoundError:
        logging.error(
            'The email address %s does not correspond to a valid user_id'
            % email)
        return None

    key = _FakeUser(id=email, user=u).put()
    obj = _FakeUser.get_by_id(key.id())
    user_id = obj.user.user_id()
    if user_id:
        return unicode(user_id)
    else:
        return None


def get_user_id(user):
    """ Given an user object, get the user id. """
    return user.user_id()
{'fraction_non_alphanumeric': 0.09614206981016533, 'fraction_numerical': 0.004082465809348847, 'mean_word_length': 3.257167680278019, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3741675', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1442, 'n_words': 523}