public class PyIOBase extends PyObject implements FinalizableBuiltin, Traverseproc
_io._IOBase
, on which the io
module depends directly.
Implementation note: The code is based heavily on the Jython 2.6-ish
_fileio.PyFileIO
, the purely Java-accessible IOBase
(both
Philip Jenvey's work), and the Python implementation in Lib/_pyio
. We do not simply
delegate to the implementation in org.python.core.io
because of the need to override
parts of the implementation in Python subclasses. A call to close()
, for example, is
required to call flush()
, but if delegated to the pure Java implementation would not
call the version of flush()
overridden in a Python sub-class of
_io._IOBase
. Equally, the use made by PyRawIOBase.read(int)
of
readinto(bytearray)
would not pick up the version of readinto
defined
in Python.
PyObject.ConversionException
Modifier and Type | Field and Description |
---|---|
static String |
close_doc |
static String |
closed_doc |
static String |
fileno_doc |
static String |
flush_doc |
static String |
isatty_doc |
static String |
readable_doc |
static String |
readline_doc |
static String |
readlines_doc |
static String |
seek_doc |
static String |
seekable_doc |
static String |
tell_doc |
static String |
truncate_doc |
static PyType |
TYPE |
static String |
writable_doc |
static String |
writelines_doc |
gcMonitorGlobal
Modifier and Type | Method and Description |
---|---|
void |
__del_builtin__()
__del_builtin__ is the built-in's own finalizer, while
__del_derived__ refers to an instance's in-dict __del__ . |
PyObject |
__enter__()
Called at the start of a context-managed suite (supporting the
with clause). |
boolean |
__exit__(PyObject type,
PyObject value,
PyObject traceback)
Called at the end of a context-managed suite (supporting the
with clause), and
will normally close the stream. |
PyObject |
__iter__()
Return an iterator on which
next may be repeatedly called to produce (usually)
lines from this stream or file. |
PyObject |
__iternext__()
Return the next element of the sequence that this is an iterator
for.
|
void |
_checkClosed() |
void |
_checkClosed(String msg)
Raise an error if the underlying IO stream is closed.
|
void |
_checkReadable()
Raise an error if the underlying IO stream is not readable.
|
void |
_checkReadable(String msg)
Raise an error if the underlying IO stream is not readable.
|
void |
_checkSeekable()
Raise an error if the pointer of underlying IO stream is not capable of being
positioned.
|
void |
_checkSeekable(String msg)
Raise an error if the pointer of underlying IO stream is not capable of being
positioned.
|
void |
_checkWritable()
Raise an error if the underlying IO stream is not writable.
|
void |
_checkWritable(String msg)
Raise an error if the underlying IO stream is not writable.
|
void |
close()
Close the stream.
|
void |
closed_readonly(boolean value) |
boolean |
closed()
Is the stream closed against further client operations?
|
PyStringMap |
fastGetDict()
xxx implements where meaningful
|
PyObject |
fileno()
Return a file descriptor for the stream.
|
void |
flush()
Flush write buffers, or no-op for read-only and non-blocking streams.
|
boolean |
isatty()
Is the stream known to be an interactive console?
|
PyObject |
next()
May be called repeatedly to produce (usually) lines from this stream or file.
|
boolean |
readable()
Is the stream readable?
|
PyObject |
readline()
Return one line of text (bytes terminates by
'\n' ), or the whole stream,
whichever is shorter. |
PyObject |
readline(int limit)
Return one line of text (bytes terminates by
'\n' ), or the specified number of
bytes, or the whole stream, whichever is shortest. |
PyObject |
readlines(PyObject hint)
Read a stream as a sequence of lines.
|
boolean |
refersDirectlyTo(PyObject ob)
Optional operation.
|
long |
seek(long pos)
Position the read or write pointer at a given byte offset
pos relative to the
start. |
long |
seek(long pos,
int whence)
Position the read or write pointer at a given byte offset
pos relative to a
position indicated by whence . |
boolean |
seekable()
Is the stream capable of positioning the read/write pointer?
|
long |
tell()
Get the current stream position.
|
int |
traverse(Visitproc visit,
Object arg)
Traverses all reachable
PyObject s. |
long |
truncate()
Truncate file to
size bytes to the current position (as reported by
tell() ). |
long |
truncate(long size)
Truncate file to
size bytes. |
boolean |
writable()
Is the stream writable?
|
void |
writelines(PyObject lines)
Write an iterable sequence of strings to the stream.
|
__abs__, __add__, __and__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __cmp__, __coerce__, __coerce_ex__, __complex__, __contains__, __delattr__, __delattr__, __delete__, __delitem__, __delitem__, __delslice__, __delslice__, __dir__, __div__, __divmod__, __ensure_finalizer__, __eq__, __findattr__, __findattr__, __findattr_ex__, __finditem__, __finditem__, __finditem__, __float__, __floordiv__, __format__, __ge__, __get__, __getattr__, __getattr__, __getitem__, __getitem__, __getnewargs__, __getslice__, __getslice__, __gt__, __hash__, __hex__, __iadd__, __iand__, __idiv__, __idivmod__, __ifloordiv__, __ilshift__, __imod__, __imul__, __index__, __int__, __invert__, __ior__, __ipow__, __irshift__, __isub__, __itruediv__, __ixor__, __le__, __len__, __long__, __lshift__, __lt__, __mod__, __mul__, __ne__, __neg__, __nonzero__, __not__, __oct__, __or__, __pos__, __pow__, __pow__, __radd__, __rand__, __rdiv__, __rdivmod__, __reduce__, __reduce_ex__, __reduce_ex__, __repr__, __rfloordiv__, __rlshift__, __rmod__, __rmul__, __ror__, __rpow__, __rrshift__, __rshift__, __rsub__, __rtruediv__, __rxor__, __set__, __setattr__, __setattr__, __setitem__, __setitem__, __setitem__, __setslice__, __setslice__, __str__, __sub__, __tojava__, __truediv__, __trunc__, __unicode__, __xor__, _add, _and, _callextra, _cmp, _div, _divmod, _doget, _doget, _doset, _eq, _floordiv, _ge, _gt, _iadd, _iand, _idiv, _idivmod, _ifloordiv, _ilshift, _imod, _imul, _in, _ior, _ipow, _irshift, _is, _isnot, _isub, _itruediv, _ixor, _jcall, _jcallexc, _jthrow, _le, _lshift, _lt, _mod, _mul, _ne, _notin, _or, _pow, _rshift, _sub, _truediv, _xor, asDouble, asIndex, asIndex, asInt, asInt, asIterable, asLong, asLong, asName, asName, asString, asString, asStringOrNull, asStringOrNull, bit_length, conjugate, delDict, delType, dispatch__init__, equals, fastGetClass, getDict, getType, hashCode, implementsDescrDelete, implementsDescrGet, implementsDescrSet, invoke, invoke, invoke, invoke, invoke, invoke, isCallable, isDataDescr, isIndex, isInteger, isMappingType, isNumberType, isSequenceType, noAttributeError, object___subclasshook__, readonlyAttributeError, setDict, setType, toString
public static final PyType TYPE
public static final String seek_doc
public static final String tell_doc
public static final String truncate_doc
public static final String flush_doc
public static final String close_doc
public static final String closed_doc
public static final String seekable_doc
public static final String readable_doc
public static final String writable_doc
public static final String fileno_doc
public static final String isatty_doc
public static final String readline_doc
public static final String readlines_doc
public static final String writelines_doc
public PyStringMap fastGetDict()
PyObject
fastGetDict
in class PyObject
public long seek(long pos, int whence)
pos
relative to a
position indicated by whence
.
whence
=0, the position will be set to pos
bytes.whence
=1 the position will be set to the current position plus
pos
.whence
=2 the position will be set to the stream size plus
pos
(and usually pos
<=0).pos
- relative to the specified pointwhence
- 0=from start, 1=from here, 2=from endpublic final long seek(long pos)
pos
relative to the
start.pos
- relative to the startpublic long tell()
public long truncate(long size)
size
bytes.size
- requested for streampublic long truncate()
size
bytes to the current position (as reported by
tell()
).public void flush()
public final void closed_readonly(boolean value)
public void close()
public boolean seekable() throws PyException
True
if may be positionedPyException(ValueError)
- if the object is closed to client operationsPyException
public void _checkSeekable(String msg)
msg
- optional custom messagePyException(ValueError)
- if the object is closed to client operationsPyException(IOError)
- if the stream is not capable of being positioned.public final void _checkSeekable()
PyException(ValueError)
- if the object is closed to client operationsPyException(IOError)
- if the stream is not capable of being positioned.public boolean readable() throws PyException
true
if readablePyException(ValueError)
- if the object is closed to client operationsPyException
public void _checkReadable(String msg)
msg
- optional custom messagePyException(ValueError)
- if the object is closed to client operationsPyException(IOError)
- if the stream is not readable.public final void _checkReadable()
PyException(ValueError)
- if the object is closed to client operationsPyException(IOError)
- if the stream is not readable.public boolean writable() throws PyException
true
if writablePyException(ValueError)
- if the object is closed to client operationsPyException
public void _checkWritable(String msg) throws PyException
msg
- optional custom messagePyException(ValueError)
- if the object is closed to client operationsPyException(IOError)
- if the stream is not writable.PyException
public final void _checkWritable() throws PyException
PyException(ValueError)
- if the object is closed to client operationsPyException(IOError)
- if the stream is not writable.PyException
public final boolean closed()
true
if closedpublic void _checkClosed(String msg) throws PyException
_checkSeekable(java.lang.String)
, etc..msg
- optional custom messagePyException(ValueError)
- if the object is closed to client operationsPyException
public final void _checkClosed() throws PyException
PyException
public PyObject __enter__()
with
clause).public boolean __exit__(PyObject type, PyObject value, PyObject traceback)
with
clause), and
will normally close the stream.public PyObject fileno()
_io.open(PyObject[], String[])
accepts the type that RawIOBase.fileno()
returns.public boolean isatty()
true
if a console: false
if not or we can't tellpublic PyObject readline(int limit)
'\n'
), or the specified number of
bytes, or the whole stream, whichever is shortest.limit
- maximum number of bytes (<0 means no limit)public PyObject readline()
'\n'
), or the whole stream,
whichever is shorter.public PyObject __iter__()
next
may be repeatedly called to produce (usually)
lines from this stream or file.public PyObject __iternext__()
PyObject
__iternext__
in class PyObject
public PyObject next() throws PyException
PyException(StopIteration)
- when iteration has reached a natural conclusionPyException(ValueError)
- if the file or stream is closedPyException(IOError)
- reflecting an I/O error in during the readPyException
public PyObject readlines(PyObject hint)
hint
- stop reading lines after this many bytes (if not EOF first)public void writelines(PyObject lines)
lines
- public void __del_builtin__()
FinalizableBuiltin
__del_builtin__
is the built-in's own finalizer, while
__del_derived__
refers to an instance's in-dict __del__
.
A FinalizeTrigger calls __del_derived__
first and
- if existent - __del_builtin__
after that. A plain __del__
would behave as overwritten by __del__Derived
, i.e. won't be called
if the type implements FinalizablePyObjectDerived
while
__del_builtin__
is called in any case.__del_builtin__
in interface FinalizableBuiltin
public int traverse(Visitproc visit, Object arg)
Traverseproc
PyObject
s.
Like in CPython, arg
must be passed
unmodified to visit
as its second parameter.
If visit.visit
returns nonzero, this return value
must be returned immediately by traverse.traverse
in interface Traverseproc
public boolean refersDirectlyTo(PyObject ob)
Traverseproc
traverse
with a visitproc
that just watches out for ob
.
Must return false
if ob
is null
.refersDirectlyTo
in interface Traverseproc