Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: third_party/twisted_8_1/twisted/conch/mixin.py

Issue 12261012: Remove third_party/twisted_8_1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # -*- test-case-name: twisted.conch.test.test_mixin -*-
2 # Copyright (c) 2001-2004 Twisted Matrix Laboratories.
3 # See LICENSE for details.
4
5 """
6 Experimental optimization
7
8 This module provides a single mixin class which allows protocols to
9 collapse numerous small writes into a single larger one.
10
11 @author: U{Jp Calderone<mailto:exarkun@twistedmatrix.com>}
12 """
13
14 from twisted.internet import reactor
15
16 class BufferingMixin:
17 """Mixin which adds write buffering.
18 """
19 _delayedWriteCall = None
20 bytes = None
21
22 DELAY = 0.0
23
24 def schedule(self):
25 return reactor.callLater(self.DELAY, self.flush)
26
27 def reschedule(self, token):
28 token.reset(self.DELAY)
29
30 def write(self, bytes):
31 """Buffer some bytes to be written soon.
32
33 Every call to this function delays the real write by C{self.DELAY}
34 seconds. When the delay expires, all collected bytes are written
35 to the underlying transport using L{ITransport.writeSequence}.
36 """
37 if self._delayedWriteCall is None:
38 self.bytes = []
39 self._delayedWriteCall = self.schedule()
40 else:
41 self.reschedule(self._delayedWriteCall)
42 self.bytes.append(bytes)
43
44 def flush(self):
45 """Flush the buffer immediately.
46 """
47 self._delayedWriteCall = None
48 self.transport.writeSequence(self.bytes)
49 self.bytes = None
OLDNEW
« no previous file with comments | « third_party/twisted_8_1/twisted/conch/manhole_tap.py ('k') | third_party/twisted_8_1/twisted/conch/openssh_compat/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698