Example #1
0
 def _refresh_authentication_token_broken(self):
     """
     POST to ArcGIS requesting a new token.
     """
     if self.retry == self._MAX_RETRIES:
         raise GeocoderAuthenticationFailure(
             'Too many retries for auth: %s' % self.retry)
     token_request_arguments = {
         'username': self.username,
         'password': self.password,
         'client': 'requestip',
         #'referer': 'requestip',
         'expiration': self.token_lifetime,
         'f': 'json'
     }
     self.token_expiry = int(time()) + self.token_lifetime
     data = urlencode(token_request_arguments)
     print(data)
     data = data.encode("utf-8")
     print(data)
     req = Request(url=self.auth_api, headers=self.headers)
     print(req)
     page = urlopen(req, data=data, timeout=self.timeout)
     print(page)
     page = page.read()
     print(page)
     response = json.loads(page.decode('unicode_escape'))
     if not 'token' in response:
         raise GeocoderAuthenticationFailure(
             'Missing token in auth request. '
             'Request URL: %s?%s. '
             'Response JSON: %s. ' %
             (self.auth_api, data, json.dumps(response)))
     self.retry = 0
     self.token = response['token']
Example #2
0
 def test_geocoder_constructor_uses_str_proxy(self):
     base_http = urlopen(self.remote_website_http, timeout=self.timeout)
     base_html = base_http.read()
     geocoder_dummy = DummyGeocoder(proxies=self.proxy_url,
                                    timeout=self.timeout)
     self.assertEqual(0, len(self.proxy_server.requests))
     self.assertEqual(base_html,
                      geocoder_dummy.geocode(self.remote_website_http))
     self.assertEqual(1, len(self.proxy_server.requests))
            def do_GET(self):
                requests.append(self.path)

                req = urlopen(self.path, timeout=self.timeout)
                self.send_response(req.getcode())
                self.send_header('Connection', 'close')
                self.end_headers()
                self.copyfile(req, self.wfile)
                self.connection.close()
                req.close()
Example #4
0
            def do_GET(self):
                requests.append(self.path)

                req = urlopen(self.path, timeout=self.timeout)
                self.send_response(req.getcode())
                self.send_header('Connection', 'close')
                self.end_headers()
                self.copyfile(req, self.wfile)
                self.connection.close()
                req.close()
Example #5
0
 def test_geocoder_constructor_uses_str_proxy(self):
     base_http = urlopen(self.remote_website_http, timeout=self.timeout)
     base_html = base_http.read()
     geocoder_dummy = DummyGeocoder(proxies=self.proxy_url,
                                    timeout=self.timeout)
     self.assertEqual(0, len(self.proxy_server.requests))
     self.assertEqual(
         base_html,
         geocoder_dummy.geocode(self.remote_website_http)
     )
     self.assertEqual(1, len(self.proxy_server.requests))
Example #6
0
    def setUp(self):

        # TODO subprocess.Popen proxy locally on os.name=="posix", and skip if not

        # Backup environ settings
        self.orig_http_proxy = os.environ['http_proxy'] if 'http_proxy' in os.environ else None

        # Get HTTP for comparison before proxy test
        base_http = urlopen('http://www.blankwebsite.com/')
        base_html = base_http.read()
        self.noproxy_data = base_html if base_html else None

        # Create the proxy instance
        self.proxyd = proxy_server.ProxyServer()
        # Set the http_proxy environment variable with Proxy_server default value
        os.environ['http_proxy'] = self.proxyd.get_proxy_url()
Example #7
0
    def setUp(self):

        # TODO subprocess.Popen proxy locally on os.name=="posix", and skip if not

        # Backup environ settings
        self.orig_http_proxy = os.environ[
            'http_proxy'] if 'http_proxy' in os.environ else None

        # Get HTTP for comparison before proxy test
        base_http = urlopen('http://www.blankwebsite.com/')
        base_html = base_http.read()
        self.noproxy_data = base_html if base_html else None

        # Create the proxy instance
        self.proxyd = proxy_server.ProxyServer()
        # Set the http_proxy environment variable with Proxy_server default value
        os.environ['http_proxy'] = self.proxyd.get_proxy_url()
Example #8
0
 def geocode(self, location):
     geo_request = urlopen(location)
     geo_html = geo_request.read()
     return geo_html if geo_html else None
Example #9
0
 def geocode(self, location):
     geo_request = urlopen(location)
     geo_html = geo_request.read()
     return geo_html if geo_html else None