def _initialize_geo_bypass(self, geo_bypass_context):
    "\n        Initialize geo restriction bypass mechanism.\n\n        This method is used to initialize geo bypass mechanism based on faking\n        X-Forwarded-For HTTP header. A random country from provided country list\n        is selected and a random IP belonging to this country is generated. This\n        IP will be passed as X-Forwarded-For HTTP header in all subsequent\n        HTTP requests.\n\n        This method will be used for initial geo bypass mechanism initialization\n        during the instance initialization with _GEO_COUNTRIES and\n        _GEO_IP_BLOCKS.\n\n        You may also manually call it from extractor's code if geo bypass\n        information is not available beforehand (e.g. obtained during\n        extraction) or due to some other reason. In this case you should pass\n        this information in geo bypass context passed as first argument. It may\n        contain following fields:\n\n        countries:  List of geo unrestricted countries (similar\n                    to _GEO_COUNTRIES)\n        ip_blocks:  List of geo unrestricted IP blocks in CIDR notation\n                    (similar to _GEO_IP_BLOCKS)\n\n        "
    if (not self._x_forwarded_for_ip):
        if (not self._downloader.params.get('geo_bypass', True)):
            return
        if (not geo_bypass_context):
            geo_bypass_context = {}
        if isinstance(geo_bypass_context, (list, tuple)):
            geo_bypass_context = {'countries': geo_bypass_context}
        ip_block = self._downloader.params.get('geo_bypass_ip_block', None)
        if (not ip_block):
            ip_blocks = geo_bypass_context.get('ip_blocks')
            if (self._GEO_BYPASS and ip_blocks):
                ip_block = random.choice(ip_blocks)
        if ip_block:
            self._x_forwarded_for_ip = GeoUtils.random_ipv4(ip_block)
            if self._downloader.params.get('verbose', False):
                self._downloader.to_screen(('[debug] Using fake IP %s as X-Forwarded-For.' % self._x_forwarded_for_ip))
            return
        country = self._downloader.params.get('geo_bypass_country', None)
        if (not country):
            countries = geo_bypass_context.get('countries')
            if (self._GEO_BYPASS and countries):
                country = random.choice(countries)
        if country:
            self._x_forwarded_for_ip = GeoUtils.random_ipv4(country)
            if self._downloader.params.get('verbose', False):
                self._downloader.to_screen(('[debug] Using fake IP %s (%s) as X-Forwarded-For.' % (self._x_forwarded_for_ip, country.upper())))
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 and
_GEO_IP_BLOCKS.

You may also manually call it from extractor's code if geo bypass
information is not available beforehand (e.g. obtained during
extraction) or due to some other reason. In this case you should pass
this information in geo bypass context passed as first argument. It may
contain following fields:

countries:  List of geo unrestricted countries (similar
            to _GEO_COUNTRIES)
ip_blocks:  List of geo unrestricted IP blocks in CIDR notation
            (similar to _GEO_IP_BLOCKS)
def _initialize_geo_bypass(self, geo_bypass_context):
    "\n        Initialize geo restriction bypass mechanism.\n\n        This method is used to initialize geo bypass mechanism based on faking\n        X-Forwarded-For HTTP header. A random country from provided country list\n        is selected and a random IP belonging to this country is generated. This\n        IP will be passed as X-Forwarded-For HTTP header in all subsequent\n        HTTP requests.\n\n        This method will be used for initial geo bypass mechanism initialization\n        during the instance initialization with _GEO_COUNTRIES and\n        _GEO_IP_BLOCKS.\n\n        You may also manually call it from extractor's code if geo bypass\n        information is not available beforehand (e.g. obtained during\n        extraction) or due to some other reason. In this case you should pass\n        this information in geo bypass context passed as first argument. It may\n        contain following fields:\n\n        countries:  List of geo unrestricted countries (similar\n                    to _GEO_COUNTRIES)\n        ip_blocks:  List of geo unrestricted IP blocks in CIDR notation\n                    (similar to _GEO_IP_BLOCKS)\n\n        "
    if (not self._x_forwarded_for_ip):
        if (not self._downloader.params.get('geo_bypass', True)):
            return
        if (not geo_bypass_context):
            geo_bypass_context = {}
        if isinstance(geo_bypass_context, (list, tuple)):
            geo_bypass_context = {'countries': geo_bypass_context}
        ip_block = self._downloader.params.get('geo_bypass_ip_block', None)
        if (not ip_block):
            ip_blocks = geo_bypass_context.get('ip_blocks')
            if (self._GEO_BYPASS and ip_blocks):
                ip_block = random.choice(ip_blocks)
        if ip_block:
            self._x_forwarded_for_ip = GeoUtils.random_ipv4(ip_block)
            if self._downloader.params.get('verbose', False):
                self._downloader.to_screen(('[debug] Using fake IP %s as X-Forwarded-For.' % self._x_forwarded_for_ip))
            return
        country = self._downloader.params.get('geo_bypass_country', None)
        if (not country):
            countries = geo_bypass_context.get('countries')
            if (self._GEO_BYPASS and countries):
                country = random.choice(countries)
        if country:
            self._x_forwarded_for_ip = GeoUtils.random_ipv4(country)
            if self._downloader.params.get('verbose', False):
                self._downloader.to_screen(('[debug] Using fake IP %s (%s) as X-Forwarded-For.' % (self._x_forwarded_for_ip, country.upper())))