<commit_before>import connexion
import os
import urllib2, urllib

import flask

from models.classes import *

github_secret = 'GITHUB_SECRET'
github_client = 'GITHUB_CLIENT'


def get_from_query(query, target):
    for p in query.split('&'):
        if 0 <= p.find('=') < len(p) - 1:
            p_key, p_value = p.split('=')

            if p_key.lower() == target.lower():
                return p_value

    return None


def current_user():
    api_key = get_from_query(connexion.request.query_string, 'api_key')

    if not api_key:
        return selected_user('')

    api_key_entity = ndb.Key(ApiKey, api_key).get()

    if api_key_entity:
        return selected_user(api_key_entity.user.id())
    else:
        return selected_user('')


def selected_user(id):
    if not id:
        return flask.Response(status=404)

    user_entity = ndb.Key(User, id.lower()).get()

    if user_entity:
        return user_entity.to_obj()
    else:
        return flask.Response(status=404)


def auth_source():
    auth_methods = []

    if os.getenv(github_secret) and os.getenv(github_client):
        raw_url = 'https://github.com/login/oauth/authorize'
        client_key_parameter = 'client_id'
        client_key = os.getenv('GITHUB_CLIENT')
        scope_parameter = 'scope'
        scope = 'user:email'

        auth_methods.append({'source': 'github',
                             'rawUrl': raw_url,
                             'clientKeyParameter': client_key_parameter,
                             'clientKey': client_key,
                             'scopeParameter': scope_parameter,
                             'scope': scope,
                             'fullUrl': '{}?{}={}&{}={}'.format(raw_url, client_key_parameter, client_key,
                                                                scope_parameter, scope)})<commit_msg>refactor(default_controller.py): renamed the parameter name 'id' to 'user_id' to prevent shadow the default keyword 'id'.<commit_after>import connexion
import os
import urllib2, urllib

import flask

from models.classes import *

github_secret = 'GITHUB_SECRET'
github_client = 'GITHUB_CLIENT'


def get_from_query(query, target):
    for p in query.split('&'):
        if 0 <= p.find('=') < len(p) - 1:
            p_key, p_value = p.split('=')

            if p_key.lower() == target.lower():
                return p_value

    return None


def current_user():
    api_key = get_from_query(connexion.request.query_string, 'api_key')

    if not api_key:
        return selected_user('')

    api_key_entity = ndb.Key(ApiKey, api_key).get()

    if api_key_entity:
        return selected_user(api_key_entity.user.id())
    else:
        return selected_user('')


def selected_user(user_id):
    if not user_id:
        return flask.Response(status=404)

    user_entity = ndb.Key(User, user_id.lower()).get()

    if user_entity:
        return user_entity.to_obj()
    else:
        return flask.Response(status=404)


def auth_source():
    auth_methods = []

    if os.getenv(github_secret) and os.getenv(github_client):
        raw_url = 'https://github.com/login/oauth/authorize'
        client_key_parameter = 'client_id'
        client_key = os.getenv('GITHUB_CLIENT')
        scope_parameter = 'scope'
        scope = 'user:email'

        auth_methods.append({'source': 'github',
                             'rawUrl': raw_url,
                             'clientKeyParameter': client_key_parameter,
                             'clientKey': client_key,
                             'scopeParameter': scope_parameter,
                             'scope': scope,
                             'fullUrl': '{}?{}={}&{}={}'.format(raw_url, client_key_parameter, client_key,
                                                                scope_parameter, scope)})
{'fraction_non_alphanumeric': 0.1142483660130719, 'fraction_numerical': 0.004705882352941176, 'mean_word_length': 2.0879741727199352, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3931271', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1144, 'n_words': 233}