# Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. # from twisted.web import resource class RewriterResource(resource.Resource): def __init__(self, orig, *rewriteRules): resource.Resource.__init__(self) self.resource = orig self.rewriteRules = list(rewriteRules) def _rewrite(self, request): for rewriteRule in self.rewriteRules: rewriteRule(request) def getChild(self, path, request): request.postpath.insert(0, path) request.prepath.pop() self._rewrite(request) path = request.postpath.pop(0) request.prepath.append(path) return self.resource.getChildWithDefault(path, request) def render(self, request): self._rewrite(request) return self.resource.render(request) def tildeToUsers(request): if request.postpath and request.postpath[0][:1]=='~': request.postpath[:1] = ['users', request.postpath[0][1:]] request.path = '/'+'/'.join(request.prepath+request.postpath) def alias(aliasPath, sourcePath): """ I am not a very good aliaser. But I'm the best I can be. If I'm aliasing to a Resource that generates links, and it uses any parts of request.prepath to do so, the links will not be relative to the aliased path, but rather to the aliased-to path. That I can't alias static.File directory listings that nicely. However, I can still be useful, as many resources will play nice. """ sourcePath = sourcePath.split('/') aliasPath = aliasPath.split('/') def rewriter(request): if request.postpath[:len(aliasPath)] == aliasPath: after = request.postpath[len(aliasPath):] request.postpath = sourcePath + after request.path = '/'+'/'.join(request.prepath+request.postpath) return rewriter
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
_auth | Folder | 0755 |
|
|
test | Folder | 0755 |
|
|
__init__.py | File | 699 B | 0644 |
|
_element.py | File | 5.81 KB | 0644 |
|
_flatten.py | File | 15.54 KB | 0644 |
|
_http2.py | File | 48 KB | 0644 |
|
_newclient.py | File | 61.84 KB | 0644 |
|
_responses.py | File | 3.57 KB | 0644 |
|
_stan.py | File | 10.54 KB | 0644 |
|
client.py | File | 74.26 KB | 0644 |
|
demo.py | File | 554 B | 0644 |
|
distrib.py | File | 11.45 KB | 0644 |
|
domhelpers.py | File | 8.44 KB | 0644 |
|
error.py | File | 12.49 KB | 0644 |
|
guard.py | File | 630 B | 0644 |
|
html.py | File | 1.52 KB | 0644 |
|
http.py | File | 96.91 KB | 0644 |
|
http_headers.py | File | 8.04 KB | 0644 |
|
iweb.py | File | 24.97 KB | 0644 |
|
microdom.py | File | 35.35 KB | 0644 |
|
proxy.py | File | 9.6 KB | 0644 |
|
resource.py | File | 12.8 KB | 0644 |
|
rewrite.py | File | 1.81 KB | 0644 |
|
script.py | File | 5.61 KB | 0644 |
|
server.py | File | 25.86 KB | 0644 |
|
static.py | File | 35.12 KB | 0644 |
|
sux.py | File | 20.4 KB | 0644 |
|
tap.py | File | 8.73 KB | 0644 |
|
template.py | File | 17.14 KB | 0644 |
|
twcgi.py | File | 11.08 KB | 0644 |
|
util.py | File | 12.12 KB | 0644 |
|
vhost.py | File | 4.36 KB | 0644 |
|
wsgi.py | File | 21.04 KB | 0644 |
|
xmlrpc.py | File | 19.66 KB | 0644 |
|