<commit_before># Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import copy
from concurrent import futures
import logging

from s3transfer.futures import TransferFuture
from s3transfer.futures import TransferCoordinator
from s3transfer.futures import TransferMeta
from s3transfer.utils import get_callbacks


logger = logging.getLogger(__name__)


class TaskSubmitter(object):
    """Submits a series of task to fufill a request

    This is the base class and must be subclassed from and have the
    submit() method implemented.
    """
    def __init__(self, client, config, osutil, executor):
        """
        :param client: The client associated with the transfer manager

        :type config: s3transfer.manager.TransferConfig
        :param config: The transfer config associated with the transfer
            manager

        :type osutil: s3transfer.utils.OSUtil
        :param osutil: The os utility associated to the transfer manager

        :type executor: concurrent.futures.Executor-like object
        :param executor: The executor associated with the transfer manager
        """
        self._client = client
        self._config = config
        self._osutil = osutil
        self._executor = executor

    def _initialize_transfer_future(self, call_args):
        components = {
            'meta': TransferMeta(call_args),
            'coordinator': TransferCoordinator()
        }
        transfer_future = TransferFuture(**components)
        on_queued_callbacks = get_callbacks(transfer_future, 'queued')
        for on_queued_callback in on_queued_callbacks:
            on_queued_callback()
        return transfer_future, components

    def __call__(self, call_args=None):
        """Initializes and submits a transfer requests corresponding tasks

        :param call_args: The call arguments associated to the request

        :rtype: s3transfer.futures.TransferFuture
        :returns: The transfer future associated with the submition.
        """
        transfer_future, components = self._initialize_transfer_future(
            call_args)
        self._submit(transfer_future,
                     transfer_coordinator=components['coordinator'])
        return transfer_future

    def _submit(self, transfer_future, transfer_coordinator):
        """The submition method to be implemented

        The implementation of the method must accept two arguments:

        :type transfer_coordinator: s3transfer.futures.TransferCoordinator
        :param transfer_coordinator: The transfer context associated to the
            transfer future.

        :type transfer_future: s3transfer.futures.TransferFuture
        :param transfer_future: The transfer future associated with the
            transfer request
        """
        raise NotImplementedError('_submit() must be implemented')


class Task(object):
    """A task associated to a TransferFuture request
<commit_msg>Small update to docstrings<commit_after># Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import copy
from concurrent import futures
import logging

from s3transfer.futures import TransferFuture
from s3transfer.futures import TransferCoordinator
from s3transfer.futures import TransferMeta
from s3transfer.utils import get_callbacks


logger = logging.getLogger(__name__)


class TaskSubmitter(object):
    """Submits a series of task to fufill a request

    This is the base class and must be subclassed from and have the
    submit() method implemented.
    """
    def __init__(self, client, config, osutil, executor):
        """
        :param client: The client associated with the transfer manager

        :type config: s3transfer.manager.TransferConfig
        :param config: The transfer config associated with the transfer
            manager

        :type osutil: s3transfer.utils.OSUtil
        :param osutil: The os utility associated to the transfer manager

        :type executor: concurrent.futures.Executor-like object
        :param executor: The executor associated with the transfer manager
        """
        self._client = client
        self._config = config
        self._osutil = osutil
        self._executor = executor

    def _initialize_transfer_future(self, call_args):
        components = {
            'meta': TransferMeta(call_args),
            'coordinator': TransferCoordinator()
        }
        transfer_future = TransferFuture(**components)
        on_queued_callbacks = get_callbacks(transfer_future, 'queued')
        for on_queued_callback in on_queued_callbacks:
            on_queued_callback()
        return transfer_future, components

    def __call__(self, call_args=None):
        """Initializes and submits a transfer requests corresponding tasks

        :type call_args: s3transfer.utils.CallArgs
        :param call_args: The call arguments associated to the request

        :rtype: s3transfer.futures.TransferFuture
        :returns: The transfer future associated with the submition.
        """
        transfer_future, components = self._initialize_transfer_future(
            call_args)
        self._submit(transfer_future,
                     transfer_coordinator=components['coordinator'])
        return transfer_future

    def _submit(self, transfer_future, transfer_coordinator):
        """The submition method to be implemented

        The implementation of the method must accept two arguments:

        :type transfer_coordinator: s3transfer.futures.TransferCoordinator
        :param transfer_coordinator: The transfer context associated to the
            transfer future.

        :type transfer_future: s3transfer.futures.TransferFuture
        :param transfer_future: The transfer future associated with the
            transfer request
        """
        raise NotImplementedError('_submit() must be implemented')


class Task(object):
    """A task associated to a TransferFuture request

{'fraction_non_alphanumeric': 0.06161411628579693, 'fraction_numerical': 0.00506219265258895, 'mean_word_length': 3.1382405745062836, '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': '4397807', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1668, 'n_words': 638}