bufsock module

socket or file wrapper provides buffered read and readto, among other methods.

Intended to deal intelligently with short reads. Also provides a rawio wrapper for os.open.

class bufsock.bufsock(filedes, disable_flush=False, chunk_len=4096, maintain_alignment=False)[source]

Bases: object

socket or file wrapper provides buffered read and readto, among other methods.

Intended to deal intelligently with short reads.

close()[source]

Close the file.

fileno()[source]

Return the fileno corresponding to self.filedes.

flush()[source]

Flush our buffer.

read(length=None)[source]

Read some bytes.

readline()[source]

Read up to a newline.

readto(terminator)[source]

Read some bytes, up to a specified terminator.

readtomax(terminator, length)[source]

Read up to a specified terminator, or a maximum length, whichever comes first.

recv(length=None)

Read some bytes.

send(buf)[source]

Send (write) some bytes.

set_chunk_len(length)[source]

Set the chunk length (blocksize) for our buffering.

shutdown(value)[source]

Shutdown our socket - or close the file.

write(buf)

Send (write) some bytes.

bufsock.o_binary()[source]

On platforms that have an os.O_BINARY, use it.

This includes CPython on Windows, and probably should include Jython on unix/linux but doesn’t (at least, not in Jython 2.5.2).

class bufsock.rawio(filename=None, mode='r', perms=438, handle=None)[source]

Bases: object

This class is a simple wrapper for os.open, os.read, os.write and os.close.

It should in turn allow us to wrap these os.* routines with bufsock. Alternatively, we should also be able to wrap a python file object with bufsock, but then you end up with two layers of buffering, each with slightly different functionality.

close()[source]

Close our file-like object.

fileno()[source]

Return the numberic file descriptor corresponding to this rawio object.

open(filename=None, mode='r', perms=438, handle=None)

Initialize.

read(length=None)[source]

Read some bytes.

write(data)[source]

Write some bytes.

bufsock.simple_test()[source]

Perform a very simple test.

bufsock.string_to_binary(string)[source]

Convert a text string (or binary string type) to a binary string type.