~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/core/howto/listings/application/service.tac

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# You can run this .tac file directly with:
 
2
#    twistd -ny service.tac
 
3
 
 
4
"""
 
5
This is an example .tac file which starts a webserver on port 8080 and
 
6
serves files from the current working directory.
 
7
 
 
8
The important part of this, the part that makes it a .tac file, is
 
9
the final root-level section, which sets up the object called 'application'
 
10
which twistd will look for
 
11
"""
 
12
 
 
13
import os
 
14
from twisted.application import service, internet
 
15
from twisted.web import static, server
 
16
 
 
17
def getWebService():
 
18
    """
 
19
    Return a service suitable for creating an application object.
 
20
 
 
21
    This service is a simple web server that serves files on port 8080 from
 
22
    underneath the current working directory.
 
23
    """
 
24
    # create a resource to serve static files
 
25
    fileServer = server.Site(static.File(os.getcwd()))
 
26
    return internet.TCPServer(8080, fileServer)
 
27
 
 
28
# this is the core part of any tac file, the creation of the root-level
 
29
# application object
 
30
application = service.Application("Demo application")
 
31
 
 
32
# attach the service to its parent application
 
33
service = getWebService()
 
34
service.setServiceParent(application)