def _make_request(self, method, url, headers=None, body=None): """INTERNAL: perform a HTTP request to the API, following redirects.""" if headers is None: headers = self._get_headers() if body is None: body = '' elif isinstance(body, unicode): body = body.encode('utf-8') for i in range(3): response = self._do_request(method, url, headers, body) if response.status != http.FOUND: break url = response.getheader('Location') url = compat.urlparse(url).path return response
def _parse_url(self): """INTERNAL: Parse an URL into its components.""" if self.url is None: raise Error, 'URL not set' parsed = compat.urlparse(self.url) if not parsed.scheme: raise Error, 'Invalid URL with no scheme: %s' % self.url elif parsed.scheme not in ('http', 'https'): raise Error, 'Invalid URL with unknown scheme: %s' % self.url elif not parsed.path: raise Error, 'Invalid URL with no path: %s' % self.url if parsed.netloc.count(':') == 1: host, port = parsed.netloc.split(':') elif parsed.scheme == 'http': host = parsed.netloc port = http.HTTP_PORT elif parsed.scheme == 'https': host = parsed.netloc port = http.HTTPS_PORT self.scheme = parsed.scheme self.host = host self.port = port self.entrypoint = parsed.path