~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Andrew Bennetts
  • Date: 2010-03-19 00:31:54 UTC
  • mto: This revision was merged to the branch mainline in revision 5117.
  • Revision ID: andrew.bennetts@canonical.com-20100319003154-4a3a5vazekn5lvtx
Make report_activity param of read_bytes_from_socket optional.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1899
1899
# data at once.
1900
1900
MAX_SOCKET_CHUNK = 64 * 1024
1901
1901
 
1902
 
def read_bytes_from_socket(sock, report_activity,
 
1902
def read_bytes_from_socket(sock, report_activity=None,
1903
1903
        max_read_size=MAX_SOCKET_CHUNK):
1904
1904
    """Read up to max_read_size of bytes from sock and notify of progress.
1905
1905
 
1921
1921
                continue
1922
1922
            raise
1923
1923
        else:
1924
 
            report_activity(len(bytes), 'read')
 
1924
            if report_activity is not None:
 
1925
                report_activity(len(bytes), 'read')
1925
1926
            return bytes
1926
1927
 
1927
1928
 
1936
1937
    This isn't optimized and is intended mostly for use in testing.
1937
1938
    """
1938
1939
    b = ''
1939
 
    reporter = lambda n, rw: None
1940
1940
    while len(b) < count:
1941
 
        new = read_bytes_from_socket(socket, reporter, count - len(b))
 
1941
        new = read_bytes_from_socket(socket, None, count - len(b))
1942
1942
        if new == '':
1943
1943
            break # eof
1944
1944
        b += new