def fetch(self, request, callback, **kwargs): if not isinstance(request, HTTPRequest): request = HTTPRequest(url=request, **kwargs) if not isinstance(request.headers, HTTPHeaders): request.headers = HTTPHeaders(request.headers) callback = stack_context.wrap(callback) self.queue.append((request, callback)) self._process_queue() if self.queue: logging.debug("max_clients limit reached, request queued. " "%d active, %d queued requests." % ( len(self.active), len(self.queue)))
def fetch(self, request, callback, **kwargs): if not isinstance(request, HTTPRequest): request = HTTPRequest(url=request, **kwargs) if not isinstance(request.headers, HTTPHeaders): request.headers = HTTPHeaders(request.headers) callback = stack_context.wrap(callback) self.queue.append((request, callback)) self._process_queue() if self.queue: logging.debug("max_clients limit reached, request queued. " "%d active, %d queued requests." % (len(self.active), len(self.queue)))
def __call__(self, path, **kw): # convert list type arguments to something the API likes for k, v in kw.iteritems(): if isinstance(v, _listtypes): kw[k] = ','.join(map(str, list(v))) cache = self._root._handler # now send the request path += ".xml.aspx" if cache: response = cache.retrieve(self._host, path, kw) else: response = None if response is None: # construct the request request = HTTPRequest(url='https://'+self._host+path) request.use_gzip = True if kw: request.body = urllib.urlencode(kw) request.method = 'POST' if self._proxy: request.url = path request.proxy_host, request.proxy_port = self._proxy # fetch from server http_client = HTTPClient() response = http_client.fetch(request) if response.code != 200: if response.code == 404: raise AttributeError("'%s' not available on API server (404 Not Found)" % path) else: raise RuntimeError("'%s' request failed (%d %s)" % (path, response.code, response.error)) # take the response's charset into account if type(response.body) != types.UnicodeType and 'charset' in response.headers["Content-Type"]: charset = response.headers["Content-Type"].split('charset=')[1].strip() response = response.body.decode(charset) else: response = response.body store = not not cache else: store = False retrieve_fallback = cache and getattr(cache, "retrieve_fallback", False) if retrieve_fallback: # implementor is handling fallbacks... try: return _ParseXML(response, True, store and (lambda obj: cache.store(self._host, path, kw, response, obj))) except Error, reason: response = retrieve_fallback(self._host, path, kw, reason=e) if response is not None: return response raise
def fetch(self, request, callback, **kwargs): if not isinstance(request, HTTPRequest): request = HTTPRequest(url=request, **kwargs) self._requests.append((request, stack_context.wrap(callback))) self._process_queue() self._set_timeout(0)