A stream resource
Naming and storage systems use the IStreamFactory interface to access
streams such as files, TCP/IP protocol connections, pipes, etc.
There are three basic ways to open a stream: to read an "existing"
stream (via open() ), to create a new stream, overwriting any existing
data (via create() ), and to update/append a (possibly existing)
stream (via update() ).
Each method provides some options. The mode argument, required by
all methods, must be "b" , "t" , or "U" , indicating the text/binary
mode for Python to use in interpreting stream contents. The seek
argument, if set to true, requests that the opened stream be seekable.
The readable and writable arguments request that the stream be
capable of that operation in addition to the normal behavior for that
opening method.
The autocommit option indicates whether autocommit behavior (i.e. a
separate transaction just for that operation) is desired. Note that if
the autocommit option is set, changes to an existing resource may be
visible to other threads or processes before the opened stream is
closed.
For all options, if the requested option is unsupported, an exception
will be raised. Ommitting autocommit when a particular stream
factory requires autocommitting, will also result in an exception.
Methods
|
|
create
delete
exists
open
update
|
|
create
|
create (
mode,
seek=False,
readable=False,
autocommit=False,
)
Create/replace a stream resource for writing (like "w" mode)
Always creates the resource, whether it exists or not, erasing any
previously existing contents if applicable.
|
|
delete
|
delete ( autocommit=False )
Delete the resource
|
|
exists
|
exists ()
Return true if the resource exists (i.e. if open() would succeed)
For remote resources, this should verify the resource's existence
without actually downloading it. However, this should include
authentication if the protocol requires it.
This method is specifically intended to be able to be used to verify
that a remote service is up and running.
|
|
open
|
open (
mode,
seek=False,
writable=False,
autocommit=False,
)
Open an existing stream resource for reading (like "r" mode)
The resource must exist and be readable. It is not created if
it does not exist.
|
|
update
|
update (
mode,
seek=False,
readable=False,
append=False,
autocommit=False,
)
Update or append to a stream resource (like "w+" or "a" mode)
Opens the resource for modification; if it doesn't exist, it's
created empty. The append flag controls whether the stream
is opened for writing at the end of the existing resource. Note
that in append mode, some operating systems will send all writes
to the end of a file, regardless of seek position (according to
the Python manual).
|
|