[Zope3-checkins]
SVN: Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/
Fixed all failing unit tests and deprecation warnings.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Thu Sep 8 10:32:59 EDT 2005
Log message for revision 38400:
Fixed all failing unit tests and deprecation warnings.
Changed:
U Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/README.txt
U Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/ftp/utils.py
U Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/log.txt
U Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/schema.xml
U Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/tests/test_docs.py
U Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/tests/test_publisher.py
-=-
Modified: Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/README.txt
===================================================================
--- Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/README.txt 2005-09-08 13:54:18 UTC (rev 38399)
+++ Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/README.txt 2005-09-08 14:32:58 UTC (rev 38400)
@@ -40,13 +40,13 @@
We are now ready to instantiate the server type:
- >>> from zope.app.server.server import ServerType
+ >>> from zope.app.twisted.server import ServerType
>>> st = ServerType(factory, defaultPort=8080)
and let's make sure it really implements the promised interface:
>>> from zope.interface.verify import verifyObject
- >>> from zope.app.server.interfaces import IServerType
+ >>> from zope.app.twisted.interfaces import IServerType
>>> verifyObject(IServerType, st)
True
@@ -57,13 +57,13 @@
When you create an instance of a server using the ``create()`` method of the
server type, you need to tell it an identifying name and a the ZODB database
object. The IP address, port and backlog count can be optionally passed to the
-method.
+method.
>>> db = 'my database'
>>> server = st.create('Example-HTTP', db, port=8080)
ZODB: my database
>>> server #doctest:+ELLIPSIS
- <zope.app.server.server.ZopeTCPServer instance at ...>
+ <zope.app.twisted.server.ZopeTCPServer instance at ...>
As you can see the server type creates a Zope-specific TCP server, which is
simply a standard ``twisted.internet.TCPServer`` that creates a log entry upon
@@ -94,14 +94,14 @@
additional information (private key path, certificate path, and TLS flag) to
start up the server. The setup will only work, if OpenSSL is installed:
- # >>> from zope.app.server.server import SSLServerType
+ # >>> from zope.app.twisted.server import SSLServerType
# >>> ssl_st = SSLServerType(factory, defaultPort=8443)
- #
+ #
# >>> ssl_server = ssl_st.create('Example-HTTPS', db,
# ... 'server.pem', 'server.pem')
# ZODB: my database
# >>> ssl_server #doctest:+ELLIPSIS
- # <zope.app.server.server.ZopeSSLServer instance at ...>
+ # <zope.app.twisted.server.ZopeSSLServer instance at ...>
Server Factories
@@ -115,7 +115,7 @@
servers.
>>> from zope.interface import implements
- >>> from zope.app.server.interfaces import IServerType
+ >>> from zope.app.twisted.interfaces import IServerType
>>> class MyServerType:
... implements(IServerType)
... def create(self, name, db,
@@ -139,7 +139,7 @@
... backlog = 30
>>> my_section = ServerSectionStub()
- >>> from zope.app.server.server import ServerFactory
+ >>> from zope.app.twisted.server import ServerFactory
>>> sf = ServerFactory(my_section)
The server factory object knows how to create a server, given a ZODB database
@@ -149,7 +149,7 @@
>>> print sf.create(db)
HTTP server on *:8080, registered with my db, backlog 30
-The settings should actually work with FTP as well.
+The settings should actually work with FTP as well.
>>> my_section.type = 'FTP'
>>> my_section.address = ('127.0.0.1', 8021)
Modified: Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/ftp/utils.py
===================================================================
--- Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/ftp/utils.py 2005-09-08 13:54:18 UTC (rev 38399)
+++ Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/ftp/utils.py 2005-09-08 14:32:58 UTC (rev 38400)
@@ -54,13 +54,12 @@
FTP request factories for a given database create FTP requets with
publications on the given database:
-
+
>>> from ZODB.tests.util import DB
>>> db = DB()
>>> factory = FTPRequestFactory(db)
>>> from cStringIO import StringIO
- >>> request = factory(StringIO(''), StringIO(),
- ... {'credentials': None, 'path': '/'})
+ >>> request = factory(StringIO(''), {'credentials': None, 'path': '/'})
>>> request.publication.db is db
True
>>> db.close()
@@ -71,8 +70,8 @@
def __init__(self, db):
self.publication = FTPPublication(db)
- def __call__(self, input_stream, output_steam, env):
- request = FTPRequest(input_stream, output_steam, env)
+ def __call__(self, input_stream, env):
+ request = FTPRequest(input_stream, env)
request.setPublication(self.publication)
return request
Modified: Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/log.txt
===================================================================
--- Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/log.txt 2005-09-08 13:54:18 UTC (rev 38399)
+++ Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/log.txt 2005-09-08 14:32:58 UTC (rev 38400)
@@ -23,7 +23,7 @@
Now we create the observer for the access log:
- >>> from zope.app.server import log
+ >>> from zope.app.twisted import log
>>> observer = log.CommonAccessLoggingObserver()
To start listening to Twisted logging calls, simply call ``start()``:
@@ -37,7 +37,7 @@
When the system emits an arbitrary log request, the observer does nothing
- >>> from twisted.web2 import http, http_headers, iweb
+ >>> from twisted.web2 import http, http_headers, iweb, channel
>>> twisted.python.log.msg('foo bar')
>>> logfile.getvalue()
''
@@ -47,20 +47,35 @@
key that contains the HTTP request implementing ``web2.iweb.IRequest``, and
the `response` of the request:
- >>> chanRequest = http.HTTPChannelRequest(None, 'GET /index.html HTTP/1.1', 1)
- >>> chanRequest.transport.client = ('127.0.0.1', 0)
+ >>> class TestHTTPChannel(channel.http.HTTPChannelRequest):
+ ... def getRemoteHost(self):
+ ... return type('TestRemoteHost', (), {'host': '127.0.0.1'})
+
+ >>> chanRequest = TestHTTPChannel(None, 'GET /index.html HTTP/1.1', 1)
>>> request = http.Request(chanRequest, 'GET', '/index.html', (1, 1),
... http_headers.Headers())
+
>>> response = http.Response()
+ >>> response.headers.setHeader('date', 1120000000)
- >>> eventDict = {'interface': iweb.IRequest,
- ... 'request': request, 'response': response}
+ >>> from zope.interface import implements
+ >>> from twisted.web2 import log
+ >>> class FauxContext(object):
+ ... implements(log.ILogInfo)
+ ... responseCompleted=True
+ ... secondsTaken=1
+ ... bytesSent=300
+ ... startTime=1120000000
+ >>> eventDict = {'interface': iweb.IRequest,
+ ... 'request': request, 'response': response,
+ ... 'context': FauxContext()}
+
If we now emit a log event, we should receive an entry:
>>> twisted.python.log.msg(**eventDict)
>>> print logfile.getvalue() #doctest: +ELLIPSIS
- 127.0.0.1 - anonymous [...] "GET /index.html HTTP/1.1" 200 0 "-" "-"
+ 127.0.0.1 - - [28/Jun/2005:...] "GET /index.html HTTP/1.1" 200 300 "-" "-"
<BLANKLINE>
If I now set the `referer` and `user-agent` headers, we get some more output:
@@ -73,7 +88,7 @@
>>> twisted.python.log.msg(**eventDict)
>>> print logfile.getvalue() #doctest: +ELLIPSIS
- 127.0.0.1 - anonymous [...] "GET /index.html HTTP/1.1" 200 0
+ 127.0.0.1 - - [28/Jun/2005:...] "GET /index.html HTTP/1.1" 200 300
"http://localhost:8080/manage" "Mozilla 1.7"
<BLANKLINE>
@@ -84,3 +99,7 @@
>>> observer.stop()
>>> observer.emit in twisted.python.log.theLogPublisher.observers
False
+
+And cleanup the logger:
+
+ >>> logger.removeHandler(handler)
\ No newline at end of file
Modified: Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/schema.xml
===================================================================
--- Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/schema.xml 2005-09-08 13:54:18 UTC (rev 38399)
+++ Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/schema.xml 2005-09-08 14:32:58 UTC (rev 38400)
@@ -11,17 +11,17 @@
<!-- logging configuration -->
<import package="ZConfig.components.logger" />
- <import package="zope.app.server" file="accesslog.xml" />
+ <import package="zope.app.twisted" file="accesslog.xml" />
- <sectiontype name="server" datatype="zope.app.server.server.ServerFactory">
+ <sectiontype name="server" datatype="zope.app.twisted.server.ServerFactory">
<key name="type" required="yes" />
<key name="address" datatype="inet-address" />
<key name="backlog" datatype="integer" default="50" />
</sectiontype>
- <sectiontype name="sslserver"
+ <sectiontype name="sslserver"
extends="server"
- datatype="zope.app.server.server.SSLServerFactory">
+ datatype="zope.app.twisted.server.SSLServerFactory">
<key name="privatekeypath" datatype="existing-file" required="yes" />
<key name="certificatepath" datatype="existing-file" required="yes" />
<key name="tls" datatype="boolean" default="false" />
@@ -29,7 +29,7 @@
<sectiontype name="sshserver"
extends="server"
- datatype="zope.app.server.server.SSHServerFactory">
+ datatype="zope.app.twisted.server.SSHServerFactory">
<key name="hostkey" datatype="existing-file" required="yes" />
</sectiontype>
Modified: Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/tests/test_docs.py
===================================================================
--- Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/tests/test_docs.py 2005-09-08 13:54:18 UTC (rev 38399)
+++ Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/tests/test_docs.py 2005-09-08 14:32:58 UTC (rev 38400)
@@ -25,7 +25,7 @@
def setUp(test):
setup.placelessSetUp()
-
+
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
Modified: Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/tests/test_publisher.py
===================================================================
--- Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/tests/test_publisher.py 2005-09-08 13:54:18 UTC (rev 38399)
+++ Zope3/branches/srichter-twisted-integration2/src/zope/app/twisted/tests/test_publisher.py 2005-09-08 14:32:58 UTC (rev 38400)
@@ -26,7 +26,7 @@
def rename(self, path, old, new):
return demofs.DemoFileSystem.rename(
- self, "%s/%s" % (path, old), "%s/%s" % (path, new))
+ self, "%s/%s" % (path, old), "%s/%s" % (path, new))
class Publication(object):
@@ -35,7 +35,7 @@
def beforeTraversal(self, request):
pass
-
+
def getApplication(self, request):
return self.root
@@ -56,8 +56,8 @@
def handleException(self, object, request, info, retry_allowed=True):
request.response._exc = info[:2]
-
+
class Request(object):
def __init__(self, input, output, env):
@@ -80,7 +80,7 @@
_exc = _body = None
- def setBody(self, result):
+ def setResult(self, result):
self._body = result
def outputBody(self):
More information about the Zope3-Checkins
mailing list