282 def write(self, data): |
282 def write(self, data): |
283 remaining = object.__getattribute__(self, '_cond').remaining_send_bytes |
283 remaining = object.__getattribute__(self, '_cond').remaining_send_bytes |
284 |
284 |
285 # No byte limit on this operation. Call original function. |
285 # No byte limit on this operation. Call original function. |
286 if not remaining: |
286 if not remaining: |
|
287 result = object.__getattribute__(self, '_orig').write(data) |
287 self._writelog(b'write(%d) -> %s' % (len(data), data)) |
288 self._writelog(b'write(%d) -> %s' % (len(data), data)) |
288 result = object.__getattribute__(self, '_orig').write(data) |
|
289 return result |
289 return result |
290 |
290 |
291 if len(data) > remaining: |
291 if len(data) > remaining: |
292 newdata = data[0:remaining] |
292 newdata = data[0:remaining] |
293 else: |
293 else: |
294 newdata = data |
294 newdata = data |
295 |
295 |
296 remaining -= len(newdata) |
296 remaining -= len(newdata) |
|
297 |
|
298 result = object.__getattribute__(self, '_orig').write(newdata) |
297 |
299 |
298 self._writelog( |
300 self._writelog( |
299 b'write(%d from %d) -> (%d) %s' |
301 b'write(%d from %d) -> (%d) %s' |
300 % (len(newdata), len(data), remaining, newdata) |
302 % (len(newdata), len(data), remaining, newdata) |
301 ) |
303 ) |
302 |
|
303 result = object.__getattribute__(self, '_orig').write(newdata) |
|
304 |
304 |
305 object.__getattribute__(self, '_cond').remaining_send_bytes = remaining |
305 object.__getattribute__(self, '_cond').remaining_send_bytes = remaining |
306 |
306 |
307 if remaining <= 0: |
307 if remaining <= 0: |
308 self._writelog(b'write limit reached; closing socket') |
308 self._writelog(b'write limit reached; closing socket') |