def call_asynchttp(self, url, data, callback=None): return self.httpmaster.open(url, data=data, headers={'Accept-Encoding': 'bzip2;q=1.0, gzip;q=0.8, compress;q=0.7, identity;q=0.1'}, success=(lambda *a, **k: callback_adapter(parse_response, do_return=False)(callback=callback, *a, **k)), error = callback.error, timeout = callback.timeout)
def call_async(self, url, callback=None): return self.httpmaster.open( url, success=(lambda *a, **k: callbacks.callback_adapter( self.parse_response, do_return=False) (callback=callback, *a, **k)), error=callback.error, timeout=callback.timeout)
def call_asynchttp(self, url, data, callback=None): return self.httpmaster.open( url, data=data, headers={ 'Accept-Encoding': 'bzip2;q=1.0, gzip;q=0.8, compress;q=0.7, identity;q=0.1' }, success=(lambda *a, **k: callback_adapter(parse_response, do_return=False) (callback=callback, *a, **k)), error=callback.error, timeout=callback.timeout)
def _do_call(self, endpoint, method, callback=None, **k): k = prepare_args(k) if self.access_token: k['access_token'] = self.access_token.encode('utf8') url = UrlQuery(self.graph_http + endpoint + '/' + method, **k) log.info("calling method: %s", method) log.info_s("calling: %s with %r", url, k) if self.mode == 'async': return self.call_asynchttp(url, None, callback=callback) elif self.mode == 'console': return call_urllib2(url, None) elif self.mode == 'threaded': from util.threads import threaded return threaded(call_urllib2)(url, None, callback=callback) else: return callback_adapter(call_urllib2)(url, None, callback=callback)
def batch(self, *a, **k): callback = k.pop('callback') k['batch'] = list(a) k = prepare_args(k) if self.access_token: k['access_token'] = self.access_token.encode('utf-8') url = UrlQuery(self.graph_http + self.graph_endpoint) data = self.prepare_values(k) if self.mode == 'async': return self.call_asynchttp(url, data, callback=callback) elif self.mode == 'console': return call_urllib2(url, data) elif self.mode == 'threaded': from util.threads import threaded return threaded(call_urllib2)(url, data, callback=callback) else: return callback_adapter(call_urllib2)(url, data, callback=callback)
def get(self, callback=None, **k): version = self.stringversion from gui.native.helpers import GetUserIdleTime from AccountManager import SECONDS_FOR_IDLE idle = GetUserIdleTime() > (1000 * SECONDS_FOR_IDLE) local_load_exc = getattr(self.profile, 'local_load_exc', None) log.debug('loaded: %s initial: %s', local_load_exc, self.initial) have_acct_data = not bool(local_load_exc) button_clicked = bool(self.initial) log.debug('have_data: %s button_clicked: %s', have_acct_data, button_clicked) if button_clicked and not have_acct_data: state = 'initial_nocache' elif button_clicked: state = 'initial' elif idle: state = 'reconnect_idle' else: state = 'reconnect' url = net.UrlQueryObject('http://%s:%s/load/all/json' % (self.host, self.port), revision=getattr(sys, 'REVISION', 'unknown'), tag=getattr(sys, 'TAG', 'unknown'), username=self.username, version=version, state=state, v=version, **k) log.debug('calling loadbalance URL: %s', url) if self.mode == 'async': return self.call_async(url, callback=callback) elif self.mode == 'console': return self.get_urllib(url) elif self.mode == 'threaded': return threads.threaded(self.get_urllib)(url, callback=callback) else: return callbacks.callback_adapter(self.get_urllib)( url, callback=callback)
def get(self, callback=None, **k): version = self.stringversion from gui.native.helpers import GetUserIdleTime from AccountManager import SECONDS_FOR_IDLE idle = GetUserIdleTime() > (1000 * SECONDS_FOR_IDLE) local_load_exc = getattr(self.profile, 'local_load_exc', None) log.debug('loaded: %s initial: %s', local_load_exc, self.initial) have_acct_data = not bool(local_load_exc) button_clicked = bool(self.initial) log.debug('have_data: %s button_clicked: %s', have_acct_data, button_clicked) if button_clicked and not have_acct_data: state = 'initial_nocache' elif button_clicked: state = 'initial' elif idle: state = 'reconnect_idle' else: state = 'reconnect' url = net.UrlQueryObject('http://%s:%s/load/all/json' % (self.host, self.port), revision = getattr(sys, 'REVISION', 'unknown'), tag = getattr(sys, 'TAG', 'unknown'), username = self.username, version = version, state = state, v = version, **k) log.debug('calling loadbalance URL: %s', url) if self.mode == 'async': return self.call_async(url, callback=callback) elif self.mode == 'console': return self.get_urllib(url) elif self.mode == 'threaded': return threads.threaded(self.get_urllib)(url, callback=callback) else: return callbacks.callback_adapter(self.get_urllib)(url, callback=callback)
def __call__(self, method, callback=None, prepare=False, **k): k = prepare_args(k) data = self.prepare_call(method, **k) if prepare: return data if pref('facebook.api.https', False, bool): url = self.secure_server_url else: url = self.server_url log.info("calling method: %s", method) log.info_s("calling: %s with %r", url, k) callback.error += self.handle_error if self.mode == 'async': return self.call_asynchttp(url, data, callback=callback) elif self.mode == 'console': return call_urllib2(url, data) elif self.mode == 'threaded': from util.threads import threaded return threaded(call_urllib2)(url, data, callback=callback) else: return callback_adapter(call_urllib2)(url, data, callback=callback) log.info("called method: %s", method)
def call_async(self, url, callback=None): return self.httpmaster.open(url, success=(lambda *a, **k: callbacks.callback_adapter(self.parse_response, do_return=False)(callback=callback, *a, **k)), error = callback.error, timeout = callback.timeout)