0
我正在创建一个扭曲的简单服务器。我想将配置值存储在yaml文件中。我找不到配置扭曲服务或应用程序特定配置的示例。如何使用扭曲加载自定义配置文件?
由于我提供的实际资源对象将为每个请求创建,显然这不是读取配置文件的正确位置。
我可能会在我的工厂读取配置文件,然后子类Site将它传递给我的资源?我似乎无法找到任何地方记录的模式。
这里是我的代码:
#!/usr/bin/env python
from twisted.internet import reactor
from twisted.web.server import Site
from twisted.web.resource import Resource
import yaml
def load_config():
return yaml.load(file('./test/config_file.yaml', 'r'))
# how can I make this resource have access to my config?
class ScaledImage(Resource):
isLeaf = True
def render_POST(self, request):
return """
<h1>image scaled</h1>
"""
factory = Site(ScaledImage())
reactor.listenTCP(8000, factory)
reactor.run()
这是有道理的。谢谢。 – jbrown