public abstract class BaseBytes extends PySequence implements java.util.List<PyInteger>
bytearray
(and bytes
in due course) that provides most of
the Java API, including Java List
behaviour. Attempts to modify the contents through this
API will throw a TypeError
if the actual type of the object is not mutable. It is
possible for a Java client to treat this class as a List<PyInteger>
, obtaining equivalent
functionality to the Python interface in a Java paradigm.
Subclasses must define (from PySequence
):
PySequence.pyset(int, PyObject)
PySequence.setslice(int, int, int, PyObject)
PySequence.del(int)
PySequence.delRange(int, int)
Many of the methods implemented here are inherited or thinly wrapped by PyByteArray
,
which offers them as Java API, or exposes them as Python methods. These prototype Python methods
mostly accept a PyObject
as argument, where you might have expected a byte[]
or
BaseBytes
, in order to accommodate the full range of types accepted by the Python
equivalent: usually, any PyObject
that implements BufferProtocol
, providing a
one-dimensional array of bytes, is an acceptable argument. In the documentation, the reader will
often see the terms "byte array" or "object viewable as bytes" instead of BaseBytes
when
this broader scope is intended.
Where the methods return a BaseBytes
, this is will normally be an instance of the class
of the object on which the method was actually called. For example capitalize()
, defined
in BaseBytes
to return a BaseBytes, actually returns a PyByteArray
when applied
to a bytearray
. Or it may be that the method returns a PyList
of instances of the
target type, for example rpartition(PyObject)
. This is achieved by the sub-class
defining getslice(int, int, int)
and getResult(Builder)
to return instances of
its own type. See the documentation of the particular methods for more information.
Modifier and Type | Class and Description |
---|---|
protected static class |
BaseBytes.Builder
A
Builder holds a buffer of bytes to which new bytes may be appended while
constructing the value of byte array, even when the type ultimately constructed is immutable. |
protected static class |
BaseBytes.ByteSet
Class for quickly determining whether a given byte is a member of a defined set.
|
protected static class |
BaseBytes.Finder
This class implements the Boyer-Moore-Horspool Algorithm for finding a pattern in text,
applied to byte arrays.
|
protected static class |
BaseBytes.Fragment
Intended as a fragment of temporary storage for use we do not know how many bytes of
allocate, and we are reading in some kind of iterable stream.
|
protected static class |
BaseBytes.FragmentList
A container of temporary storage when we do not know how many bytes to allocate, and we are
reading in some kind of iterable stream.
|
protected static class |
BaseBytes.ReverseFinder
This class is the complement of
BaseBytes.Finder and implements the Boyer-Moore-Horspool
Algorithm adapted for right-to-left search for a pattern in byte arrays. |
PySequence.DefaultIndexDelegate
PyObject.ConversionException
Modifier and Type | Field and Description |
---|---|
protected static byte[] |
emptyStorage
Empty storage constant
|
protected java.util.List<PyInteger> |
listDelegate
Access to the byte array as a
List . |
protected int |
offset
Index of first byte used in storage array.
|
protected int |
size
Number of bytes actually used in storage array.
|
protected byte[] |
storage
Storage array.
|
delegator
attributes, gcMonitorGlobal, objtype, TYPE
Modifier | Constructor and Description |
---|---|
|
BaseBytes(PyType type)
Constructs a zero-length
BaseBytes of explicitly-specified sub-type. |
|
BaseBytes(PyType type,
int size)
Constructs a zero-filled array of defined size and type.
|
|
BaseBytes(PyType type,
int[] value)
Constructs a byte array of defined type by copying values from int[].
|
protected |
BaseBytes(PyType type,
java.lang.String value)
Constructs a byte array of defined type by copying character values from a String.
|
Modifier and Type | Method and Description |
---|---|
int |
__len__()
Equivalent to the standard Python __len__ method.
|
PyObject |
__reduce__()
Support for pickling byte arrays: reduce a byte array to the actual type, arguments for
(re-)construction of the object, and the dictionary of any user-defined sub-class.
|
void |
add(int index,
PyInteger element) |
boolean |
add(PyInteger o) |
boolean |
addAll(java.util.Collection<? extends PyInteger> c) |
boolean |
addAll(int index,
java.util.Collection<? extends PyInteger> c) |
java.lang.String |
asString()
Present the bytes of a byte array, with no decoding, as a Java String.
|
protected boolean |
basebytes___contains__(PyObject target)
Search for the target in this byte array, returning true if found and false if not.
|
protected PyObject |
basebytes_decode(PyObject[] args,
java.lang.String[] keywords)
Ready-to-expose implementation of decode( [ encoding [, errors ]] )
|
protected PyList |
basebytes_splitlines(boolean keepends)
Ready-to-expose implementation of Python
splitlines(keepends) , returning a list of
the lines in the array, breaking at line boundaries. |
protected boolean |
basebytes_starts_or_endswith(PyObject target,
PyObject ostart,
PyObject oend,
boolean endswith)
Almost ready-to-expose implementation serving both Python
startswith( prefix [, start [, end ]] ) and
endswith( suffix [, start [, end ]] ) . |
protected static byte |
byteCheck(int value)
Check that an integer is suitable for storage in a (Python) byte array, and convert it to the
Java byte value that can be stored there.
|
protected static byte |
byteCheck(PyInteger value)
Check that the value of an PyInteger is suitable for storage in a (Python) byte array, and
convert it to the Java byte value that can be stored there.
|
protected static byte |
byteCheck(PyObject value)
Check that the type and value of a PyObject is suitable for storage in a (Python) byte array,
and convert it to the Java byte value that can be stored there.
|
BaseBytes |
capitalize()
Java API equivalent of Python
capitalize() . |
protected static int |
checkForEmptySeparator(PyBuffer separator)
Convenience routine producing a ValueError for "empty separator" if the PyBuffer is of an
object with zero length, and returning the length otherwise.
|
void |
clear() |
boolean |
contains(java.lang.Object o)
Returns true if this list contains the specified value.
|
boolean |
containsAll(java.util.Collection<?> c) |
PyObject |
decode()
Decode the byte array to a Unicode string according to the default encoding.
|
PyObject |
decode(java.lang.String encoding)
Decode the byte array to a Unicode string according to the specified encoding and default
error policy.
|
PyObject |
decode(java.lang.String encoding,
java.lang.String errors)
Decode the byte array to a Unicode string according to the specified encoding and error
policy.
|
protected static java.lang.String |
encode(PyString arg,
java.lang.String encoding,
java.lang.String errors)
Helper for
PySequence.setslice(int, int, int, PyObject) , for __new__ and
__init__ and the Java API constructor from a text string with the specified encoding
in subclasses. |
boolean |
equals(java.lang.Object other)
Test for the equality of (the value of) this byte array to the object
other . |
protected static byte |
fillByteCheck(java.lang.String function,
java.lang.String fillchar)
Helper to check the fill byte for
basebytes_rjust(int, String) ,
basebytes_ljust(int, String) and basebytes_center(int, String) , which is
required to be a single character string, treated as a byte. |
PyInteger |
get(int index) |
protected abstract BaseBytes |
getResult(BaseBytes.Builder b)
Every sub-class of BaseBytes overrides this method to access a
Builder and return
that class' particular type, possibly without copying. |
protected BaseBytes |
getslice(int start,
int stop)
Specialisation of
getslice(int, int, int) to contiguous slices (of step size 1) for
brevity and efficiency. |
protected abstract BaseBytes |
getslice(int start,
int stop,
int step)
Returns a range of elements from the sequence.
|
protected static PyBuffer |
getView(PyObject b)
Return a buffer exported by the argument, or return
null if it does not bear the
buffer API. |
protected static PyBuffer |
getViewOrError(PyObject b)
Return a buffer exported by the argument or raise an exception if it does not bear the buffer
API.
|
int |
hashCode() |
protected int |
index(byte b)
The very simplest kind of find operation: return the index in the byte array of the first
occurrence of the byte value
|
protected void |
indexCheck(int index)
Check that an index is within the range of the array, that is 0<=index<size.
|
int |
indexOf(java.lang.Object o) |
protected void |
init(BaseBytes source)
Helper for
__new__ and __init__ and the Java API constructor from
bytearray or bytes in subclasses. |
protected void |
init(BufferProtocol value)
Helper for
__new__ and __init__ and the Java API constructor from objects
supporting the Jython implementation of PEP 3118 (Buffer API) in subclasses. |
protected void |
init(int n)
Helper for
__new__ and __init__ and the Java API constructor from int in
subclasses. |
protected void |
init(java.lang.Iterable<? extends PyObject> iter)
Helper for
__new__ and __init__ and the Java API constructor from an
arbitrary iterable Python type in subclasses. |
protected void |
init(PyObject arg)
Helper for
__new__ and __init__ and the Java API constructor from PyObject in
subclasses. |
protected void |
init(PyString arg,
PyObject encoding,
PyObject errors)
Helper for
__new__ and __init__ and the Java API constructor from a text
string with the specified encoding in subclasses. |
protected void |
init(PyString arg,
java.lang.String encoding,
java.lang.String errors)
Helper for
__new__ and __init__ and the Java API constructor from a text
string with the specified encoding in subclasses. |
int |
intAt(int index)
Return the Python byte (in range 0 to 255 inclusive) at the given index.
|
boolean |
isalnum()
Java API equivalent of Python
isalnum() . |
boolean |
isalpha()
Java API equivalent of Python
isalpha() . |
boolean |
isdigit()
Java API equivalent of Python
isdigit() . |
boolean |
isEmpty() |
boolean |
islower()
Java API equivalent of Python
islower() . |
boolean |
isspace()
Java API equivalent of Python
isspace() . |
boolean |
istitle()
Java API equivalent of Python
istitle() . |
boolean |
isupper()
Java API equivalent of Python
isupper() . |
java.util.Iterator<PyInteger> |
iterator() |
int |
lastIndexOf(java.lang.Object o) |
java.util.ListIterator<PyInteger> |
listIterator() |
java.util.ListIterator<PyInteger> |
listIterator(int index) |
BaseBytes |
lower()
Java API equivalent of Python
lower() . |
protected int |
lstripIndex()
Return the index [0..size-1] of the leftmost non-whitespace byte, or
size if they are
all whitespace. |
protected int |
lstripIndex(BaseBytes.ByteSet byteSet)
Return the index [0..size-1] of the leftmost byte not matching any in
byteSet , or
size if they are all strippable. |
protected void |
newStorage(int needed)
Allocate fresh, zero-filled storage for the requested number of bytes and make that the size.
|
PyTuple |
partition(PyObject sep)
Implementation of Python
partition(sep) , returning a 3-tuple of byte arrays (of the
same type as this ). |
protected PyInteger |
pyget(int index)
Returns the element of the sequence at the given index.
|
void |
pyinsert(int index,
PyObject element)
Insert the element (interpreted as a Python byte value) at the given index.
|
PyInteger |
remove(int index) |
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> c) |
protected abstract BaseBytes |
repeat(int count)
Returns a (concrete subclass of) PySequence that repeats the given sequence, as in the
implementation of
__mul__ for strings. |
boolean |
retainAll(java.util.Collection<?> c) |
protected static int |
roundUp(int size)
Choose a size appropriate to store the given number of bytes, with some room for growth, when
allocating storage for mutable types or
Builder . |
PyTuple |
rpartition(PyObject sep)
Implementation of Python
rpartition(sep) , returning a 3-tuple of byte arrays (of the
same type as this ). |
PyList |
rsplit()
Implementation of Python
rsplit() , that returns a list of the words in the byte
array, using whitespace as the delimiter. |
PyList |
rsplit(PyObject sep)
Implementation of Python
rsplit(sep) , that returns a list of the words in the byte
array, using sep as the delimiter. |
PyList |
rsplit(PyObject sep,
int maxsplit)
Implementation of Python
rsplit(sep, maxsplit) , that returns a list of the words in
the byte array, using sep as the delimiter. |
protected int |
rstripIndex()
Return the index [0..size-1] such that all bytes from here to the right are whitespace, that
is, the index of the whitespace tail, or
size if there is no whitespace tail. |
protected int |
rstripIndex(BaseBytes.ByteSet byteSet)
Return the index [0..size-1] such that all bytes from here to the right match one in
byteSet , that is, the index of the matching tail, or size if there is no
matching tail byte. |
PyInteger |
set(int index,
PyInteger element) |
protected void |
setBytes(int start,
int step,
java.lang.String value)
Fill a strided slice of a byte array by copying character values from a String.
|
protected void |
setBytes(int start,
java.lang.String value)
Fill a defined section of a byte array by copying character values from a String.
|
protected void |
setStorage(byte[] storage)
Helper for constructors and methods that manipulate the storage in mutable subclasses in the
case where the storage should consist of exactly the whole of the given array.
|
protected void |
setStorage(byte[] storage,
int size)
Helper for constructors and methods that manipulate the storage in mutable subclasses in the
case where the storage should consist of the first part of the given array.
|
protected void |
setStorage(byte[] storage,
int size,
int offset)
Helper for constructors and methods that manipulate the storage in mutable subclasses.
|
int |
size()
Number of bytes in
bytearray (or bytes ) object. |
PyList |
split()
Implementation of Python
split() , that returns a list of the words in the byte array,
using whitespace as the delimiter. |
PyList |
split(PyObject sep)
Implementation of Python
split(sep) , that returns a list of the words in the byte
array, using sep as the delimiter. |
PyList |
split(PyObject sep,
int maxsplit)
Implementation of Python
split(sep, maxsplit) , that returns a list of the words in
the byte array, using sep as the delimiter. |
PyList |
splitlines()
Implementation of Python
splitlines() , returning a list of the lines in the byte
array, breaking at line boundaries. |
PyList |
splitlines(boolean keepends)
Implementation of Python
splitlines(keepends) , returning a list of the lines in the
string, breaking at line boundaries. |
java.util.List<PyInteger> |
subList(int fromIndex,
int toIndex) |
BaseBytes |
swapcase()
Java API equivalent of Python
swapcase() . |
BaseBytes |
title()
Java API equivalent of Python
title() . |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
BaseBytes |
upper()
Java API equivalent of Python
upper() . |
__delitem__, __delslice__, __eq__, __finditem__, __finditem__, __ge__, __getitem__, __getslice__, __gt__, __iter__, __le__, __lt__, __ne__, __nonzero__, __setitem__, __setitem__, __setslice__, __tojava__, boundToSequence, cmp, del, delRange, delslice, fastSequence, isMappingType, isNumberType, isSequenceType, isSubType, pyset, runsupportedopMessage, setslice, sliceLength, unsupportedopMessage
__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__, __delslice__, __dir__, __div__, __divmod__, __ensure_finalizer__, __findattr__, __findattr__, __findattr_ex__, __finditem__, __float__, __floordiv__, __format__, __get__, __getattr__, __getattr__, __getitem__, __getnewargs__, __getslice__, __hash__, __hex__, __iadd__, __iand__, __idiv__, __idivmod__, __ifloordiv__, __ilshift__, __imod__, __imul__, __index__, __int__, __invert__, __ior__, __ipow__, __irshift__, __isub__, __iternext__, __itruediv__, __ixor__, __long__, __lshift__, __mod__, __mul__, __neg__, __not__, __oct__, __or__, __pos__, __pow__, __pow__, __radd__, __rand__, __rawdir__, __rdiv__, __rdivmod__, __reduce_ex__, __reduce_ex__, __repr__, __rfloordiv__, __rlshift__, __rmod__, __rmul__, __ror__, __rpow__, __rrshift__, __rshift__, __rsub__, __rtruediv__, __rxor__, __set__, __setattr__, __setattr__, __setitem__, __setslice__, __str__, __sub__, __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, _unsupportedop, _xor, adaptToCoerceTuple, asDouble, asIndex, asIndex, asInt, asInt, asIterable, asLong, asLong, asName, asName, asString, asStringOrNull, asStringOrNull, bit_length, conjugate, delDict, delType, dispatch__init__, fastGetClass, fastGetDict, finalize, getDict, getJavaProxy, getType, impAttr, implementsDescrDelete, implementsDescrGet, implementsDescrSet, invoke, invoke, invoke, invoke, invoke, invoke, isCallable, isDataDescr, isIndex, isInteger, mergeClassDict, mergeDictAttr, mergeListAttr, noAttributeError, object___subclasshook__, readonlyAttributeError, setDict, setType, toString
protected static final byte[] emptyStorage
protected byte[] storage
protected int size
protected int offset
protected final java.util.List<PyInteger> listDelegate
List
. The List interface supplied by
BaseBytes delegates to this object.public BaseBytes(PyType type)
BaseBytes
of explicitly-specified sub-type.type
- explicit Jython typepublic BaseBytes(PyType type, int size)
size
- requiredtype
- explicit Jython typepublic BaseBytes(PyType type, int[] value)
type
- explicit Jython typevalue
- source of values (and size)protected BaseBytes(PyType type, java.lang.String value) throws PyException
type
- explicit Jython typevalue
- source of charactersPyException
- ValueError
if any value[i] > 255
protected void setStorage(byte[] storage, int size, int offset) throws java.lang.IllegalArgumentException
storage
- byte array allocated by clientsize
- number of bytes actually usedoffset
- index of first byte usedjava.lang.IllegalArgumentException
- if the range [offset:offset+size]
is not within the
array bounds of storage or size<0
.protected void setStorage(byte[] storage, int size) throws java.lang.IllegalArgumentException
storage
- byte array allocated by clientsize
- number of bytes actually usedjava.lang.IllegalArgumentException
- if the range [0:size]
is not within the array bounds
of storage.protected void setStorage(byte[] storage)
storage
- byte array allocated by clientprotected void init(PyObject arg)
__new__
and __init__
and the Java API constructor from PyObject in
subclasses.arg
- primary argument from which value is takenPyByteArray.bytearray___init__(PyObject[], String[])
,
PyByteArray.PyByteArray(PyObject)
protected void init(PyString arg, PyObject encoding, PyObject errors)
__new__
and __init__
and the Java API constructor from a text
string with the specified encoding in subclasses.arg
- primary argument from which value is takenencoding
- name of optional encoding (must be a string type)errors
- name of optional errors policy (must be a string type)PyByteArray.bytearray___init__(PyObject[], String[])
,
PyByteArray.PyByteArray(PyString, String, String)
protected void init(PyString arg, java.lang.String encoding, java.lang.String errors)
__new__
and __init__
and the Java API constructor from a text
string with the specified encoding in subclasses.arg
- primary argument from which value is takenencoding
- name of optional encodingerrors
- name of optional errors policyPyByteArray.bytearray___init__(PyObject[], String[])
,
PyByteArray.PyByteArray(PyString, String, String)
protected static java.lang.String encode(PyString arg, java.lang.String encoding, java.lang.String errors) throws PyException
PySequence.setslice(int, int, int, PyObject)
, for __new__
and
__init__
and the Java API constructor from a text string with the specified encoding
in subclasses. This method thinly wraps a call to the codecs module and deals with checking
for PyUnicode (where the encoding argument is mandatory).arg
- primary argument from which value is takenencoding
- name of optional encodingerrors
- name of optional errors policyPyException
- TypeError
if the PyString
is actually a PyUnicode
and encoding is null
PyByteArray.PyByteArray(PyString, String, String)
protected void setBytes(int start, java.lang.String value) throws PyException
start
- index in this byte array at which the first character code landsvalue
- source of charactersPyException
- ValueError
if any value[i] > 255
protected void setBytes(int start, int step, java.lang.String value) throws PyException
start
- index in this byte array at which the first character code landsvalue
- source of charactersPyException
- ValueError
if any value[i] > 255
protected void init(int n)
__new__
and __init__
and the Java API constructor from int in
subclasses. Construct zero-filled byte array of specified size.n
- size of zero-filled arrayprotected void init(BufferProtocol value) throws PyException, java.lang.ClassCastException
__new__
and __init__
and the Java API constructor from objects
supporting the Jython implementation of PEP 3118 (Buffer API) in subclasses.value
- an object bearing the Buffer API and consistent with the slice assignmentPyException
java.lang.ClassCastException
protected void init(BaseBytes source)
__new__
and __init__
and the Java API constructor from
bytearray
or bytes
in subclasses.source
- bytearray
(or bytes
) to copyprotected void init(java.lang.Iterable<? extends PyObject> iter)
__new__
and __init__
and the Java API constructor from an
arbitrary iterable Python type in subclasses. This will include generators and lists.iter
- iterable source of values to enter in the arrayprotected final void indexCheck(int index) throws PyException
index
- to checkPyException
- IndexError
if the index is outside the array boundsprotected void newStorage(int needed)
needed
- becomes the new value of this.sizeprotected static final byte byteCheck(int value) throws PyException
value
- to convert.PyException
- ValueError
if value<0 or value>255protected static final byte byteCheck(PyInteger value) throws PyException
value
- to convert.PyException
- ValueError
if value<0 or value>255protected static final byte byteCheck(PyObject value) throws PyException
value
- to convert.PyException
- TypeError
if not acceptable typePyException
- ValueError
if value<0 or value>255 or string length!=1protected static PyBuffer getView(PyObject b)
null
if it does not bear the
buffer API. The caller is responsible for calling PyBuffer.release()
on the buffer,
if the return value is not null
.b
- object to wrapnull
protected static PyBuffer getViewOrError(PyObject b)
PyBuffer.release()
on the buffer. The
return value is never null
.b
- object to wrapprotected PyInteger pyget(int index)
PySequence
PySequence.__getitem__(org.python.core.PyObject)
It is guaranteed by PySequence that
when it calls pyget(int)
the index is within the bounds of the array. Any other
clients must make the same guarantee.pyget
in class PySequence
index
- index of element to return.protected abstract BaseBytes getslice(int start, int stop, int step)
PySequence
getslice
in class PySequence
start
- the position of the first element.stop
- one more than the position of the last element.step
- the step size.protected abstract BaseBytes repeat(int count)
PySequence
__mul__
for strings.repeat
in class PySequence
count
- the number of times to repeat the sequence.public void pyinsert(int index, PyObject element)
index
- to insert atelement
- to insert (by value)PyException
- IndexError
if the index is outside the array boundsPyException
- ValueError
if element<0 or element>255PyException
- TypeError
if the subclass is immutableprotected BaseBytes getslice(int start, int stop)
getslice(int, int, int)
to contiguous slices (of step size 1) for
brevity and efficiency. The default implementation is getslice(start, stop, 1)
but it
is worth overriding.start
- the position of the first element.stop
- one more than the position of the last element.public int __len__()
PyObject
protected final boolean basebytes___contains__(PyObject target)
target
- byte value to search forprotected final boolean basebytes_starts_or_endswith(PyObject target, PyObject ostart, PyObject oend, boolean endswith)
startswith( prefix [, start [, end ]] )
and
endswith( suffix [, start [, end ]] )
. An extra boolean argument specifies which to
implement on a given call, that is, whether the target is a suffix or prefix. The target may
also be a tuple of targets.target
- prefix or suffix sequence to find (of a type viewable as a byte sequence) or a
tuple of those.ostart
- of slice to search.oend
- of slice to search.endswith
- true if we are doing endswith, false if startswith.target
.public java.lang.String asString()
public PyObject decode()
PyUnicode
, since the default codec is well-behaved.public PyObject decode(java.lang.String encoding)
PyUnicode
, but in practice it
is whatever the decode
method of the codec decides.encoding
- the name of the codec (uses default codec if null
)public PyObject decode(java.lang.String encoding, java.lang.String errors)
PyUnicode
, but in practice it is
whatever the decode
method of the codec decides.encoding
- the name of the codec (uses default codec if null
)errors
- the name of the error policy (uses 'strict' if null
)protected final PyObject basebytes_decode(PyObject[] args, java.lang.String[] keywords)
args
- Python argument listkeywords
- Assocaited keywordspublic PyObject __reduce__()
__reduce__
in class PyObject
protected int index(byte b)
b
- byte to search forprotected static final int checkForEmptySeparator(PyBuffer separator) throws PyException
separator
- view to testPyException
- if the PyBuffer is zero lengthprotected int lstripIndex(BaseBytes.ByteSet byteSet)
byteSet
, or
size
if they are all strippable.byteSet
- set of byte values to skip overprotected int lstripIndex()
size
if they are
all whitespace.protected int rstripIndex(BaseBytes.ByteSet byteSet)
byteSet
, that is, the index of the matching tail, or size
if there is no
matching tail byte.byteSet
- set of byte values to stripprotected int rstripIndex()
size
if there is no whitespace tail.public PyTuple partition(PyObject sep)
partition(sep)
, returning a 3-tuple of byte arrays (of the
same type as this
).
Split the string at the first occurrence of sep
, and return a 3-tuple containing the
part before the separator, the separator itself, and the part after the separator. If the
separator is not found, return a 3-tuple containing the string itself, followed by two empty
byte arrays.
The elements of the PyTuple
returned by this method are instances of the same actual
type as this
.
sep
- the separator on which to partition this byte arraypublic PyTuple rpartition(PyObject sep)
rpartition(sep)
, returning a 3-tuple of byte arrays (of the
same type as this
).
Split the string at the rightmost occurrence of sep
, and return a 3-tuple containing
the part before the separator, the separator itself, and the part after the separator. If the
separator is not found, return a 3-tuple containing two empty byte arrays, followed by the
byte array itself.
The elements of the PyTuple
returned by this method are instances of the same actual
type as this
.
sep
- the separator on which to partition this byte arraypublic PyList rsplit()
rsplit()
, that returns a list of the words in the byte
array, using whitespace as the delimiter. See rsplit(PyObject, int)
.
The elements of the PyList
returned by this method are instances of the same actual
type as this
.
public PyList rsplit(PyObject sep)
rsplit(sep)
, that returns a list of the words in the byte
array, using sep
as the delimiter. See rsplit(PyObject, int)
for the
semantics of the separator.
The elements of the PyList
returned by this method are instances of the same actual
type as this
.
sep
- bytes
, or object viewable as bytes, defining the separatorpublic PyList rsplit(PyObject sep, int maxsplit)
rsplit(sep, maxsplit)
, that returns a list of the words in
the byte array, using sep
as the delimiter. If maxsplit
is given, at most
maxsplit
splits are done (thus, the list will have at most maxsplit+1
elements). If maxsplit
is not specified, then there is no limit on the number of
splits (all possible splits are made).
The semantics of sep
and maxcount are identical to those of
split(sep, maxsplit)
, except that splits are generated from the right (and pushed
onto the front of the result list). The result is only different from that of split
if maxcount
limits the number of splits. For example,
bytearray(b' 1 2 3 ').rsplit()
returns
[bytearray(b'1'), bytearray(b'2'), bytearray(b'3')]
, andbytearray(b' 1 2 3 ').rsplit(None, 1)
returns
[bytearray(b' 1 2'), bytearray(b'3')]
.
The elements of the PyList
returned by this method are instances of the same actual
type as this
.
sep
- bytes
, or object viewable as bytes, defining the separatormaxsplit
- maximum number of splitspublic PyList split()
split()
, that returns a list of the words in the byte array,
using whitespace as the delimiter. See split(PyObject, int)
.
The elements of the PyList
returned by this method are instances of the same actual
type as this
.
public PyList split(PyObject sep)
split(sep)
, that returns a list of the words in the byte
array, using sep
as the delimiter. See split(PyObject, int)
for the
semantics of the separator.
The elements of the PyList
returned by this method are instances of the same actual
type as this
.
sep
- bytes
, or object viewable as bytes, defining the separatorpublic PyList split(PyObject sep, int maxsplit)
split(sep, maxsplit)
, that returns a list of the words in
the byte array, using sep
as the delimiter. If maxsplit
is given, at most
maxsplit
splits are done. (Thus, the list will have at most maxsplit+1
elements). If maxsplit
is not specified, then there is no limit on the number of
splits (all possible splits are made).
If sep
is given, consecutive delimiters are not grouped together and are deemed to
delimit empty strings (for example, '1,,2'.split(',')
returns
['1', '', '2']
). The sep
argument may consist of multiple characters (for
example, '1<>2<>3'.split('<>')
returns ['1', '2', '3']
). Splitting an empty
string with a specified separator ['']
.
If sep
is not specified or is None
, a different splitting algorithm is
applied: runs of consecutive whitespace are regarded as a single separator, and the result
will contain no empty strings at the start or end if the string has leading or trailing
whitespace. Consequently, splitting an empty string or a string consisting of just whitespace
with a None
separator returns []
. For example,
bytearray(b' 1 2 3 ').split()
returns
[bytearray(b'1'), bytearray(b'2'), bytearray(b'3')]
, andbytearray(b' 1 2 3 ').split(None, 1)
returns
[bytearray(b'1'), bytearray(b'2 3 ')]
.
The elements of the PyList
returned by this method are instances of the same actual
type as this
.
sep
- bytes
, or object viewable as bytes, defining the separatormaxsplit
- maximum number of splitspublic PyList splitlines()
splitlines()
, returning a list of the lines in the byte
array, breaking at line boundaries. Line breaks are not included in the resulting segments.
The elements of the PyList
returned by this method are instances of the same actual
type as this
.
public PyList splitlines(boolean keepends)
splitlines(keepends)
, returning a list of the lines in the
string, breaking at line boundaries. Line breaks are not included in the resulting list
unless keepends
is true.
The elements of the PyList
returned by this method are instances of the same actual
type as this
.
keepends
- if true, include the end of line bytes(s)protected final PyList basebytes_splitlines(boolean keepends)
splitlines(keepends)
, returning a list of
the lines in the array, breaking at line boundaries. Line breaks are not included in the
resulting list unless keepends
is given and true.
The elements of the PyList
returned by this method are instances of the same actual
type as this
.
keepends
- if true, include the end of line bytes(s)protected static byte fillByteCheck(java.lang.String function, java.lang.String fillchar)
basebytes_rjust(int, String)
,
basebytes_ljust(int, String)
and basebytes_center(int, String)
, which is
required to be a single character string, treated as a byte.function
- namefillchar
- or null
public boolean isalnum()
isalnum()
. This method treats the bytes as US-ASCII
code points.public boolean isalpha()
isalpha()
. This method treats the bytes as US-ASCII
code points.public boolean isdigit()
isdigit()
. This method treats the bytes as US-ASCII
code points.public boolean islower()
islower()
. This method treats the bytes as US-ASCII
code points.public boolean isspace()
isspace()
. This method treats the bytes as US-ASCII
code points.public boolean istitle()
istitle()
. This method treats the bytes as US-ASCII
code points.public boolean isupper()
isupper()
. This method treats the bytes as US-ASCII
code points.public BaseBytes capitalize()
capitalize()
. This method treats the bytes as US-ASCII
code points. The BaseBytes
returned by this method has the same actual type as
this/self
.public BaseBytes lower()
lower()
. This method treats the bytes as US-ASCII code
points. The BaseBytes
returned by this method has the same actual type as
this/self
.public BaseBytes swapcase()
swapcase()
. This method treats the bytes as US-ASCII
code points. The BaseBytes
returned by this method has the same actual type as
this/self
.public BaseBytes title()
title()
. The algorithm uses a simple
language-independent definition of a word as groups of consecutive letters. The definition
works in many contexts but it means that apostrophes in contractions and possessives form
word boundaries, which may not be the desired result. The BaseBytes
returned by this
method has the same actual type as this/self
.public BaseBytes upper()
upper()
. Note that x.upper().isupper()
might be
false
if the array contains uncased characters. The BaseBytes
returned by
this method has the same actual type as this/self
.public int intAt(int index) throws PyException
index
- of value in byte arrayPyException
- IndexError
if the index is outside the array boundspublic int size()
bytearray
(or bytes
) object.public boolean isEmpty()
public boolean contains(java.lang.Object o)
public java.util.Iterator<PyInteger> iterator()
public java.lang.Object[] toArray()
public <T> T[] toArray(T[] a)
public boolean add(PyInteger o)
public boolean remove(java.lang.Object o)
public boolean containsAll(java.util.Collection<?> c)
public boolean addAll(java.util.Collection<? extends PyInteger> c)
public boolean addAll(int index, java.util.Collection<? extends PyInteger> c)
addAll
in interface java.util.List<PyInteger>
public boolean removeAll(java.util.Collection<?> c)
public boolean retainAll(java.util.Collection<?> c)
public void clear()
public boolean equals(java.lang.Object other)
other
. In the
case where other
is a PyObject
, the comparison used is the standard Python
==
operation through PyObject
. When other
is not a PyObject
,
this object acts as a List<PyInteger>
.equals
in interface java.util.Collection<PyInteger>
equals
in interface java.util.List<PyInteger>
equals
in class PyObject
other
- object to compare this byte array totrue
if and only if this byte array is equal (in value) to other
List.equals(java.lang.Object)
public int hashCode()
public PyInteger set(int index, PyInteger element)
set
in interface java.util.List<PyInteger>
public void add(int index, PyInteger element)
add
in interface java.util.List<PyInteger>
public PyInteger remove(int index)
remove
in interface java.util.List<PyInteger>
public int indexOf(java.lang.Object o)
indexOf
in interface java.util.List<PyInteger>
public int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface java.util.List<PyInteger>
public java.util.ListIterator<PyInteger> listIterator()
listIterator
in interface java.util.List<PyInteger>
public java.util.ListIterator<PyInteger> listIterator(int index)
listIterator
in interface java.util.List<PyInteger>
public java.util.List<PyInteger> subList(int fromIndex, int toIndex)
subList
in interface java.util.List<PyInteger>
protected abstract BaseBytes getResult(BaseBytes.Builder b)
Builder
and return
that class' particular type, possibly without copying. Although the instance of which this is
a method is not used, the class of that instance determines which overridden implementation
is chosen, and hence both the action and the return type.b
- containing the resultprotected static final int roundUp(int size)
Builder
. We'll be more generous than CPython
for small array sizes to avoid needless reallocation.size
- of storage actually needed