Created
January 4, 2014 12:02
-
-
Save huyx/8254751 to your computer and use it in GitHub Desktop.
支持 Twisted Web 中的 rpy 文件,作了下列定制: - 由于很多编辑器不支持 .rpy 文件的语法高亮,改用 .py 作为 rpy 文件扩展名 - 允许不指定 .html 和 .py 扩展名,默认按照 .html 和 .py 的顺序查找文件 - 索引文件默认为: index.html, index.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from twisted.web import static, script | |
class PyFile(static.File): | |
u'''支持 Twisted Web 中的 rpy 文件,作了下列定制: | |
- 由于很多编辑器不支持 .rpy 文件的语法高亮,改用 .py 作为 rpy 文件扩展名 | |
- 允许不指定 .html 和 .py 扩展名,默认按照 .html 和 .py 的顺序查找文件 | |
- 索引文件默认为: index.html, index.py | |
''' | |
processors = { | |
'.py': script.ResourceScript | |
} | |
indexNames = ['index.html', 'index.py'] | |
def __init__(self, path, defaultType="text/html", ignoredExts=(), registry=None, allowExt=0): | |
if ignoredExts == (): | |
ignoredExts = '.html .py'.split() | |
static.File.__init__(self, path, ignoredExts=ignoredExts) | |
if __name__ == '__main__': | |
from twisted.web.server import Site | |
from twisted.internet import reactor | |
from twisted.python import log | |
import sys | |
log.startLogging(sys.stdout) | |
resource = PyFile('www') | |
factory = Site(resource) | |
reactor.listenTCP(8888, factory) | |
reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment