Example #1
0
def indexFile(IPFSHash):
    path = IPFSGateway+IPFSHash
    req = requests.get(path)
    print("got request")
    rawText = req.text
    bloom = generateBloomFilter(tokenizeHTML(rawText))
    return bloom
Example #2
0
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()
Example #3
0
    def ping(self,remote):
        try:
            r = requests.get(remote.addr+"api/v0/peer/ping")

            return r.status_code == requests.codes.ok
        except:
            return False
Example #4
0
    def ping(self, service, remote):
        try:
            r = requests.get(remote.addr + service + "/peer/ping")

            return r.status_code == requests.codes.ok
        except:
            return False
Example #5
0
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()
Example #6
0
    def ping(self,service,remote):
        try:
            r = requests.get(remote.addr+service+"/peer/ping")

            return r.status_code == requests.codes.ok
        except:
            return False
Example #7
0
def indexFile(IPFSHash):
    path = IPFSGateway + IPFSHash
    req = requests.get(path)
    print("got request")
    rawText = req.text
    bloom = generateBloomFilter(tokenizeHTML(rawText))
    return bloom
Example #8
0
 def getIP(self, service, remote):
     ip = None
     try:
         r = requests.get(remote.addr + service + "/peer/getmyIP")
         ip = r.text
     except:
         raise DialFailed()
     return ip
Example #9
0
 def getIP(self,remote):
     ip = None
     try:
         r = requests.get(remote.addr+"api/v0/peer/getmyIP")
         ip = r.text
     except:
         raise DialFailed()
     return ip
Example #10
0
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
Example #11
0
 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
Example #12
0
 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
Example #13
0
 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
Example #14
0
 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
Example #15
0
    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)
Example #16
0
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
Example #17
0
 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
Example #18
0
 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
Example #19
0
 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
Example #20
0
 def crawler(self, url):
     return myrequests.get(url).content
Example #21
0
 def test_HTTPS_200_OK_GET(self):
     r = myrequests.get('https://www.baidu.com')
     self.assertEqual(r.status_code, 200)
Example #22
0
 def test_invald_url(self):
     r = myrequests.get('http://wwwwwwww')
     self.assertEqual(r, None)
Example #23
0
 def wsResolve(path):
     newpath = ''.join((path,"websocket/client/wsinfo"))
     print(newpath)
     r = requests.get(newpath)
     return r.text
Example #24
0
def test_myrequests1(url):

    for n in range(100):
        r = myrequests.get(url)
Example #25
0
def test_myrequests2(url):

    for n in range(100):
        r = myrequests.get(url, headers=headers)
Example #26
0
def test_myrequests1(url):

    for n in range(100):
        r = myrequests.get(url)
        print(r.request.headers)