<commit_before># -*- coding: utf-8 -*-
"""This module implements an interface to a DynECT REST Session. It provides
easy access to all other functionality within the dynect library via
methods that return various types of DynECT objects which will provide their
own respective functionality.
"""
# API Libs
from ..core import SessionEngine
from .errors import *
from ..compat import force_unicode
from ..encrypt import AESCipher


class DynectSession(SessionEngine):
    """Base object representing a DynectSession Session"""
    __metakey__ = 'bf7886ea-c61d-40df-8c7b-4241ebed0544'
    _valid_methods = ('DELETE', 'GET', 'POST', 'PUT')
    uri_root = '/REST'

    def __init__(self, customer, username, password, host='api.dynect.net', 
                 port=443, ssl=True, api_version='current', auto_auth=True):
        """Initialize a Dynect Rest Session object and store the provided
        credentials

        :param host: DynECT API server address
        :param port: Port to connect to DynECT API server
        :param ssl: Enable SSL
        :param api_version: version of the api to use
        :param customer: DynECT customer name
        :param username: DynECT Customer's username
        :param password: <PASSWORD>
        :param auto_auth: declare whether or not to automatically log in
        :return: DynectSession object
        """
        super(DynectSession, self).__init__(host, port, ssl)
        self.__cipher = AESCipher()
        self.extra_headers = {'API-Version': api_version}
        self.customer = customer
        self.username = username
        self.password = self.__cipher.encrypt(password)
        self.connect()
        if auto_auth:
            self.authenticate()

    def _handle_error(self, uri, method, raw_args):
        """Handle the processing of a connection error with the api"""
        # Our token is no longer valid because our session was killed
        self._token = None
        # Need to force a re-connect on next execute
        self._conn.close()<commit_msg>Added the ability for users to specify their own password encryption keys<commit_after># -*- coding: utf-8 -*-
"""This module implements an interface to a DynECT REST Session. It provides
easy access to all other functionality within the dynect library via
methods that return various types of DynECT objects which will provide their
own respective functionality.
"""
# API Libs
from ..core import SessionEngine
from .errors import *
from ..compat import force_unicode
from ..encrypt import AESCipher


class DynectSession(SessionEngine):
    """Base object representing a DynectSession Session"""
    __metakey__ = 'bf7886ea-c61d-40df-8c7b-4241ebed0544'
    _valid_methods = ('DELETE', 'GET', 'POST', 'PUT')
    uri_root = '/REST'

    def __init__(self, customer, username, password, host='api.dynect.net', 
                 port=443, ssl=True, api_version='current', auto_auth=True,
                 key=None):
        """Initialize a Dynect Rest Session object and store the provided
        credentials

        :param host: DynECT API server address
        :param port: Port to connect to DynECT API server
        :param ssl: Enable SSL
        :param api_version: version of the api to use
        :param customer: DynECT customer name
        :param username: DynECT Customer's username
        :param password: <PASSWORD>
        :param auto_auth: declare whether or not to automatically log in
        :param key: A valid AES-256 password encryption key to be used when
            encrypting your password
        """
        super(DynectSession, self).__init__(host, port, ssl)
        self.__cipher = AESCipher(key)
        self.extra_headers = {'API-Version': api_version}
        self.customer = customer
        self.username = username
        self.password = self.__cipher.encrypt(password)
        self.connect()
        if auto_auth:
            self.authenticate()

    def _handle_error(self, uri, method, raw_args):
        """Handle the processing of a connection error with the api"""
        # Our token is no longer valid because our session was killed
        self._token = None
        # Need to force a re-connect on next execute
        self._conn.close()
{'fraction_non_alphanumeric': 0.08145333649964379, 'fraction_numerical': 0.011161244360009499, 'mean_word_length': 2.874885004599816, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2593629', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1100, 'n_words': 433}