<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from six.moves import configparser
import os

def write(aws_credentials, filename=None, profile_name='default'):

    # WTF
    ORIG_DEFAULTSECT = configparser.DEFAULTSECT
    configparser.DEFAULTSECT = 'default'

    try:

        if not filename:
            filename = os.path.expanduser("~") + '/.aws/credentials'

        if not os.path.exists(os.path.dirname(filename)):
            os.makedirs(os.path.dirname(filename))

        config = configparser.RawConfigParser()
        config.read(filename)

        if not config.has_section(profile_name) and profile_name.lower() != 'default':
            config.add_section(profile_name)

        config.set(profile_name, 'aws_access_key_id', aws_credentials['AWS_ACCESS_KEY_ID'])
        config.set(profile_name, 'aws_secret_access_key', aws_credentials['AWS_SECRET_ACCESS_KEY'])
        config.set(profile_name, 'aws_session_token', aws_credentials['AWS_SESSION_TOKEN'])

        with open(filename, 'w') as config_file:
                config.write(config_file)

    finally:
        configparser.DEFAULTSECT = ORIG_DEFAULTSECT<commit_msg>python 3 compatibility<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from six.moves import configparser
import os
import six

def write(aws_credentials, filename=None, profile_name='default'):

    if six.PY2:
        # WTF
        ORIG_DEFAULTSECT = configparser.DEFAULTSECT
        configparser.DEFAULTSECT = 'default'

    try:

        if not filename:
            filename = os.path.expanduser("~") + '/.aws/credentials'

        if not os.path.exists(os.path.dirname(filename)):
            os.makedirs(os.path.dirname(filename))

        config = configparser.RawConfigParser()
        config.read(filename)

        if not config.has_section(profile_name) and (profile_name.lower() != 'default' or six.PY3):
            config.add_section(profile_name)

        config.set(profile_name, 'aws_access_key_id', aws_credentials['AWS_ACCESS_KEY_ID'])
        config.set(profile_name, 'aws_secret_access_key', aws_credentials['AWS_SECRET_ACCESS_KEY'])
        config.set(profile_name, 'aws_session_token', aws_credentials['AWS_SESSION_TOKEN'])

        with open(filename, 'w') as config_file:
                config.write(config_file)

    finally:
        if six.PY2:
            configparser.DEFAULTSECT = ORIG_DEFAULTSECT
{'fraction_non_alphanumeric': 0.11315240083507307, 'fraction_numerical': 0.0025052192066805845, 'mean_word_length': 3.2183098591549295, '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': '2005081', 'n_tokens_mistral': 754, 'n_tokens_neox': 740, 'n_words': 125}