from urllib import quote_plus, unquote_plus
from binascii import b2a_hex
+import operator
from twisted.python import log
from twisted.internet import defer
Uploads use L{FileUploaderStream} or L{twisted.web2.stream.MemorySTream},
apt uses L{CacheManager.ProxyFileStream} or L{twisted.web.stream.FileStream}.
"""
+
+ stats = None
def __init__(self, factory, wrappedProtocol):
ThrottlingProtocol.__init__(self, factory, wrappedProtocol)
def write(self, data):
if self.throttle:
ThrottlingProtocol.write(self, data)
+ if self.stats:
+ self.stats.sentBytes(len(data))
else:
ProtocolWrapper.write(self, data)
+ def writeSequence(self, seq):
+ if self.throttle:
+ ThrottlingProtocol.writeSequence(self, seq)
+ if self.stats:
+ self.stats.sentBytes(reduce(operator.add, map(len, seq)))
+ else:
+ ProtocolWrapper.writeSequence(self, seq)
+
def registerProducer(self, producer, streaming):
ThrottlingProtocol.registerProducer(self, producer, streaming)
streamType = getattr(producer, 'stream', None)
'betweenRequestsTimeOut': 60})
self.factory = ThrottlingFactory(self.factory, writeLimit = self.uploadLimit)
self.factory.protocol = UploadThrottlingProtocol
+ if self.manager:
+ self.factory.protocol.stats = self.manager.stats
return self.factory
def render(self, ctx):
return [{'pieces': 'abcdefghij0123456789\xca\xec\xb8\x0c\x00\xe7\x07\xf8~])\x8f\x9d\xe5_B\xff\x1a\xc4!'}]
return [{'path': FilePath(os.path.expanduser('~/school/optout'))}]
- t = TopLevel(FilePath(os.path.expanduser('~')), DB(), None, 0)
+ t = TopLevel(FilePath(os.path.expanduser('~')), DB(), None)
factory = t.getHTTPFactory()
# Standard twisted application Boilerplate