55
from bzrlib.smart import medium
56
from bzrlib.tests import test_smart_transport
59
from bzrlib.symbol_versioning import (
57
64
# sha and md5 modules are deprecated in python2.6 but hashlib is available as
59
66
if sys.version_info < (2, 5):
1874
1881
return socket.gethostname().decode(get_user_encoding())
1884
@deprecated_function(deprecated_in((2, 2, 0)))
1885
def until_no_eintr(f, *a, **kw):
1886
"""Stub version of previous attempt at signal handling code"""
1890
@deprecated_function(deprecated_in((2, 2, 0)))
1877
1891
def recv_all(socket, bytes):
1878
"""Receive an exact number of bytes.
1880
Regular Socket.recv() may return less than the requested number of bytes,
1881
dependning on what's in the OS buffer. MSG_WAITALL is not available
1882
on all platforms, but this should work everywhere. This will return
1883
less than the requested amount if the remote end closes.
1885
This isn't optimized and is intended mostly for use in testing.
1888
while len(b) < bytes:
1889
new = socket.recv(bytes - len(b))
1892
"""See bzrlib.tests.test_smart_transport._recv_all"""
1893
return test_smart_transport._recv_all(socket, bytes)
1896
@deprecated_function(deprecated_in((2, 2, 0)))
1896
1897
def send_all(socket, bytes, report_activity=None):
1897
"""Send all bytes on a socket.
1899
Regular socket.sendall() can give socket error 10053 on Windows. This
1900
implementation sends no more than 64k at a time, which avoids this problem.
1902
:param report_activity: Call this as bytes are read, see
1903
Transport._report_activity
1906
for pos in xrange(0, len(bytes), chunk_size):
1907
block = bytes[pos:pos+chunk_size]
1908
if report_activity is not None:
1909
report_activity(len(block), 'write')
1910
socket.sendall(block)
1898
"""See bzrlib.smart.medium._send_bytes_chunked"""
1899
if report_activity is None:
1900
report_activity = lambda n, rw: None
1901
medium._send_bytes_chunked(socket, bytes, report_activity)
1913
1904
def dereference_path(path):