~certify-web-dev/twisted/certify-staging

« back to all changes in this revision

Viewing changes to twisted/protocols/policies.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-01-02 19:38:17 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100102193817-jphp464ppwh7dulg
Tags: 9.0.0-1
* python-twisted: Depend on the python-twisted-* 9.0 packages.
* python-twisted: Depend on python-zope.interface only. Closes: #557781.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- test-case-name: twisted.test.test_policies -*-
2
 
# Copyright (c) 2001-2007 Twisted Matrix Laboratories.
 
2
# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
3
3
# See LICENSE for details.
4
4
 
5
 
 
6
5
"""
7
6
Resource limiting policies.
8
7
 
12
11
# system imports
13
12
import sys, operator
14
13
 
 
14
from zope.interface import directlyProvides, providedBy
 
15
 
15
16
# twisted imports
16
17
from twisted.internet.protocol import ServerFactory, Protocol, ClientFactory
17
 
from twisted.internet import reactor, error
 
18
from twisted.internet import error
18
19
from twisted.python import log
19
 
from zope.interface import providedBy, directlyProvides
20
20
 
21
21
 
22
22
class ProtocolWrapper(Protocol):
23
 
    """Wraps protocol instances and acts as their transport as well."""
 
23
    """
 
24
    Wraps protocol instances and acts as their transport as well.
 
25
 
 
26
    @ivar wrappedProtocol: An L{IProtocol} provider to which L{IProtocol}
 
27
        method calls onto this L{ProtocolWrapper} will be proxied.
 
28
 
 
29
    @ivar factory: The L{WrappingFactory} which created this
 
30
        L{ProtocolWrapper}.
 
31
    """
24
32
 
25
33
    disconnecting = 0
26
34
 
29
37
        self.factory = factory
30
38
 
31
39
    def makeConnection(self, transport):
32
 
        directlyProvides(self, *providedBy(self) + providedBy(transport))
 
40
        """
 
41
        When a connection is made, register this wrapper with its factory,
 
42
        save the real transport, and connect the wrapped protocol to this
 
43
        L{ProtocolWrapper} to intercept any transport calls it makes.
 
44
        """
 
45
        directlyProvides(self, providedBy(transport))
33
46
        Protocol.makeConnection(self, transport)
 
47
        self.factory.registerProtocol(self)
 
48
        self.wrappedProtocol.makeConnection(self)
34
49
 
35
50
    # Transport relaying
36
51
 
64
79
 
65
80
    # Protocol relaying
66
81
 
67
 
    def connectionMade(self):
68
 
        self.factory.registerProtocol(self)
69
 
        self.wrappedProtocol.makeConnection(self)
70
 
 
71
82
    def dataReceived(self, data):
72
83
        self.wrappedProtocol.dataReceived(data)
73
84
 
184
195
        """
185
196
        Wrapper around L{reactor.callLater} for test purpose.
186
197
        """
 
198
        from twisted.internet import reactor
187
199
        return reactor.callLater(period, func)
188
200
 
189
201
 
481
493
        """
482
494
        Wrapper around L{reactor.callLater} for test purpose.
483
495
        """
 
496
        from twisted.internet import reactor
484
497
        return reactor.callLater(period, func)
485
498
 
486
499
 
591
604
    __timeoutCall = None
592
605
 
593
606
    def callLater(self, period, func):
 
607
        from twisted.internet import reactor
594
608
        return reactor.callLater(period, func)
595
609
 
596
610