<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
VRT WideSky operation implementations.
"""

import fysom
import json
import base64

from ....util import state
from ....util.asyncexc import AsynchronousException

class WideskyAuthenticateOperation(state.HaystackOperation):
    """
    An implementation of the log-in procedure for WideSky.  WideSky uses
    a M2M variant of OAuth2.0 to authenticate users.
    """

    def __init__(self, session, retries=2):
        """
        Attempt to log in to the VRT WideSky server.  The procedure is as
        follows:

            POST to auth_dir URI:
                Headers:
                    Accept: application/json
                    Authorization: Basic [BASE64:"[ID]:[SECRET]"]
                    Content-Type: application/json
                Body: {
                    username: "[USER]", password: "[PASSWORD]",
                    grant_type: "password"
                }
            EXPECT reply:
                Headers:
                    Content-Type: application/json
                Body:
                    {
                        access_token: ..., refresh_token: ...,
                        expires_in: ..., token_type: ...
                    }

        :param session: Haystack HTTP session object.
        :param retries: Number of retries permitted in case of failure.
        """

        super(WideskyAuthenticateOperation, self).__init__()
        self._auth_headers = {
                'Authorization': 'Basic %s' % base64.b64encode(
                    ':'.join([session._client_id, session._client_secret])),
                'Accept': 'application/json',
                'Content-Type': 'application/json',
        }
        self._auth_body = json.dumps({
            'username': session._username,
            'password': <PASSWORD>._password,
            'grant_type': 'password',
        })
        self._session = session
        self._retries = retries
        self._auth_result = None
<commit_msg>client.ops.vendor.widesky: Handle Python 3 differences.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
VRT WideSky operation implementations.
"""

import fysom
import json
import base64

from ....util import state
from ....util.asyncexc import AsynchronousException

class WideskyAuthenticateOperation(state.HaystackOperation):
    """
    An implementation of the log-in procedure for WideSky.  WideSky uses
    a M2M variant of OAuth2.0 to authenticate users.
    """

    def __init__(self, session, retries=2):
        """
        Attempt to log in to the VRT WideSky server.  The procedure is as
        follows:

            POST to auth_dir URI:
                Headers:
                    Accept: application/json
                    Authorization: Basic [BASE64:"[ID]:[SECRET]"]
                    Content-Type: application/json
                Body: {
                    username: "[USER]", password: "[PASSWORD]",
                    grant_type: "password"
                }
            EXPECT reply:
                Headers:
                    Content-Type: application/json
                Body:
                    {
                        access_token: ..., refresh_token: ...,
                        expires_in: ..., token_type: ...
                    }

        :param session: Haystack HTTP session object.
        :param retries: Number of retries permitted in case of failure.
        """

        super(WideskyAuthenticateOperation, self).__init__()
        self._auth_headers = {
                'Authorization': 'Basic %s' % base64.b64encode(
                    ':'.join([session._client_id,
                        session._client_secret]).encode()),
                'Accept': 'application/json',
                'Content-Type': 'application/json',
        }
        self._auth_body = json.dumps({
            'username': session._username,
            'password': session._password,
            'grant_type': 'password',
        })
        self._session = session
        self._retries = retries
        self._auth_result = None

{'fraction_non_alphanumeric': 0.10327949094468918, 'fraction_numerical': 0.006607929515418502, 'mean_word_length': 1.5801767676767677, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '5614980', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1015, 'n_words': 268}