We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Update docs for "twisted web" command line
|[<img alt="moshez's avatar" src="https://avatars.githubusercontent.com/u/422703?s=50" width="50" height="50">](https://github.com/moshez)| @moshez reported|
|-|-|
|Trac ID|trac#9434|
|Type|defect|
|Created|2018-04-24 13:18:44Z|

See [#6670](https://github.com/twisted/twisted/issues/6670) [#9402](https://github.com/twisted/twisted/issues/9402) for details

<details><summary>Searchable metadata</summary>

```
trac-id__9434 9434
type__defect defect
reporter__moshez moshez
priority__normal normal
milestone__None None
branch__ 
branch_author__ 
status__closed closed
resolution__fixed fixed
component__core core
keywords__documentation__review documentation, review
time__1524575924346110 1524575924346110
changetime__1524999288440818 1524999288440818
version__None None
owner__Amber_Brown__hawkowl_____ Amber Brown <hawkowl@...>

```
</details>


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/twisted/web/tap.py`
Content:
```
1 # -*- test-case-name: twisted.web.test.test_tap -*-
2 # Copyright (c) Twisted Matrix Laboratories.
3 # See LICENSE for details.
4 
5 """
6 Support for creating a service which runs a web server.
7 """
8 
9 from __future__ import absolute_import, division
10 
11 import os
12 import warnings
13 
14 import incremental
15 
16 from twisted.application import service, strports
17 from twisted.internet import interfaces, reactor
18 from twisted.python import usage, reflect, threadpool, deprecate
19 from twisted.spread import pb
20 from twisted.web import distrib
21 from twisted.web import resource, server, static, script, demo, wsgi
22 from twisted.web import twcgi
23 
24 class Options(usage.Options):
25     """
26     Define the options accepted by the I{twistd web} plugin.
27     """
28     synopsis = "[web options]"
29 
30     optParameters = [["logfile", "l", None,
31                       "Path to web CLF (Combined Log Format) log file."],
32                      ["certificate", "c", "server.pem",
33                       "(DEPRECATED: use --http) "
34                       "SSL certificate to use for HTTPS. "],
35                      ["privkey", "k", "server.pem",
36                       "(DEPRECATED: use --http) "
37                       "SSL certificate to use for HTTPS."],
38                      ]
39 
40     optFlags = [
41         ["notracebacks", "n", (
42             "Do not display tracebacks in broken web pages. Displaying "
43             "tracebacks to users may be security risk!")],
44     ]
45 
46     optFlags.append([
47         "personal", "",
48         "Instead of generating a webserver, generate a "
49         "ResourcePublisher which listens on  the port given by "
50         "--http, or ~/%s " % (distrib.UserDirectory.userSocketName,) +
51         "if --http is not specified."])
52 
53     compData = usage.Completions(
54                    optActions={"logfile" : usage.CompleteFiles("*.log"),
55                                "certificate" : usage.CompleteFiles("*.pem"),
56                                "privkey" : usage.CompleteFiles("*.pem")}
57                    )
58 
59     longdesc = """\
60 This starts a webserver.  If you specify no arguments, it will be a
61 demo webserver that has the Test class from twisted.web.demo in it."""
62 
63     def __init__(self):
64         usage.Options.__init__(self)
65         self['indexes'] = []
66         self['root'] = None
67         self['extraHeaders'] = []
68         self['ports'] = []
69         self['port'] = self['https'] = None
70 
71 
72     def opt_port(self, port):
73         """
74         (DEPRECATED: use --http)
75         Strports description of port to start the server on
76         """
77         msg = deprecate.getDeprecationWarningString(
78             self.opt_port, incremental.Version("Twisted", "NEXT", 0, 0))
79         warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
80         self['port'] = port
81 
82     opt_p = opt_port
83 
84     def opt_https(self, port):
85         """
86         (DEPRECATED: use --http)
87         Port to listen on for Secure HTTP.
88         """
89         msg = deprecate.getDeprecationWarningString(
90             self.opt_https, incremental.Version("Twisted", "NEXT", 0, 0))
91         warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
92         self['https'] = port
93 
94 
95     def opt_listen(self, port):
96         """
97         Add an strports description of port to start the server on.
98         [default: tcp:8080]
99         """
100         self['ports'].append(port)
101 
102 
103     def opt_index(self, indexName):
104         """
105         Add the name of a file used to check for directory indexes.
106         [default: index, index.html]
107         """
108         self['indexes'].append(indexName)
109 
110     opt_i = opt_index
111 
112 
113     def opt_user(self):
114         """
115         Makes a server with ~/public_html and ~/.twistd-web-pb support for
116         users.
117         """
118         self['root'] = distrib.UserDirectory()
119 
120     opt_u = opt_user
121 
122 
123     def opt_path(self, path):
124         """
125         <path> is either a specific file or a directory to be set as the root
126         of the web server. Use this if you have a directory full of HTML, cgi,
127         epy, or rpy files or any other files that you want to be served up raw.
128         """
129         self['root'] = static.File(os.path.abspath(path))
130         self['root'].processors = {
131             '.epy': script.PythonScript,
132             '.rpy': script.ResourceScript,
133         }
134         self['root'].processors['.cgi'] = twcgi.CGIScript
135 
136 
137     def opt_processor(self, proc):
138         """
139         `ext=class' where `class' is added as a Processor for files ending
140         with `ext'.
141         """
142         if not isinstance(self['root'], static.File):
143             raise usage.UsageError(
144                 "You can only use --processor after --path.")
145         ext, klass = proc.split('=', 1)
146         self['root'].processors[ext] = reflect.namedClass(klass)
147 
148 
149     def opt_class(self, className):
150         """
151         Create a Resource subclass with a zero-argument constructor.
152         """
153         classObj = reflect.namedClass(className)
154         self['root'] = classObj()
155 
156 
157     def opt_resource_script(self, name):
158         """
159         An .rpy file to be used as the root resource of the webserver.
160         """
161         self['root'] = script.ResourceScriptWrapper(name)
162 
163 
164     def opt_wsgi(self, name):
165         """
166         The FQPN of a WSGI application object to serve as the root resource of
167         the webserver.
168         """
169         try:
170             application = reflect.namedAny(name)
171         except (AttributeError, ValueError):
172             raise usage.UsageError("No such WSGI application: %r" % (name,))
173         pool = threadpool.ThreadPool()
174         reactor.callWhenRunning(pool.start)
175         reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
176         self['root'] = wsgi.WSGIResource(reactor, pool, application)
177 
178 
179     def opt_mime_type(self, defaultType):
180         """
181         Specify the default mime-type for static files.
182         """
183         if not isinstance(self['root'], static.File):
184             raise usage.UsageError(
185                 "You can only use --mime_type after --path.")
186         self['root'].defaultType = defaultType
187     opt_m = opt_mime_type
188 
189 
190     def opt_allow_ignore_ext(self):
191         """
192         Specify whether or not a request for 'foo' should return 'foo.ext'
193         """
194         if not isinstance(self['root'], static.File):
195             raise usage.UsageError("You can only use --allow_ignore_ext "
196                                    "after --path.")
197         self['root'].ignoreExt('*')
198 
199 
200     def opt_ignore_ext(self, ext):
201         """
202         Specify an extension to ignore.  These will be processed in order.
203         """
204         if not isinstance(self['root'], static.File):
205             raise usage.UsageError("You can only use --ignore_ext "
206                                    "after --path.")
207         self['root'].ignoreExt(ext)
208 
209 
210     def opt_add_header(self, header):
211         """
212         Specify an additional header to be included in all responses. Specified
213         as "HeaderName: HeaderValue".
214         """
215         name, value = header.split(':', 1)
216         self['extraHeaders'].append((name.strip(), value.strip()))
217 
218 
219     def postOptions(self):
220         """
221         Set up conditional defaults and check for dependencies.
222 
223         If SSL is not available but an HTTPS server was configured, raise a
224         L{UsageError} indicating that this is not possible.
225 
226         If no server port was supplied, select a default appropriate for the
227         other options supplied.
228         """
229         if self['port'] is not None:
230             self['ports'].append(self['port'])
231         if self['https'] is not None:
232             try:
233                 reflect.namedModule('OpenSSL.SSL')
234             except ImportError:
235                 raise usage.UsageError("SSL support not installed")
236             sslStrport = 'ssl:port={}:privateKey={}:certKey={}'.format(
237                              self['https'],
238                              self['privkey'],
239                              self['certificate'],
240                          )
241             self['ports'].append(sslStrport)
242         if len(self['ports']) == 0:
243             if self['personal']:
244                 path = os.path.expanduser(
245                     os.path.join('~', distrib.UserDirectory.userSocketName))
246                 self['ports'].append('unix:' + path)
247             else:
248                 self['ports'].append('tcp:8080')
249 
250 
251 
252 def makePersonalServerFactory(site):
253     """
254     Create and return a factory which will respond to I{distrib} requests
255     against the given site.
256 
257     @type site: L{twisted.web.server.Site}
258     @rtype: L{twisted.internet.protocol.Factory}
259     """
260     return pb.PBServerFactory(distrib.ResourcePublisher(site))
261 
262 
263 
264 class _AddHeadersResource(resource.Resource):
265     def __init__(self, originalResource, headers):
266         self._originalResource = originalResource
267         self._headers = headers
268 
269 
270     def getChildWithDefault(self, name, request):
271         for k, v in self._headers:
272             request.responseHeaders.addRawHeader(k, v)
273         return self._originalResource.getChildWithDefault(name, request)
274 
275 
276 
277 def makeService(config):
278     s = service.MultiService()
279     if config['root']:
280         root = config['root']
281         if config['indexes']:
282             config['root'].indexNames = config['indexes']
283     else:
284         # This really ought to be web.Admin or something
285         root = demo.Test()
286 
287     if isinstance(root, static.File):
288         root.registry.setComponent(interfaces.IServiceCollection, s)
289 
290     if config['extraHeaders']:
291         root = _AddHeadersResource(root, config['extraHeaders'])
292 
293     if config['logfile']:
294         site = server.Site(root, logPath=config['logfile'])
295     else:
296         site = server.Site(root)
297 
298     site.displayTracebacks = not config["notracebacks"]
299 
300     if config['personal']:
301         site = makePersonalServerFactory(site)
302     for port in config['ports']:
303         svc = strports.service(port, site)
304         svc.setServiceParent(s)
305     return s
306
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/twisted/web/tap.py b/src/twisted/web/tap.py
--- a/src/twisted/web/tap.py
+++ b/src/twisted/web/tap.py
@@ -30,10 +30,10 @@
     optParameters = [["logfile", "l", None,
                       "Path to web CLF (Combined Log Format) log file."],
                      ["certificate", "c", "server.pem",
-                      "(DEPRECATED: use --http) "
+                      "(DEPRECATED: use --listen) "
                       "SSL certificate to use for HTTPS. "],
                      ["privkey", "k", "server.pem",
-                      "(DEPRECATED: use --http) "
+                      "(DEPRECATED: use --listen) "
                       "SSL certificate to use for HTTPS."],
                      ]
 
@@ -47,8 +47,8 @@
         "personal", "",
         "Instead of generating a webserver, generate a "
         "ResourcePublisher which listens on  the port given by "
-        "--http, or ~/%s " % (distrib.UserDirectory.userSocketName,) +
-        "if --http is not specified."])
+        "--listen, or ~/%s " % (distrib.UserDirectory.userSocketName,) +
+        "if --listen is not specified."])
 
     compData = usage.Completions(
                    optActions={"logfile" : usage.CompleteFiles("*.log"),
@@ -71,7 +71,7 @@
 
     def opt_port(self, port):
         """
-        (DEPRECATED: use --http)
+        (DEPRECATED: use --listen)
         Strports description of port to start the server on
         """
         msg = deprecate.getDeprecationWarningString(
@@ -83,7 +83,7 @@
 
     def opt_https(self, port):
         """
-        (DEPRECATED: use --http)
+        (DEPRECATED: use --listen)
         Port to listen on for Secure HTTP.
         """
         msg = deprecate.getDeprecationWarningString(

{"golden_diff": "diff --git a/src/twisted/web/tap.py b/src/twisted/web/tap.py\n--- a/src/twisted/web/tap.py\n+++ b/src/twisted/web/tap.py\n@@ -30,10 +30,10 @@\n     optParameters = [[\"logfile\", \"l\", None,\n                       \"Path to web CLF (Combined Log Format) log file.\"],\n                      [\"certificate\", \"c\", \"server.pem\",\n-                      \"(DEPRECATED: use --http) \"\n+                      \"(DEPRECATED: use --listen) \"\n                       \"SSL certificate to use for HTTPS. \"],\n                      [\"privkey\", \"k\", \"server.pem\",\n-                      \"(DEPRECATED: use --http) \"\n+                      \"(DEPRECATED: use --listen) \"\n                       \"SSL certificate to use for HTTPS.\"],\n                      ]\n \n@@ -47,8 +47,8 @@\n         \"personal\", \"\",\n         \"Instead of generating a webserver, generate a \"\n         \"ResourcePublisher which listens on  the port given by \"\n-        \"--http, or ~/%s \" % (distrib.UserDirectory.userSocketName,) +\n-        \"if --http is not specified.\"])\n+        \"--listen, or ~/%s \" % (distrib.UserDirectory.userSocketName,) +\n+        \"if --listen is not specified.\"])\n \n     compData = usage.Completions(\n                    optActions={\"logfile\" : usage.CompleteFiles(\"*.log\"),\n@@ -71,7 +71,7 @@\n \n     def opt_port(self, port):\n         \"\"\"\n-        (DEPRECATED: use --http)\n+        (DEPRECATED: use --listen)\n         Strports description of port to start the server on\n         \"\"\"\n         msg = deprecate.getDeprecationWarningString(\n@@ -83,7 +83,7 @@\n \n     def opt_https(self, port):\n         \"\"\"\n-        (DEPRECATED: use --http)\n+        (DEPRECATED: use --listen)\n         Port to listen on for Secure HTTP.\n         \"\"\"\n         msg = deprecate.getDeprecationWarningString(\n", "issue": "Update docs for \"twisted web\" command line\n|[<img alt=\"moshez's avatar\" src=\"https://avatars.githubusercontent.com/u/422703?s=50\" width=\"50\" height=\"50\">](https://github.com/moshez)| @moshez reported|\n|-|-|\n|Trac ID|trac#9434|\n|Type|defect|\n|Created|2018-04-24 13:18:44Z|\n\nSee [#6670](https://github.com/twisted/twisted/issues/6670) [#9402](https://github.com/twisted/twisted/issues/9402) for details\n\n<details><summary>Searchable metadata</summary>\n\n```\ntrac-id__9434 9434\ntype__defect defect\nreporter__moshez moshez\npriority__normal normal\nmilestone__None None\nbranch__ \nbranch_author__ \nstatus__closed closed\nresolution__fixed fixed\ncomponent__core core\nkeywords__documentation__review documentation, review\ntime__1524575924346110 1524575924346110\nchangetime__1524999288440818 1524999288440818\nversion__None None\nowner__Amber_Brown__hawkowl_____ Amber Brown <hawkowl@...>\n\n```\n</details>\n\n", "before_files": [{"content": "# -*- test-case-name: twisted.web.test.test_tap -*-\n# Copyright (c) Twisted Matrix Laboratories.\n# See LICENSE for details.\n\n\"\"\"\nSupport for creating a service which runs a web server.\n\"\"\"\n\nfrom __future__ import absolute_import, division\n\nimport os\nimport warnings\n\nimport incremental\n\nfrom twisted.application import service, strports\nfrom twisted.internet import interfaces, reactor\nfrom twisted.python import usage, reflect, threadpool, deprecate\nfrom twisted.spread import pb\nfrom twisted.web import distrib\nfrom twisted.web import resource, server, static, script, demo, wsgi\nfrom twisted.web import twcgi\n\nclass Options(usage.Options):\n    \"\"\"\n    Define the options accepted by the I{twistd web} plugin.\n    \"\"\"\n    synopsis = \"[web options]\"\n\n    optParameters = [[\"logfile\", \"l\", None,\n                      \"Path to web CLF (Combined Log Format) log file.\"],\n                     [\"certificate\", \"c\", \"server.pem\",\n                      \"(DEPRECATED: use --http) \"\n                      \"SSL certificate to use for HTTPS. \"],\n                     [\"privkey\", \"k\", \"server.pem\",\n                      \"(DEPRECATED: use --http) \"\n                      \"SSL certificate to use for HTTPS.\"],\n                     ]\n\n    optFlags = [\n        [\"notracebacks\", \"n\", (\n            \"Do not display tracebacks in broken web pages. Displaying \"\n            \"tracebacks to users may be security risk!\")],\n    ]\n\n    optFlags.append([\n        \"personal\", \"\",\n        \"Instead of generating a webserver, generate a \"\n        \"ResourcePublisher which listens on  the port given by \"\n        \"--http, or ~/%s \" % (distrib.UserDirectory.userSocketName,) +\n        \"if --http is not specified.\"])\n\n    compData = usage.Completions(\n                   optActions={\"logfile\" : usage.CompleteFiles(\"*.log\"),\n                               \"certificate\" : usage.CompleteFiles(\"*.pem\"),\n                               \"privkey\" : usage.CompleteFiles(\"*.pem\")}\n                   )\n\n    longdesc = \"\"\"\\\nThis starts a webserver.  If you specify no arguments, it will be a\ndemo webserver that has the Test class from twisted.web.demo in it.\"\"\"\n\n    def __init__(self):\n        usage.Options.__init__(self)\n        self['indexes'] = []\n        self['root'] = None\n        self['extraHeaders'] = []\n        self['ports'] = []\n        self['port'] = self['https'] = None\n\n\n    def opt_port(self, port):\n        \"\"\"\n        (DEPRECATED: use --http)\n        Strports description of port to start the server on\n        \"\"\"\n        msg = deprecate.getDeprecationWarningString(\n            self.opt_port, incremental.Version(\"Twisted\", \"NEXT\", 0, 0))\n        warnings.warn(msg, category=DeprecationWarning, stacklevel=2)\n        self['port'] = port\n\n    opt_p = opt_port\n\n    def opt_https(self, port):\n        \"\"\"\n        (DEPRECATED: use --http)\n        Port to listen on for Secure HTTP.\n        \"\"\"\n        msg = deprecate.getDeprecationWarningString(\n            self.opt_https, incremental.Version(\"Twisted\", \"NEXT\", 0, 0))\n        warnings.warn(msg, category=DeprecationWarning, stacklevel=2)\n        self['https'] = port\n\n\n    def opt_listen(self, port):\n        \"\"\"\n        Add an strports description of port to start the server on.\n        [default: tcp:8080]\n        \"\"\"\n        self['ports'].append(port)\n\n\n    def opt_index(self, indexName):\n        \"\"\"\n        Add the name of a file used to check for directory indexes.\n        [default: index, index.html]\n        \"\"\"\n        self['indexes'].append(indexName)\n\n    opt_i = opt_index\n\n\n    def opt_user(self):\n        \"\"\"\n        Makes a server with ~/public_html and ~/.twistd-web-pb support for\n        users.\n        \"\"\"\n        self['root'] = distrib.UserDirectory()\n\n    opt_u = opt_user\n\n\n    def opt_path(self, path):\n        \"\"\"\n        <path> is either a specific file or a directory to be set as the root\n        of the web server. Use this if you have a directory full of HTML, cgi,\n        epy, or rpy files or any other files that you want to be served up raw.\n        \"\"\"\n        self['root'] = static.File(os.path.abspath(path))\n        self['root'].processors = {\n            '.epy': script.PythonScript,\n            '.rpy': script.ResourceScript,\n        }\n        self['root'].processors['.cgi'] = twcgi.CGIScript\n\n\n    def opt_processor(self, proc):\n        \"\"\"\n        `ext=class' where `class' is added as a Processor for files ending\n        with `ext'.\n        \"\"\"\n        if not isinstance(self['root'], static.File):\n            raise usage.UsageError(\n                \"You can only use --processor after --path.\")\n        ext, klass = proc.split('=', 1)\n        self['root'].processors[ext] = reflect.namedClass(klass)\n\n\n    def opt_class(self, className):\n        \"\"\"\n        Create a Resource subclass with a zero-argument constructor.\n        \"\"\"\n        classObj = reflect.namedClass(className)\n        self['root'] = classObj()\n\n\n    def opt_resource_script(self, name):\n        \"\"\"\n        An .rpy file to be used as the root resource of the webserver.\n        \"\"\"\n        self['root'] = script.ResourceScriptWrapper(name)\n\n\n    def opt_wsgi(self, name):\n        \"\"\"\n        The FQPN of a WSGI application object to serve as the root resource of\n        the webserver.\n        \"\"\"\n        try:\n            application = reflect.namedAny(name)\n        except (AttributeError, ValueError):\n            raise usage.UsageError(\"No such WSGI application: %r\" % (name,))\n        pool = threadpool.ThreadPool()\n        reactor.callWhenRunning(pool.start)\n        reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)\n        self['root'] = wsgi.WSGIResource(reactor, pool, application)\n\n\n    def opt_mime_type(self, defaultType):\n        \"\"\"\n        Specify the default mime-type for static files.\n        \"\"\"\n        if not isinstance(self['root'], static.File):\n            raise usage.UsageError(\n                \"You can only use --mime_type after --path.\")\n        self['root'].defaultType = defaultType\n    opt_m = opt_mime_type\n\n\n    def opt_allow_ignore_ext(self):\n        \"\"\"\n        Specify whether or not a request for 'foo' should return 'foo.ext'\n        \"\"\"\n        if not isinstance(self['root'], static.File):\n            raise usage.UsageError(\"You can only use --allow_ignore_ext \"\n                                   \"after --path.\")\n        self['root'].ignoreExt('*')\n\n\n    def opt_ignore_ext(self, ext):\n        \"\"\"\n        Specify an extension to ignore.  These will be processed in order.\n        \"\"\"\n        if not isinstance(self['root'], static.File):\n            raise usage.UsageError(\"You can only use --ignore_ext \"\n                                   \"after --path.\")\n        self['root'].ignoreExt(ext)\n\n\n    def opt_add_header(self, header):\n        \"\"\"\n        Specify an additional header to be included in all responses. Specified\n        as \"HeaderName: HeaderValue\".\n        \"\"\"\n        name, value = header.split(':', 1)\n        self['extraHeaders'].append((name.strip(), value.strip()))\n\n\n    def postOptions(self):\n        \"\"\"\n        Set up conditional defaults and check for dependencies.\n\n        If SSL is not available but an HTTPS server was configured, raise a\n        L{UsageError} indicating that this is not possible.\n\n        If no server port was supplied, select a default appropriate for the\n        other options supplied.\n        \"\"\"\n        if self['port'] is not None:\n            self['ports'].append(self['port'])\n        if self['https'] is not None:\n            try:\n                reflect.namedModule('OpenSSL.SSL')\n            except ImportError:\n                raise usage.UsageError(\"SSL support not installed\")\n            sslStrport = 'ssl:port={}:privateKey={}:certKey={}'.format(\n                             self['https'],\n                             self['privkey'],\n                             self['certificate'],\n                         )\n            self['ports'].append(sslStrport)\n        if len(self['ports']) == 0:\n            if self['personal']:\n                path = os.path.expanduser(\n                    os.path.join('~', distrib.UserDirectory.userSocketName))\n                self['ports'].append('unix:' + path)\n            else:\n                self['ports'].append('tcp:8080')\n\n\n\ndef makePersonalServerFactory(site):\n    \"\"\"\n    Create and return a factory which will respond to I{distrib} requests\n    against the given site.\n\n    @type site: L{twisted.web.server.Site}\n    @rtype: L{twisted.internet.protocol.Factory}\n    \"\"\"\n    return pb.PBServerFactory(distrib.ResourcePublisher(site))\n\n\n\nclass _AddHeadersResource(resource.Resource):\n    def __init__(self, originalResource, headers):\n        self._originalResource = originalResource\n        self._headers = headers\n\n\n    def getChildWithDefault(self, name, request):\n        for k, v in self._headers:\n            request.responseHeaders.addRawHeader(k, v)\n        return self._originalResource.getChildWithDefault(name, request)\n\n\n\ndef makeService(config):\n    s = service.MultiService()\n    if config['root']:\n        root = config['root']\n        if config['indexes']:\n            config['root'].indexNames = config['indexes']\n    else:\n        # This really ought to be web.Admin or something\n        root = demo.Test()\n\n    if isinstance(root, static.File):\n        root.registry.setComponent(interfaces.IServiceCollection, s)\n\n    if config['extraHeaders']:\n        root = _AddHeadersResource(root, config['extraHeaders'])\n\n    if config['logfile']:\n        site = server.Site(root, logPath=config['logfile'])\n    else:\n        site = server.Site(root)\n\n    site.displayTracebacks = not config[\"notracebacks\"]\n\n    if config['personal']:\n        site = makePersonalServerFactory(site)\n    for port in config['ports']:\n        svc = strports.service(port, site)\n        svc.setServiceParent(s)\n    return s\n", "path": "src/twisted/web/tap.py"}], "after_files": [{"content": "# -*- test-case-name: twisted.web.test.test_tap -*-\n# Copyright (c) Twisted Matrix Laboratories.\n# See LICENSE for details.\n\n\"\"\"\nSupport for creating a service which runs a web server.\n\"\"\"\n\nfrom __future__ import absolute_import, division\n\nimport os\nimport warnings\n\nimport incremental\n\nfrom twisted.application import service, strports\nfrom twisted.internet import interfaces, reactor\nfrom twisted.python import usage, reflect, threadpool, deprecate\nfrom twisted.spread import pb\nfrom twisted.web import distrib\nfrom twisted.web import resource, server, static, script, demo, wsgi\nfrom twisted.web import twcgi\n\nclass Options(usage.Options):\n    \"\"\"\n    Define the options accepted by the I{twistd web} plugin.\n    \"\"\"\n    synopsis = \"[web options]\"\n\n    optParameters = [[\"logfile\", \"l\", None,\n                      \"Path to web CLF (Combined Log Format) log file.\"],\n                     [\"certificate\", \"c\", \"server.pem\",\n                      \"(DEPRECATED: use --listen) \"\n                      \"SSL certificate to use for HTTPS. \"],\n                     [\"privkey\", \"k\", \"server.pem\",\n                      \"(DEPRECATED: use --listen) \"\n                      \"SSL certificate to use for HTTPS.\"],\n                     ]\n\n    optFlags = [\n        [\"notracebacks\", \"n\", (\n            \"Do not display tracebacks in broken web pages. Displaying \"\n            \"tracebacks to users may be security risk!\")],\n    ]\n\n    optFlags.append([\n        \"personal\", \"\",\n        \"Instead of generating a webserver, generate a \"\n        \"ResourcePublisher which listens on  the port given by \"\n        \"--listen, or ~/%s \" % (distrib.UserDirectory.userSocketName,) +\n        \"if --listen is not specified.\"])\n\n    compData = usage.Completions(\n                   optActions={\"logfile\" : usage.CompleteFiles(\"*.log\"),\n                               \"certificate\" : usage.CompleteFiles(\"*.pem\"),\n                               \"privkey\" : usage.CompleteFiles(\"*.pem\")}\n                   )\n\n    longdesc = \"\"\"\\\nThis starts a webserver.  If you specify no arguments, it will be a\ndemo webserver that has the Test class from twisted.web.demo in it.\"\"\"\n\n    def __init__(self):\n        usage.Options.__init__(self)\n        self['indexes'] = []\n        self['root'] = None\n        self['extraHeaders'] = []\n        self['ports'] = []\n        self['port'] = self['https'] = None\n\n\n    def opt_port(self, port):\n        \"\"\"\n        (DEPRECATED: use --listen)\n        Strports description of port to start the server on\n        \"\"\"\n        msg = deprecate.getDeprecationWarningString(\n            self.opt_port, incremental.Version(\"Twisted\", \"NEXT\", 0, 0))\n        warnings.warn(msg, category=DeprecationWarning, stacklevel=2)\n        self['port'] = port\n\n    opt_p = opt_port\n\n    def opt_https(self, port):\n        \"\"\"\n        (DEPRECATED: use --listen)\n        Port to listen on for Secure HTTP.\n        \"\"\"\n        msg = deprecate.getDeprecationWarningString(\n            self.opt_https, incremental.Version(\"Twisted\", \"NEXT\", 0, 0))\n        warnings.warn(msg, category=DeprecationWarning, stacklevel=2)\n        self['https'] = port\n\n\n    def opt_listen(self, port):\n        \"\"\"\n        Add an strports description of port to start the server on.\n        [default: tcp:8080]\n        \"\"\"\n        self['ports'].append(port)\n\n\n    def opt_index(self, indexName):\n        \"\"\"\n        Add the name of a file used to check for directory indexes.\n        [default: index, index.html]\n        \"\"\"\n        self['indexes'].append(indexName)\n\n    opt_i = opt_index\n\n\n    def opt_user(self):\n        \"\"\"\n        Makes a server with ~/public_html and ~/.twistd-web-pb support for\n        users.\n        \"\"\"\n        self['root'] = distrib.UserDirectory()\n\n    opt_u = opt_user\n\n\n    def opt_path(self, path):\n        \"\"\"\n        <path> is either a specific file or a directory to be set as the root\n        of the web server. Use this if you have a directory full of HTML, cgi,\n        epy, or rpy files or any other files that you want to be served up raw.\n        \"\"\"\n        self['root'] = static.File(os.path.abspath(path))\n        self['root'].processors = {\n            '.epy': script.PythonScript,\n            '.rpy': script.ResourceScript,\n        }\n        self['root'].processors['.cgi'] = twcgi.CGIScript\n\n\n    def opt_processor(self, proc):\n        \"\"\"\n        `ext=class' where `class' is added as a Processor for files ending\n        with `ext'.\n        \"\"\"\n        if not isinstance(self['root'], static.File):\n            raise usage.UsageError(\n                \"You can only use --processor after --path.\")\n        ext, klass = proc.split('=', 1)\n        self['root'].processors[ext] = reflect.namedClass(klass)\n\n\n    def opt_class(self, className):\n        \"\"\"\n        Create a Resource subclass with a zero-argument constructor.\n        \"\"\"\n        classObj = reflect.namedClass(className)\n        self['root'] = classObj()\n\n\n    def opt_resource_script(self, name):\n        \"\"\"\n        An .rpy file to be used as the root resource of the webserver.\n        \"\"\"\n        self['root'] = script.ResourceScriptWrapper(name)\n\n\n    def opt_wsgi(self, name):\n        \"\"\"\n        The FQPN of a WSGI application object to serve as the root resource of\n        the webserver.\n        \"\"\"\n        try:\n            application = reflect.namedAny(name)\n        except (AttributeError, ValueError):\n            raise usage.UsageError(\"No such WSGI application: %r\" % (name,))\n        pool = threadpool.ThreadPool()\n        reactor.callWhenRunning(pool.start)\n        reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)\n        self['root'] = wsgi.WSGIResource(reactor, pool, application)\n\n\n    def opt_mime_type(self, defaultType):\n        \"\"\"\n        Specify the default mime-type for static files.\n        \"\"\"\n        if not isinstance(self['root'], static.File):\n            raise usage.UsageError(\n                \"You can only use --mime_type after --path.\")\n        self['root'].defaultType = defaultType\n    opt_m = opt_mime_type\n\n\n    def opt_allow_ignore_ext(self):\n        \"\"\"\n        Specify whether or not a request for 'foo' should return 'foo.ext'\n        \"\"\"\n        if not isinstance(self['root'], static.File):\n            raise usage.UsageError(\"You can only use --allow_ignore_ext \"\n                                   \"after --path.\")\n        self['root'].ignoreExt('*')\n\n\n    def opt_ignore_ext(self, ext):\n        \"\"\"\n        Specify an extension to ignore.  These will be processed in order.\n        \"\"\"\n        if not isinstance(self['root'], static.File):\n            raise usage.UsageError(\"You can only use --ignore_ext \"\n                                   \"after --path.\")\n        self['root'].ignoreExt(ext)\n\n\n    def opt_add_header(self, header):\n        \"\"\"\n        Specify an additional header to be included in all responses. Specified\n        as \"HeaderName: HeaderValue\".\n        \"\"\"\n        name, value = header.split(':', 1)\n        self['extraHeaders'].append((name.strip(), value.strip()))\n\n\n    def postOptions(self):\n        \"\"\"\n        Set up conditional defaults and check for dependencies.\n\n        If SSL is not available but an HTTPS server was configured, raise a\n        L{UsageError} indicating that this is not possible.\n\n        If no server port was supplied, select a default appropriate for the\n        other options supplied.\n        \"\"\"\n        if self['port'] is not None:\n            self['ports'].append(self['port'])\n        if self['https'] is not None:\n            try:\n                reflect.namedModule('OpenSSL.SSL')\n            except ImportError:\n                raise usage.UsageError(\"SSL support not installed\")\n            sslStrport = 'ssl:port={}:privateKey={}:certKey={}'.format(\n                             self['https'],\n                             self['privkey'],\n                             self['certificate'],\n                         )\n            self['ports'].append(sslStrport)\n        if len(self['ports']) == 0:\n            if self['personal']:\n                path = os.path.expanduser(\n                    os.path.join('~', distrib.UserDirectory.userSocketName))\n                self['ports'].append('unix:' + path)\n            else:\n                self['ports'].append('tcp:8080')\n\n\n\ndef makePersonalServerFactory(site):\n    \"\"\"\n    Create and return a factory which will respond to I{distrib} requests\n    against the given site.\n\n    @type site: L{twisted.web.server.Site}\n    @rtype: L{twisted.internet.protocol.Factory}\n    \"\"\"\n    return pb.PBServerFactory(distrib.ResourcePublisher(site))\n\n\n\nclass _AddHeadersResource(resource.Resource):\n    def __init__(self, originalResource, headers):\n        self._originalResource = originalResource\n        self._headers = headers\n\n\n    def getChildWithDefault(self, name, request):\n        for k, v in self._headers:\n            request.responseHeaders.addRawHeader(k, v)\n        return self._originalResource.getChildWithDefault(name, request)\n\n\n\ndef makeService(config):\n    s = service.MultiService()\n    if config['root']:\n        root = config['root']\n        if config['indexes']:\n            config['root'].indexNames = config['indexes']\n    else:\n        # This really ought to be web.Admin or something\n        root = demo.Test()\n\n    if isinstance(root, static.File):\n        root.registry.setComponent(interfaces.IServiceCollection, s)\n\n    if config['extraHeaders']:\n        root = _AddHeadersResource(root, config['extraHeaders'])\n\n    if config['logfile']:\n        site = server.Site(root, logPath=config['logfile'])\n    else:\n        site = server.Site(root)\n\n    site.displayTracebacks = not config[\"notracebacks\"]\n\n    if config['personal']:\n        site = makePersonalServerFactory(site)\n    for port in config['ports']:\n        svc = strports.service(port, site)\n        svc.setServiceParent(s)\n    return s\n", "path": "src/twisted/web/tap.py"}]}