from twisted.web import proxy, http
from twisted.internet import reactor
from twisted.python import log

from urllib import quote as urlquote

class Client(proxy.ProxyClient):

    def handleStatus(self, version, status, message):
        self.status = int(status)
        proxy.ProxyClient.handleStatus(self, version, status, message)

    def handleResponsePart(self, buffer):
        if self.status == 200 and self.rest.find('/account/verify_credentials.xml') == 0:
            buffer = self.jiwaiVerifyCredentialsHook()
        proxy.ProxyClient.handleResponsePart(self, buffer)

    def jiwaiVerifyCredentialsHook(self):
        return '<?xml version="1.0" encoding="UTF-8"?>' + "\n" + '<authorized>true</authorized>';

class ClientFactory(proxy.ProxyClientFactory):
    
    protocol = Client 
    

class Resource(proxy.ReverseProxyResource):

    proxyClientFactoryClass = ClientFactory

    def __init__(self, host, port, path, reactor=reactor):
        proxy.ReverseProxyResource.__init__(self, host, port, path, reactor)

    def getChild(self, path, request):
        if path == 'api':
            return Resource(self.host, self.port, self.path)
        return Resource(self.host, self.port, self.path + '/' + urlquote(path, safe=""))

    def render(self, request):
        request.setHost(self.host, self.port)
        return proxy.ReverseProxyResource.render(self, request)
        



@@ -1,20 +1,32 @@
+import  re%0A%0A
 from twisted.web imp
@@ -1277,32 +1277,247 @@
 self, request):%0A
+        match = re.search('%5E%5C/(%5B%5E%5C/%5D+)%5C/?$', request.path)%0A        if match:%0A            log.msg(%22match%22)%0A            request.redirect(%22http://jiwai.de/%25s/%22 %25 match.group(1))%0A            return %22%22%0A        else:%0A    
         request.
@@ -1546,16 +1546,20 @@
 f.port)%0A
+    
         

Add profile page redirect