Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes trailing whitespace and fixes some epydoc warnings #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ To get good API documentation, run:

$ epydoc -n "pyFreenet API manual" -o html fcp

When you install this package (refer INSTALL), you should
When you install this package (refer INSTALL), you should
end up with a command 'freesitemgr' on your PATH.

'freesitemgr' is a console-based freesite insertion utility
Expand Down
70 changes: 35 additions & 35 deletions fcp/fproxyproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ class Handler(SimpleHTTPRequestHandler):
#@ @+others
#@+node:__init__
def __init__(self, request, client_address, server):

self.server = server
SimpleHTTPRequestHandler.__init__(self, request, client_address, server)

#@-node:__init__
#@+node:do_GET
def do_GET(self):

print "GET: client=%s path=%s" % (self.client_address, self.path)

#SimpleHTTPRequestHandler.do_GET(self)

try:
#mimetype, data = self.server.node.get(self.path[1:])
#self.send_response(200)
Expand All @@ -51,14 +51,14 @@ def do_GET(self):
#self.end_headers()
#self.wfile.write(data)
#self.wfile.flush()

self.fproxyGet(self.path)

except:
traceback.print_exc()
self.send_error(404, "File not found")
return None

#@-node:do_GET
#@+node:fproxyGet
def fproxyGet(self, path):
Expand All @@ -67,10 +67,10 @@ def fproxyGet(self, path):
"""
server = self.server
headers = self.headers

print "--------------------------------------------"
print "** path=%s" % path

# first scenario - user is pointing their browser directly at
# fproxyfproxy, barf!
if not path.startswith("http://"):
Expand All @@ -92,25 +92,25 @@ def fproxyGet(self, path):
self.wfile.write(data)
self.wfile.flush()
return

# convert path to relative
path = "/" + path[7:].split("/", 1)[-1]
#print "** path=%s" % repr(path)


try:
# check host header
hostname = headers.get("Host", 'fproxy')
pathbits = path.split("/")

print "** hostname = %s" % hostname

# second scenario, user has just given a domain name without trailing /
if len(pathbits) == 1:
# redirect to force trailing slash
location = path + "/"
print "** redirecting to: %s" % location

self.send_response(301)
self.send_header("Content-type", "text/html")
data = "\n".join([
Expand All @@ -128,12 +128,12 @@ def fproxyGet(self, path):
self.wfile.write(data)
self.wfile.flush()
return

tail = "/".join(pathbits[1:])

# third scenario - request into fproxy
if hostname == 'fproxy':

# tis an fproxy request, go straight through
conn = HTTPConnection(server.fproxyHost, server.fproxyPort)
conn.request("GET", path)
Expand All @@ -148,11 +148,11 @@ def fproxyGet(self, path):
self.wfile.flush()
conn.close()
return

else:
# final scenario - some other domain, try lookup
uri = server.node.namesiteLookup(hostname)

if not uri:
# lookup failed, do the usual 404 thang
print "** lookup of domain %s failed" % hostname
Expand All @@ -175,7 +175,7 @@ def fproxyGet(self, path):
self.end_headers()
self.wfile.write(data)
self.wfile.flush()

# lookup succeeded - ok to go now via fproxy
conn = HTTPConnection(server.fproxyHost, server.fproxyPort)
newpath = "/" + uri
Expand All @@ -190,7 +190,7 @@ def fproxyGet(self, path):
self.send_response(resp.status)
self.send_header("Content-type",
resp.getheader("Content-Type", "text/plain"))

# has fproxy sent us a redirect?
if resp.status == 301:
# yuck, fproxy is telling us to redirect, which
Expand All @@ -202,7 +202,7 @@ def fproxyGet(self, path):
print "*** old location = %s" % location
print "*** --> %s" % newLocation
self.send_header("Location", newLocation)

# get the data from fproxy and send it up to the client
data = resp.read()
self.send_header("Content-Length", str(len(data)))
Expand All @@ -211,12 +211,12 @@ def fproxyGet(self, path):
self.wfile.flush()
conn.close()
return

return

except socket.error:
raise

#@-node:fproxyGet
#@-others

Expand All @@ -231,7 +231,7 @@ class FProxyProxy(ThreadingMixIn, HTTPServer):
def __init__(self, **kw):
"""
runs the FProxyProxy service

Keywords:
- node - a live FCPNode object
- fproxyHost - hostname of fproxy
Expand All @@ -241,11 +241,11 @@ def __init__(self, **kw):
"""
for k in ['node', 'fproxyHost', 'fproxyPort', 'listenHost', 'listenPort']:
setattr(self, k, kw[k])

self.log = self.node._log

HTTPServer.__init__(self, (self.listenHost, self.listenPort), Handler)

#@-node:__init__
#@+node:run
def run(self):
Expand All @@ -256,9 +256,9 @@ def run(self):
log(ERROR, "FproxyProxy listening on %s:%s" % (self.listenHost, self.listenPort))
log(ERROR, " -> forwarding requests to fproxy at %s:%s" % (
self.fproxyHost, self.fproxyPort))

self.serve_forever()

#@-node:run
#@-others

Expand Down Expand Up @@ -364,7 +364,7 @@ def main():

if o in ("-H", "--fcpHost"):
fcpHost = a

if o in ("-P", "--fcpPort"):
try:
fcpPort = int(a)
Expand Down Expand Up @@ -392,7 +392,7 @@ def main():
fproxyHost = parts[0]
if parts[1]:
fproxyPort = int(parts[1])

# try to create an FCP node, needed for name lookups
try:
n = node.FCPNode(host=fcpHost, port=fcpPort, verbosity=verbosity,
Expand Down
Loading