/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin
  • Date: 2010-02-17 01:42:45 UTC
  • mto: This revision was merged to the branch mainline in revision 5117.
  • Revision ID: gzlist@googlemail.com-20100217014245-oii9iih0mvry7abk
Reintroduce EINTR handling only for socket object functions and general cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
    errors,
53
53
    win32utils,
54
54
    )
 
55
from bzrlib.smart import medium
 
56
from bzrlib.tests import test_smart_transport
55
57
""")
56
58
 
 
59
from bzrlib.symbol_versioning import (
 
60
    deprecated_function,
 
61
    deprecated_in,
 
62
    )
 
63
 
57
64
# sha and md5 modules are deprecated in python2.6 but hashlib is available as
58
65
# of 2.5
59
66
if sys.version_info < (2, 5):
1874
1881
        return socket.gethostname().decode(get_user_encoding())
1875
1882
 
1876
1883
 
 
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"""
 
1887
    return f(*a, **kw)
 
1888
 
 
1889
 
 
1890
@deprecated_function(deprecated_in((2, 2, 0)))
1877
1891
def recv_all(socket, bytes):
1878
 
    """Receive an exact number of bytes.
1879
 
 
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.
1884
 
 
1885
 
    This isn't optimized and is intended mostly for use in testing.
1886
 
    """
1887
 
    b = ''
1888
 
    while len(b) < bytes:
1889
 
        new = socket.recv(bytes - len(b))
1890
 
        if new == '':
1891
 
            break # eof
1892
 
        b += new
1893
 
    return b
1894
 
 
1895
 
 
 
1892
    """See bzrlib.tests.test_smart_transport._recv_all"""
 
1893
    return test_smart_transport._recv_all(socket, bytes)
 
1894
 
 
1895
 
 
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.
1898
 
 
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.
1901
 
 
1902
 
    :param report_activity: Call this as bytes are read, see
1903
 
        Transport._report_activity
1904
 
    """
1905
 
    chunk_size = 2**16
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)
1911
1902
 
1912
1903
 
1913
1904
def dereference_path(path):