title: How to load custom configuration file with twisted?
body: <p>I'm creating a simple server with twisted. I want to store config values in a yaml file. I can't find examples of configuring twisted services or applications with app-specific config.</p>
  
  <p>Since the actual Resource object I'm serving will be created for each request, obviously this isn't the right place to read a config file.</p>
  
  <p>Would I read the config file in my factory perhaps, and then subclass Site to pass it to my resource? I just can't seem to find the pattern documented anywhere.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>#!/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 """
  &lt;h1&gt;image scaled&lt;/h1&gt;
      """
  
  factory = Site(ScaledImage())
  reactor.listenTCP(8000, factory)
  reactor.run()
  </code></pre>