Skip to content

Commit

Permalink
added support for pythonscript resources (.epy)
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jun 26, 2010
1 parent 7f72ec8 commit 600fa58
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
26 changes: 15 additions & 11 deletions controllers/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import socket, urlparse, os
from twisted.internet import reactor, defer
from twisted.internet.task import deferLater
from twisted.web import server, resource, script
from twisted.web.proxy import ReverseProxyResource
from twisted.web.static import File
from twisted.web import server, resource, static, script, proxy
from twisted.names import client
from random import choice

Expand All @@ -26,9 +24,9 @@ def error(failure):
request.finish()
def direct(config):
endpoint = choice(config.endpoints)
mode = "redirect"
if endpoint == "local":
mode = "serve"
mode = "serve"
if endpoint == "redirect":
mode = "redirect"
elif config.get == "proxy":
mode = "proxy"
d = None
Expand All @@ -46,14 +44,20 @@ def direct(config):

class Controller(MammatusHttpResource):
def serve(self, request, endpoint, config):
path = "".join((self.localRoot, request.uri))
file = File(path)
file.ignoreExt(".rpy")
file.processors = {'.rpy': script.ResourceScript}
path = "".join((self.localRoot, request.path))
if os.path.exists(path) and not path.endswith(".epy"):
file = static.File(path)
else:
if not path.endswith(".epy"):
path = ".".join((path, 'epy'))
if os.path.exists(path):
file = script.PythonScript(path, static.Registry())
else:
file = static.File.childNotFound
file.render(request)
def proxy(self, request, endpoint, config):
host = urlparse.urlparse(endpoint).netloc
rproxy = ReverseProxyResource(host, 80, request.uri)
rproxy = proxy.ReverseProxyResource(host, 80, request.uri)
rproxy.render(request)
def redirect(self, request, endpoint, config):
target = urlparse.urljoin(endpoint, request.uri)
Expand Down
6 changes: 3 additions & 3 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ def test():
def ipaddr(addr):
return addr
d = None
if config.resolve == "self":
d = getOwnIpAddr()
elif config.resolve == "endpoint":
if config.resolve == "endpoint":
endpoint = choice(config.endpoints)
netloc = urlparse.urlparse(endpoint).netloc
d = client.lookupAddress(netloc)
d.addCallback(direct)
else:
d = getOwnIpAddr()
d.addCallback(ipaddr)
return d
d = deferLater(reactor, 0, getConfiguration, name)
Expand Down

0 comments on commit 600fa58

Please sign in to comment.