def indexFile(IPFSHash): path = IPFSGateway+IPFSHash req = requests.get(path) print("got request") rawText = req.text bloom = generateBloomFilter(tokenizeHTML(rawText)) return bloom
def dial(subnet,target, cmd, **kwargs): buildURL = [target["addr"]] buildURL.append(subnet+"/client/") buildURL.append(cmd) buildURL.append("/") postData = None if cmd == "seek" or cmd == "get": buildURL.append(kwargs["id"]) elif cmd == "poll": buildURL.append(kwargs["id"]) buildURL.append("/") buildURL.append(str(kwargs["time"])) elif cmd == "post": buildURL.append(kwargs["id"]) postData = kwargs["data"] elif cmd == "store": buildURL.append(kwargs["id"]) postData = kwargs["data"] trgAddr = ''.join(buildURL) if postData is not None: r = requests.post(trgAddr, data=postData) if r.text: return r.json() else: r = requests.get(trgAddr) #print(r.text) if len(r.text)>0: if cmd == "get": return r.text else: return r.json()
def ping(self,remote): try: r = requests.get(remote.addr+"api/v0/peer/ping") return r.status_code == requests.codes.ok except: return False
def ping(self, service, remote): try: r = requests.get(remote.addr + service + "/peer/ping") return r.status_code == requests.codes.ok except: return False
def dial(subnet, target, cmd, **kwargs): buildURL = [target["addr"]] buildURL.append(subnet + "/client/") buildURL.append(cmd) buildURL.append("/") postData = None if cmd == "seek" or cmd == "get": buildURL.append(kwargs["id"]) elif cmd == "poll": buildURL.append(kwargs["id"]) buildURL.append("/") buildURL.append(str(kwargs["time"])) elif cmd == "post": buildURL.append(kwargs["id"]) postData = kwargs["data"] elif cmd == "store": buildURL.append(kwargs["id"]) postData = kwargs["data"] trgAddr = ''.join(buildURL) print(trgAddr) if postData is not None: r = requests.post(trgAddr, data=postData) if r.text: return r.json() else: r = requests.get(trgAddr) #print(r.text) if len(r.text) > 0: if cmd == "get": return r.text else: return r.json()
def ping(self,service,remote): try: r = requests.get(remote.addr+service+"/peer/ping") return r.status_code == requests.codes.ok except: return False
def indexFile(IPFSHash): path = IPFSGateway + IPFSHash req = requests.get(path) print("got request") rawText = req.text bloom = generateBloomFilter(tokenizeHTML(rawText)) return bloom
def getIP(self, service, remote): ip = None try: r = requests.get(remote.addr + service + "/peer/getmyIP") ip = r.text except: raise DialFailed() return ip
def getIP(self,remote): ip = None try: r = requests.get(remote.addr+"api/v0/peer/getmyIP") ip = r.text except: raise DialFailed() return ip
def sentence_analyze_matxin(sentence): r = myrequests.get( "http://lindat.mff.cuni.cz/services/udpipe/api/process?tokenizer&tagger&parser&model=russian-syntagrus-ud-2.5-191206&output=matxin&data=" + sentence) if r and r.status_code == 200: root = ET.fromstring(myjson.json.loads(r.text)['result']) return Result(root).childs[0].childs[0] return None
def seekPoint(self, service, remote, point): path = remote.addr + service + "/peer/" + "seekPoint/%s" % point val = None try: r = requests.get(path) results = r.json() val = util.PeerInfo(results["id"], results["addr"], results["loc"]) except Exception: raise DialFailed() return val
def getSuccessors(self, service, remote): result = [] try: r = requests.get(remote.addr + service + "/peer/getSuccessors/") if len(r.json()) == 0: return [] for p in r.json(): newPeer = util.PeerInfo(p["id"], p["addr"], p["loc"]) result.append(newPeer) except Exception: raise DialFailed() return result
def getPredecessor(self, service, remote): result = [] try: r = requests.get(remote.addr + service + "/peer/getPredecessor/") if len(r.json()) == 0: return [] for p in r.json(): newPeer = util.PeerInfo(p["id"], p["addr"], p["loc"]) result.append(newPeer) except Exception: raise DialFailed() return result
def proxy(websocket, path): cmd_text = yield from websocket.recv() print(cmd_text) cmd = json.loads(cmd_text) output = "" if cmd["method"] == "seek": seekarg = cmd["id"] newpath = ''.join((hostPath,"seek/",seekarg)) r = requests.get(newpath) peer = r.json() peerAddr = peer["addr"] wsaddr = wsResolve(peerAddr) peer["wsAddr"] = wsaddr print(json.dumps(peer)) output = json.dumps(peer) if cmd["method"] == "get": seekarg = cmd["id"] newpath = ''.join((hostPath,"get/",seekarg)) r = requests.get(newpath) output = r.text if cmd["method"] == "poll": seekarg = cmd["id"] t = cmd["time"] newpath = ''.join((hostPath,"poll/",seekarg,"/",str(t))) r = requests.get(newpath) output = r.text if cmd["method"] == "store": seekarg = cmd["id"] newpath = ''.join((hostPath,"store/",seekarg)) data = json.dumps(cmd["data"]) r = requests.post(newpath, data=data) output = r.text if cmd["method"] == "post": seekarg = cmd["id"] newpath = ''.join((hostPath,"post/",seekarg)) data = json.dumps(cmd["data"]) r = requests.post(newpath, data=data) output = r.text yield from websocket.send(output)
def sentence_analyze(sentence): r = myrequests.get( "http://lindat.mff.cuni.cz/services/udpipe/api/process?tokenizer&tagger&parser&model=russian-syntagrus-ud-2.5-191206&data=" + sentence) if r and r.status_code == 200: parsed = myjson.json.loads(r.text) return [ line.split('\t') for line in parsed['result'].split('#')[4].split('\n')[1:] ] return None
def seek(self,remote,id): """ This function remotely calls seek on the remote node, asking it to run LogicComponent.seek() on id """ path = remote.addr+"api/v0/peer/"+"seek/%s" % id val = None try: r = requests.get(path) results = r.json() val = util.PeerInfo(results["id"],results["addr"],results["loc"]) except Exception: raise DialFailed() return val
def seek(self, service, remote, id): """ This function remotely calls seek on the remote node, asking it to run LogicComponent.seek() on id """ path = remote.addr + service + "/peer/" + "seek/%s" % id val = None try: r = requests.get(path) results = r.json() val = util.PeerInfo(results["id"], results["addr"], results["loc"]) except Exception: raise DialFailed() return val
def getPeers(self,remote): result = [] try: r = requests.get(remote.addr+"api/v0/peer/getPeers/") #print(r.text) #print(r.text) #print(r.text) if len(r.json()) == 0: return [] for p in r.json(): newPeer = util.PeerInfo(p["id"],p["addr"],p["loc"]) result.append(newPeer) except Exception: raise DialFailed() return result
def crawler(self, url): return myrequests.get(url).content
def test_HTTPS_200_OK_GET(self): r = myrequests.get('https://www.baidu.com') self.assertEqual(r.status_code, 200)
def test_invald_url(self): r = myrequests.get('http://wwwwwwww') self.assertEqual(r, None)
def wsResolve(path): newpath = ''.join((path,"websocket/client/wsinfo")) print(newpath) r = requests.get(newpath) return r.text
def test_myrequests1(url): for n in range(100): r = myrequests.get(url)
def test_myrequests2(url): for n in range(100): r = myrequests.get(url, headers=headers)
def test_myrequests1(url): for n in range(100): r = myrequests.get(url) print(r.request.headers)