<commit_before># Copyright 2015, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""Google API Extensions"""

from __future__ import absolute_import
import collections


__version__ = '0.9.4'


OPTION_INHERIT = object()
"""Global constant.

If a CallOptions field is set to OPTION_INHERIT, the call to which that
CallOptions belongs will attempt to inherit that field from its default
settings."""


class CallSettings(object):
    """Encapsulates the call settings for an API call"""
    # pylint: disable=too-few-public-methods
    def __init__(self, timeout=30, retry=None, page_descriptor=None,
                 bundler=None, bundle_descriptor=None):
        """Constructor.

        Args:
            timeout (int): The client-side timeout for API calls. This
              parameter is ignored for retrying calls.
            retry (:class:`RetryOptions`): The configuration for retrying upon
              transient error. If set to None, this call will not retry.
            page_descriptor (:class:`PageDescriptor`): indicates the structure
              of page streaming to be performed. If set to None, page streaming
              is disabled
            bundler (:class:`gax.bundling.Executor`): orchestrates bundling. If
              None, bundling is not performed.
            bundle_descriptor (:class:`BundleDescriptor`): indicates the
              structure of of the bundle. If None, bundling is disabled.
        """
        self.timeout = timeout
        self.retry = retry
        self.page_descriptor = page_descriptor
        self.bundler = bundler
        self.bundle_descriptor = bundle_descriptor

    def merge(self, options):
        """Returns a new CallSettings merged from this and a CallOptions object.

        Args:
            options (:class:`CallOptions`): an instance whose values override
              those in this object. If None, `merge` returns a copy of this
              object

        Returns:
            A :class:`CallSettings` object.
        """
        if not options:
            return CallSettings(
                timeout=self.timeout, retry=self.retry,
                page_descriptor=self.page_descriptor, bundler=self.bundler,
                bundle_descriptor=self.bundle_descriptor)
        else:
            if options.timeout == OPTION_INHERIT:
                timeout = self.timeout
            else:
                timeout = options.timeout

            if options.retry == OPTION_INHERIT:
                retry = self.retry
            else:
                retry = options.retry

            if options.is_page_streaming:
                page_descriptor = self.page_descriptor
            else:
                page_descriptor = None

            return CallSettings(
                timeout=timeout, retry=retry,
                page_descriptor=page_descriptor, bundler=self.bundler,
                bundle_descriptor=self.bundle_descriptor)


class CallOptions(object):
    """Encapsulates the overridable settings for a particular API call.

    ``CallOptions`` are an optional arg for all GAX API calls.  They are used to
    configure the settings of a specific API call.

    When provided, its values override the GAX service defaults for that
    particular call.

    """
    # pylint: disable=too-few-public-methods
    def __init__(self, timeout=OPTION_INHERIT, retry=OPTION_INHERIT,
                 is_page_streaming=OPTION_INHERIT):
        """Constructor.

        Example:
           >>> # change an api call's timeout
           >>> o1 = CallOptions(timeout=30)  # make the timeout 30 seconds
           >>>
           >>> # disable page streaming on an api call that normally supports it
           >>> o2 = CallOptions(page_streaming=False)
           >>>
           >>> # disable retrys on an api call that normally retries
           >>> o3 = CallOptions(retry=None)

        Args:
            timeout (int): The client-side timeout for API calls.
            retry (:class:`RetryOptions`): determines whether and how to retry
              on transient errors. When set to None, the call will not retry.
            is_page_streaming (bool): If set and the call is configured for page
              streaming, page streaming is performed.
        """
        self.timeout = timeout
        self.retry = retry
        self.is_page_streaming = is_page_streaming


class PageDescriptor(
        collections.namedtuple(
            'PageDescriptor',
            ['request_page_token_field',
             'response_page_token_field',
             'resource_field'])):
    """Describes the structure of a page-streaming call."""
    pass


class RetryOptions(
        collections.namedtuple(
            'RetryOptions',
            ['retry_codes',
             'backoff_settings'])):
    """Per-call configurable settings for retrying upon transient failure.

    Attributes:
      retry_codes (list[string]): a list of exception codes upon which a retry
        should be attempted.
      backoff_settings (:class:`BackoffSettings`): configures the retry
        exponential backoff algorithm.
    """
    pass


class BackoffSettings(
        collections.namedtuple(
            'BackoffSettings',
            ['initial_retry_delay_millis',<commit_msg>Fix working around status code comment.<commit_after># Copyright 2015, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""Google API Extensions"""

from __future__ import absolute_import
import collections


__version__ = '0.9.4'


OPTION_INHERIT = object()
"""Global constant.

If a CallOptions field is set to OPTION_INHERIT, the call to which that
CallOptions belongs will attempt to inherit that field from its default
settings."""


class CallSettings(object):
    """Encapsulates the call settings for an API call"""
    # pylint: disable=too-few-public-methods
    def __init__(self, timeout=30, retry=None, page_descriptor=None,
                 bundler=None, bundle_descriptor=None):
        """Constructor.

        Args:
            timeout (int): The client-side timeout for API calls. This
              parameter is ignored for retrying calls.
            retry (:class:`RetryOptions`): The configuration for retrying upon
              transient error. If set to None, this call will not retry.
            page_descriptor (:class:`PageDescriptor`): indicates the structure
              of page streaming to be performed. If set to None, page streaming
              is disabled
            bundler (:class:`gax.bundling.Executor`): orchestrates bundling. If
              None, bundling is not performed.
            bundle_descriptor (:class:`BundleDescriptor`): indicates the
              structure of of the bundle. If None, bundling is disabled.
        """
        self.timeout = timeout
        self.retry = retry
        self.page_descriptor = page_descriptor
        self.bundler = bundler
        self.bundle_descriptor = bundle_descriptor

    def merge(self, options):
        """Returns a new CallSettings merged from this and a CallOptions object.

        Args:
            options (:class:`CallOptions`): an instance whose values override
              those in this object. If None, `merge` returns a copy of this
              object

        Returns:
            A :class:`CallSettings` object.
        """
        if not options:
            return CallSettings(
                timeout=self.timeout, retry=self.retry,
                page_descriptor=self.page_descriptor, bundler=self.bundler,
                bundle_descriptor=self.bundle_descriptor)
        else:
            if options.timeout == OPTION_INHERIT:
                timeout = self.timeout
            else:
                timeout = options.timeout

            if options.retry == OPTION_INHERIT:
                retry = self.retry
            else:
                retry = options.retry

            if options.is_page_streaming:
                page_descriptor = self.page_descriptor
            else:
                page_descriptor = None

            return CallSettings(
                timeout=timeout, retry=retry,
                page_descriptor=page_descriptor, bundler=self.bundler,
                bundle_descriptor=self.bundle_descriptor)


class CallOptions(object):
    """Encapsulates the overridable settings for a particular API call.

    ``CallOptions`` are an optional arg for all GAX API calls.  They are used to
    configure the settings of a specific API call.

    When provided, its values override the GAX service defaults for that
    particular call.

    """
    # pylint: disable=too-few-public-methods
    def __init__(self, timeout=OPTION_INHERIT, retry=OPTION_INHERIT,
                 is_page_streaming=OPTION_INHERIT):
        """Constructor.

        Example:
           >>> # change an api call's timeout
           >>> o1 = CallOptions(timeout=30)  # make the timeout 30 seconds
           >>>
           >>> # disable page streaming on an api call that normally supports it
           >>> o2 = CallOptions(page_streaming=False)
           >>>
           >>> # disable retrys on an api call that normally retries
           >>> o3 = CallOptions(retry=None)

        Args:
            timeout (int): The client-side timeout for API calls.
            retry (:class:`RetryOptions`): determines whether and how to retry
              on transient errors. When set to None, the call will not retry.
            is_page_streaming (bool): If set and the call is configured for page
              streaming, page streaming is performed.
        """
        self.timeout = timeout
        self.retry = retry
        self.is_page_streaming = is_page_streaming


class PageDescriptor(
        collections.namedtuple(
            'PageDescriptor',
            ['request_page_token_field',
             'response_page_token_field',
             'resource_field'])):
    """Describes the structure of a page-streaming call."""
    pass


class RetryOptions(
        collections.namedtuple(
            'RetryOptions',
            ['retry_codes',
             'backoff_settings'])):
    """Per-call configurable settings for retrying upon transient failure.

    Attributes:
      retry_codes (list[string]): a list of Google API canonical error codes
        upon which a retry should be attempted.
      backoff_settings (:class:`BackoffSettings`): configures the retry
        exponential backoff algorithm.
    """
    pass


class BackoffSettings(
        collections.namedtuple(
            'BackoffSettings',
            ['initial_retry_delay_millis',
{'fraction_non_alphanumeric': 0.06812272490899636, 'fraction_numerical': 0.0023772379466607237, 'mean_word_length': 2.514882506527415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 51, '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': '4501829', 'n_tokens_mistral': 3365, 'n_tokens_neox': 3206, 'n_words': 1301}