Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: third_party/twisted_8_1/twisted/web/rewrite.py

Issue 12261012: Remove third_party/twisted_8_1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 #
5 from twisted.web import resource
6
7 class RewriterResource(resource.Resource):
8
9 def __init__(self, orig, *rewriteRules):
10 resource.Resource.__init__(self)
11 self.resource = orig
12 self.rewriteRules = list(rewriteRules)
13
14 def _rewrite(self, request):
15 for rewriteRule in self.rewriteRules:
16 rewriteRule(request)
17
18 def getChild(self, path, request):
19 request.postpath.insert(0, path)
20 request.prepath.pop()
21 self._rewrite(request)
22 path = request.postpath.pop(0)
23 request.prepath.append(path)
24 return self.resource.getChildWithDefault(path, request)
25
26 def render(self, request):
27 self._rewrite(request)
28 return self.resource.render(request)
29
30
31 def tildeToUsers(request):
32 if request.postpath and request.postpath[0][:1]=='~':
33 request.postpath[:1] = ['users', request.postpath[0][1:]]
34 request.path = '/'+'/'.join(request.prepath+request.postpath)
35
36 def alias(aliasPath, sourcePath):
37 """
38 I am not a very good aliaser. But I'm the best I can be. If I'm
39 aliasing to a Resource that generates links, and it uses any parts
40 of request.prepath to do so, the links will not be relative to the
41 aliased path, but rather to the aliased-to path. That I can't
42 alias static.File directory listings that nicely. However, I can
43 still be useful, as many resources will play nice.
44 """
45 sourcePath = sourcePath.split('/')
46 aliasPath = aliasPath.split('/')
47 def rewriter(request):
48 if request.postpath[:len(aliasPath)] == aliasPath:
49 after = request.postpath[len(aliasPath):]
50 request.postpath = sourcePath + after
51 request.path = '/'+'/'.join(request.prepath+request.postpath)
52 return rewriter
OLDNEW
« no previous file with comments | « third_party/twisted_8_1/twisted/web/resource.py ('k') | third_party/twisted_8_1/twisted/web/script.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698