# Path: kingpin/thrift_utils/ttypes.py
# class RetriableRPCException(TException):
#   """
#   Attributes:
#    - errorCode
#    - message
#   """
# 
#   thrift_spec = (
#     None, # 0
#     (1, TType.I32, 'errorCode', None, None, ), # 1
#     (2, TType.STRING, 'message', None, None, ), # 2
#   )
# 
#   def __init__(self, errorCode=None, message=None,):
#     self.errorCode = errorCode
#     self.message = message
# 
#   def read(self, iprot):
#     if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
#       fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
#       return
#     iprot.readStructBegin()
#     while True:
#       (fname, ftype, fid) = iprot.readFieldBegin()
#       if ftype == TType.STOP:
#         break
#       if fid == 1:
#         if ftype == TType.I32:
#           self.errorCode = iprot.readI32();
#         else:
#           iprot.skip(ftype)
#       elif fid == 2:
#         if ftype == TType.STRING:
#           self.message = iprot.readString();
#         else:
#           iprot.skip(ftype)
#       else:
#         iprot.skip(ftype)
#       iprot.readFieldEnd()
#     iprot.readStructEnd()
# 
#   def write(self, oprot):
#     if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
#       oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
#       return
#     oprot.writeStructBegin('RetriableRPCException')
#     if self.errorCode is not None:
#       oprot.writeFieldBegin('errorCode', TType.I32, 1)
#       oprot.writeI32(self.errorCode)
#       oprot.writeFieldEnd()
#     if self.message is not None:
#       oprot.writeFieldBegin('message', TType.STRING, 2)
#       oprot.writeString(self.message)
#       oprot.writeFieldEnd()
#     oprot.writeFieldStop()
#     oprot.writeStructEnd()
# 
#   def validate(self):
#     return
# 
# 
#   def __str__(self):
#     return repr(self)
# 
#   def __repr__(self):
#     L = ['%s=%r' % (key, value)
#       for key, value in self.__dict__.iteritems()]
#     return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
# 
#   def __eq__(self, other):
#     return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
# 
#   def __ne__(self, other):
#     return not (self == other)


from .ttypes import RetriableRPCException
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License 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.

"""The policy on whether to retry a thrift request on a given exception."""



class RetryPolicy(object):
    """This class encapsulate the logic on whether to retry a thrift request
     given a particular exception.

    """
    def should_retry(self, exception):
        """Whether to retry a thrift request on the given exception.

        Args:
            exception: The exception thrown by the previous thrift request.

        Returns:
            True, if the request should be retried; False, otherwise.

        """
        # only service specific exceptions need to be considered

# Path: kingpin/thrift_utils/ttypes.py
# class RetriableRPCException(TException):
#   """
#   Attributes:
#    - errorCode
#    - message
#   """
# 
#   thrift_spec = (
#     None, # 0
#     (1, TType.I32, 'errorCode', None, None, ), # 1
#     (2, TType.STRING, 'message', None, None, ), # 2
#   )
# 
#   def __init__(self, errorCode=None, message=None,):
#     self.errorCode = errorCode
#     self.message = message
# 
#   def read(self, iprot):
#     if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
#       fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
#       return
#     iprot.readStructBegin()
#     while True:
#       (fname, ftype, fid) = iprot.readFieldBegin()
#       if ftype == TType.STOP:
#         break
#       if fid == 1:
#         if ftype == TType.I32:
#           self.errorCode = iprot.readI32();
#         else:
#           iprot.skip(ftype)
#       elif fid == 2:
#         if ftype == TType.STRING:
#           self.message = iprot.readString();
#         else:
#           iprot.skip(ftype)
#       else:
#         iprot.skip(ftype)
#       iprot.readFieldEnd()
#     iprot.readStructEnd()
# 
#   def write(self, oprot):
#     if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
#       oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
#       return
#     oprot.writeStructBegin('RetriableRPCException')
#     if self.errorCode is not None:
#       oprot.writeFieldBegin('errorCode', TType.I32, 1)
#       oprot.writeI32(self.errorCode)
#       oprot.writeFieldEnd()
#     if self.message is not None:
#       oprot.writeFieldBegin('message', TType.STRING, 2)
#       oprot.writeString(self.message)
#       oprot.writeFieldEnd()
#     oprot.writeFieldStop()
#     oprot.writeStructEnd()
# 
#   def validate(self):
#     return
# 
# 
#   def __str__(self):
#     return repr(self)
# 
#   def __repr__(self):
#     L = ['%s=%r' % (key, value)
#       for key, value in self.__dict__.iteritems()]
#     return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
# 
#   def __eq__(self, other):
#     return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
# 
#   def __ne__(self, other):
#     return not (self == other)


# Path: kingpin/thrift_utils/retry_policy.py
from .ttypes import RetriableRPCException

# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License 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.

"""The policy on whether to retry a thrift request on a given exception."""



class RetryPolicy(object):
    """This class encapsulate the logic on whether to retry a thrift request
     given a particular exception.

    """
    def should_retry(self, exception):
        """Whether to retry a thrift request on the given exception.

        Args:
            exception: The exception thrown by the previous thrift request.

        Returns:
            True, if the request should be retried; False, otherwise.

        """
        # only service specific exceptions need to be considered

        return isinstance(exception, RetriableRPCException)