(sources_list)
Find the URL of the main mirror that is currently in use by ``apt-get``.

    :param sources_list: The contents of apt's package resource list, e.g. the
                         contents of :attr:`main_sources_list` (a string).
    :returns: The URL of the main mirror in use (a string).
    :raises: If the main mirror can't be determined
             :exc:`~exceptions.EnvironmentError` is raised.

    The main mirror is determined by looking for the first ``deb`` or
    ``deb-src`` directive in apt's package resource list whose URL uses the
    HTTP or FTP scheme and whose components contain ``main``.
Find the URL of the main mirror that is currently in use by ``apt-get``.
Find the URL of the main mirror that is currently in use by apt - get .
def find_current_mirror(sources_list):
    """
    Find the URL of the main mirror that is currently in use by ``apt-get``.

    :param sources_list: The contents of apt's package resource list, e.g. the
                         contents of :attr:`main_sources_list` (a string).
    :returns: The URL of the main mirror in use (a string).
    :raises: If the main mirror can't be determined
             :exc:`~exceptions.EnvironmentError` is raised.

    The main mirror is determined by looking for the first ``deb`` or
    ``deb-src`` directive in apt's package resource list whose URL uses the
    HTTP or FTP scheme and whose components contain ``main``.
    """
    for line in sources_list.splitlines():
        # The first token should be `deb' or `deb-src', the second token is
        # the mirror's URL, the third token is the `distribution' and any
        # further tokens are `components'.
        tokens = line.split()
        if (len(tokens) >= 4
                and tokens[0] in ('deb', 'deb-src')
                and tokens[1].startswith(('http://', 'https://', 'ftp://', 'mirror://'))
                and 'main' in tokens[3:]):
            return tokens[1]
    raise EnvironmentError("Failed to determine current mirror in apt's package resource list!")
def find_current_mirror ( sources_list ) : for line in sources_list . splitlines ( ) : # The first token should be `deb' or `deb-src', the second token is # the mirror's URL, the third token is the `distribution' and any # further tokens are `components'. tokens = line . split ( ) if ( len ( tokens ) >= 4 and tokens [ 0 ] in ( 'deb' , 'deb-src' ) and tokens [ 1 ] . startswith ( ( 'http://' , 'https://' , 'ftp://' , 'mirror://' ) ) and 'main' in tokens [ 3 : ] ) : return tokens [ 1 ] raise EnvironmentError ( "Failed to determine current mirror in apt's package resource list!" )