From c4de0806e7d4a0246329fcc88237903a0e291341 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Tue, 3 Apr 2012 13:25:29 +0000 Subject: [PATCH] -proxy work --- src/gns/proxy/gnunet-gns-proxy.py | 27 +++++++++++++++++++-------- src/gns/test_gns_simple_lookup.conf | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/gns/proxy/gnunet-gns-proxy.py b/src/gns/proxy/gnunet-gns-proxy.py index f13a0adad..d53776872 100644 --- a/src/gns/proxy/gnunet-gns-proxy.py +++ b/src/gns/proxy/gnunet-gns-proxy.py @@ -22,7 +22,7 @@ Any help will be greatly appreciated. SUZUKI Hisao __version__ = "0.2.1" -import BaseHTTPServer, select, socket, SocketServer, urlparse, re, string, os +import BaseHTTPServer, select, socket, SocketServer, urlparse, re, string, os, sys class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): __base = BaseHTTPServer.BaseHTTPRequestHandler @@ -87,22 +87,33 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): print "\t" "bye" soc.close() self.connection.close() + + def test_re2(self, mo): + short = os.popen("gnunet-gns -s"+string.replace(mo.group(1), 'a href="http://', "")) + lines = short.readlines() + if (len(lines) < 1): + return mo.group(1) + elif (len(lines[0].split(" ")) > 0): + return 'a href="http://'+lines[0].split(" ")[-1].rstrip() + else: + return mo.group(1) def shorten_zkey(self): - return lambda mo: 'a href="http://'+os.popen("gnunet-gns -s"+string.replace(mo.group(1), 'a href="http://', "")).readlines()[0].split(" ")[-1].rstrip() + return lambda mo: self.test_re2(mo) + #return lambda mo: 'a href="http://'+os.popen("gnunet-gns -s"+string.replace(mo.group(1), 'a href="http://', "")).readlines()[0].split(" ")[-1].rstrip() def test_re(self, to_repl, mo): short = os.popen("gnunet-gns -s "+string.replace(mo.group(1)+to_repl, 'a href="http://', "")) lines = short.readlines() if (len(lines) < 1): return to_repl - elif (len(lines.split(" ")) > 0): - return 'a href="http://'+lines.split(" ")[-1].rstrip() + elif (len(lines[0].split(" ")) > 0): + return 'a href="http://'+lines[0].split(" ")[-1].rstrip() else: return to_repl def replace_and_shorten(self, to_repl): - return lambda mo: test_re(self, to_repl, mo) + return lambda mo: self.test_re(to_repl, mo) # return lambda mo: 'a href="http://'+os.popen("gnunet-gns -s "+string.replace(mo.group(1)+to_repl, 'a href="http://', "")).readlines()[0].split(" ")[-1].rstrip() #full = string.replace(mo.group(1)+to_repl, 'a href="http://', "") #print 'calling gnunet-gns -s '+full @@ -166,7 +177,7 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): out = soc data = i.recv(8192) if data: - try: + #try: data = re.sub(r'\nAccept-Ranges: \w+', r'', data) data = re.sub('(a href="http://(\w+\.)*zkey)', self.shorten_zkey(), data) @@ -177,8 +188,8 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): self.replace_and_shorten(to_repl), data) out.send(data) count = 0 - except: - print "GNS exception:", sys.exc_info()[0] + #except: + # print "GNS exception:", sys.exc_info()[0] else: print "\t" "idle", count diff --git a/src/gns/test_gns_simple_lookup.conf b/src/gns/test_gns_simple_lookup.conf index b609e03b2..410fe6319 100644 --- a/src/gns/test_gns_simple_lookup.conf +++ b/src/gns/test_gns_simple_lookup.conf @@ -1,3 +1,4 @@ +@INLINE@ test_gns_defaults.conf [fs] AUTOSTART = NO -- 2.25.1