+class UploadThrottlingProtocol(ThrottlingProtocol):
+ """Protocol for throttling uploads.
+
+ Determines whether or not to throttle the upload based on the type of stream.
+ Uploads use L{FileUploaderStream} or L{twisted.web2.stream.MemorySTream},
+ apt uses L{CacheManager.ProxyFileStream} or L{twisted.web.stream.FileStream}.
+ """
+
+ def __init__(self, factory, wrappedProtocol):
+ ThrottlingProtocol.__init__(self, factory, wrappedProtocol)
+ self.throttle = False
+
+ def write(self, data):
+ if self.throttle:
+ ThrottlingProtocol.write(self, data)
+ else:
+ ProtocolWrapper.write(self, data)
+
+ def registerProducer(self, producer, streaming):
+ ThrottlingProtocol.registerProducer(self, producer, streaming)
+ streamType = getattr(producer, 'stream', None)
+ if isinstance(streamType, FileUploaderStream) or isinstance(streamType, stream.MemoryStream):
+ self.throttle = True
+
+