ó
N_c           @   sU   d  Z  d d l Z d d	 d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(
   s/   Classes for handling failovers for server URLs.iÿÿÿÿNt   baseFailOverMethodc           B   sJ   e  Z d  Z d „  Z d d „ Z d „  Z d d „ Z d „  Z d „  Z	 RS(	   s_   A base class to provide a failover to switch to a new server if
    the current one fails.
    c         C   s   | |  _  d |  _ d  S(   Ni    (   t   repot   failures(   t   selfR   (    (    s0   /usr/lib/python2.7/site-packages/yum/failover.pyt   __init__   s    	c         C   s   d S(   s  Return a server URL based on this failover method, or None
        if there is a complete failure.  This method should always be
        used to translate an index into a URL, as this object may
        change how indexes map.

        :param i: if given, this is the index of the server URL to
           return, instead of using the failures counter
        :return: the next server URL
        N(   t   None(   R   t   i(    (    s0   /usr/lib/python2.7/site-packages/yum/failover.pyt   get_serverurl"   s    
c         C   s   |  j  d |  _  d S(   sO   Notify the failover method that the current server has
        failed.
        i   N(   R   (   R   (    (    s0   /usr/lib/python2.7/site-packages/yum/failover.pyt   server_failed.   s    i    c         C   s   | |  _  d S(   su   Reset the failures counter to the given index.

        :param i: the index to reset the failures counter to
        N(   R   (   R   R   (    (    s0   /usr/lib/python2.7/site-packages/yum/failover.pyt   reset4   s    c         C   s   |  j  S(   s{  Return the current number of failures, which is also the
        current index into the list of URLs that this object
        represents.  :fun:`get_serverurl` should always be used to
        translate an index into a URL, as this object may change how
        indexes map.

        :return: the current number of failures, which is also the
           current index   
        (   R   (   R   (    (    s0   /usr/lib/python2.7/site-packages/yum/failover.pyt	   get_index;   s    
c         C   s   t  |  j j ƒ S(   s   Return the total number of URLs available to cycle through
        in this object.

        :return: the total number of URLs available
        (   t   lenR   t   urls(   R   (    (    s0   /usr/lib/python2.7/site-packages/yum/failover.pyR   G   s    N(
   t   __name__t
   __module__t   __doc__R   R   R   R   R	   R
   R   (    (    (    s0   /usr/lib/python2.7/site-packages/yum/failover.pyR       s   			t   priorityc           B   s   e  Z d  Z d d „ Z RS(   s·   A class to provide a failover to switch to a new server
    if the current one fails.  This classes chooses the next server
    based on the first success in the list of servers.
    c         C   sH   | d k r |  j } n | } | t |  j j ƒ k r: d S|  j j | S(   s  Return the next successful server URL in the list, or None
        if there is a complete failure.  This method should always be
        used to translate an index into a URL, as this object may
        change how indexes map.

        :param i: if given, this is the index of the server URL to
           return, instead of using the failures counter
        :return: the next server URL
        N(   R   R   R   R   R   (   R   R   t   index(    (    s0   /usr/lib/python2.7/site-packages/yum/failover.pyR   V   s    
N(   R   R   R   R   R   (    (    (    s0   /usr/lib/python2.7/site-packages/yum/failover.pyR   Q   s   t
   roundRobinc           B   s#   e  Z d  Z d „  Z d d „ Z RS(   sj  A class to provide a failover to switch to a new server
    if the current one fails.  When an object of this class is
    created, it selects a random place in the list of URLs to begin
    with, then each time :func:`get_serveurl` is called, the next URL
    in the list is returned, cycling back to the beginning of the list
    after the end is reached.
    c         C   s3   t  j |  | ƒ t j ƒ  t j d d ƒ |  _ d  S(   Ni    i%   (   R    R   t   randomt   seedt   randintt   offset(   R   R   (    (    s0   /usr/lib/python2.7/site-packages/yum/failover.pyR   t   s    
c         C   se   | d k r |  j } n | } | t |  j j ƒ k r: d S| |  j t |  j j ƒ } |  j j | S(   s«  Return the next successful server URL in the list, using
        the round robin scheme, or None if there is a complete
        failure.  This method should always be used to translate an
        index into a URL, as this object may change how indexes map.

        :param i: if given, this is the index of the server URL to
           return, instead of using the failures counter
        :return: the next server URL
        N(   R   R   R   R   R   R   (   R   R   R   t   rr(    (    s0   /usr/lib/python2.7/site-packages/yum/failover.pyR   y   s    
N(   R   R   R   R   R   R   (    (    (    s0   /usr/lib/python2.7/site-packages/yum/failover.pyR   l   s   	(    (   R   R   R    R   R   (    (    (    s0   /usr/lib/python2.7/site-packages/yum/failover.pyt   <module>   s   7