'Initialize geo restriction bypass mechanism.
This method is used to initialize geo bypass mechanism based on faking
X-Forwarded-For HTTP header. A random country from provided country list
is selected and a random IP belonging to this country is generated. This
IP will be passed as X-Forwarded-For HTTP header in all subsequent
HTTP requests.
This method will be used for initial geo bypass mechanism initialization
during the instance initialization with _GEO_COUNTRIES.
You may also manually call it from extractor\'s code if geo countries
information is not available beforehand (e.g. obtained during
extraction) or due to some another reason.'

def _initialize_geo_bypass(self, countries):

    if (not self._x_forwarded_for_ip):
        country_code = self._downloader.params.get(u'geo_bypass_country', None)
        if ((not country_code) and self._GEO_BYPASS and self._downloader.params.get(u'geo_bypass', True) and countries):
            country_code = random.choice(countries)
        if country_code:
            self._x_forwarded_for_ip = GeoUtils.random_ipv4(country_code)
            if self._downloader.params.get(u'verbose', False):
                self._downloader.to_screen((u'[debug]    Using    fake    IP    %s    (%s)    as    X-Forwarded-For.' % (self._x_forwarded_for_ip, country_code.upper())))
