<commit_before>import json
import requests
import sys

try:
    import configparser
except ImportError:
    import ConfigParser as configparser
import re
import errno
import os

from pnc_cli import swagger_client
from pnc_cli.swagger_client.rest import ApiException

__author__ = 'thauser'


def get_auth_token(config):
    try:
        server = config.get('PNC', 'authServer')
    except configparser.NoOptionError:
        print('No authentication server defined. Define "authServer" in pnc-cli.conf to enable authentication.')
        return
    server = server + "/auth/realms/pncredhat/tokens/grants/access"
    try:
        username = config.get('PNC', 'username')
        password = config.get('PNC', 'password')
    except configparser.NoOptionError:
        print('Username / password missing. Define "username" and "password" in pnc-cli.conf for authentication.')
        return

    params = {'grant_type': 'password',
              'client_id': 'pncdirect',
              'username': username,
              'password': password}
    r = requests.post(server, params, verify=False)
    if r.status_code == 200:
        reply = json.loads(r.content.decode('utf-8'))
        return reply.get('access_token')


config = configparser.ConfigParser()
configfilename = os.path.expanduser("~") + "/.config/pnc-cli/pnc-cli.conf"
configdirname = os.path.dirname(configfilename)

try:
    os.makedirs(configdirname)
except OSError as e:
    if e.errno != errno.EEXIST:
        raise
found = config.read(os.path.join(configfilename))<commit_msg>convert token to string so that swagger doesn't puke<commit_after>import json
import requests
import sys

try:
    import configparser
except ImportError:
    import ConfigParser as configparser
import re
import errno
import os

from pnc_cli import swagger_client
from pnc_cli.swagger_client.rest import ApiException

__author__ = 'thauser'


def get_auth_token(config):
    try:
        server = config.get('PNC', 'authServer')
    except configparser.NoOptionError:
        print('No authentication server defined. Define "authServer" in pnc-cli.conf to enable authentication.')
        return
    server = server + "/auth/realms/pncredhat/tokens/grants/access"
    try:
        username = config.get('PNC', 'username')
        password = config.get('PNC', 'password')
    except configparser.NoOptionError:
        print('Username / password missing. Define "username" and "password" in pnc-cli.conf for authentication.')
        return

    params = {'grant_type': 'password',
              'client_id': 'pncdirect',
              'username': username,
              'password': password}
    r = requests.post(server, params, verify=False)
    if r.status_code == 200:
        reply = json.loads(r.content.decode('utf-8'))
        return str(reply.get('access_token'))


config = configparser.ConfigParser()
configfilename = os.path.expanduser("~") + "/.config/pnc-cli/pnc-cli.conf"
configdirname = os.path.dirname(configfilename)

try:
    os.makedirs(configdirname)
except OSError as e:
    if e.errno != errno.EEXIST:
        raise
found = config.read(os.path.join(configfilename))
{'fraction_non_alphanumeric': 0.11135928525845565, 'fraction_numerical': 0.0025526483726866626, 'mean_word_length': 3.348127600554785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4691934', 'n_tokens_mistral': 939, 'n_tokens_neox': 925, 'n_words': 235}