public class PyShadowString extends PyString
startswith
are concerned. This solves a problem that Jython users sometimes
experience with libraries that are sensitive to platform.
A library may test for a particular platform in order to adjust to local file name conventions or
to decide which operating system commands are available. In Jython, os.name
and
sys.platform
indicate that Java is the platform, which is necessary information in
some parts of the standard library, but other libraries assuming CPython then draw incorrect
conclusions.
With hindsight, a better choice could be made, where sys.platform
etc. indicated
Windows or Posix, and something else indicates the implementation. A change in Jython 2 would
cause more problems than it solved, but we expect Jython 3 to work that way. In the Python
Standard Library, the Jython project can make all necessary changes. It can't do anything about
third-party libraries. But it would be a big help if users could cause sys.platform
or os.name
to appear to have the OS-dependent value as far as those troublesome
libraries were concerned.
This is what this class achieves. os.name
and sys.platform
regular
strings for most purposes, but each has a "shadow" value that is used in contexts the user may
specify.
PyObject.ConversionException
Modifier and Type | Field and Description |
---|---|
static PyType |
TYPE |
gcMonitorGlobal
Constructor and Description |
---|
PyShadowString()
Empty string (not very useful but needed for technical reasons).
|
PyShadowString(PyObject primary,
java.lang.String shadow)
Deprecated.
use the constructor with strings instead.
|
PyShadowString(PyType subtype,
PyObject primary,
PyObject shadow) |
PyShadowString(java.lang.String primary,
java.lang.String shadow)
Construct an instance specifying primary and shadow values.
|
Modifier and Type | Method and Description |
---|---|
PyObject |
__eq__(PyObject other)
Compare this
PyShadowString with another PyObject for equality. |
PyObject |
__getslice__(PyObject start,
PyObject stop,
PyObject step) |
PyString |
__repr__()
Equivalent to the standard Python
__repr__ method. |
void |
addTarget(java.lang.String className,
java.lang.String methodName)
Specify a context (class, method) in which the shadow string is allowed to match.
|
PyString |
getshadow()
Get the shadow value.
|
PyList |
getTargets()
Return a list of the tuples specifying the contexts in which the shadow value will be
consulted during matching.
|
void |
shadowstr_addtarget(PyObject classname,
PyObject methodname) |
PyString |
shadowstr_getshadow() |
PyObject |
shadowstr_gettargets() |
boolean |
startswith(PyObject prefix)
Equivalent to the Python
str.startswith method testing whether a string starts
with a specified prefix. |
boolean |
startswith(PyObject prefix,
PyObject start)
Equivalent to the Python
str.startswith method, testing whether a string starts
with a specified prefix, where a sub-range is specified by [start:] . |
boolean |
startswith(PyObject prefix,
PyObject start,
PyObject end)
Equivalent to the Python
str.startswith method, testing whether a string starts
with a specified prefix, where a sub-range is specified by [start:end] . |
__add__, __cmp__, __complex__, __contains__, __float__, __format__, __ge__, __getnewargs__, __gt__, __int__, __invert__, __le__, __len__, __long__, __lt__, __mod__, __mul__, __ne__, __neg__, __pos__, __rmul__, __str__, __tojava__, __unicode__, asDouble, asInt, asLong, asName, asString, asString, atof, atoi, atoi, atol, atol, capitalize, center, charAt, count, count, count, count, count, count, createInstance, decode_UnicodeEscape, decode, decode, decode, encode_UnicodeEscape, encode, encode, encode, endswith, endswith, endswith, expandtabs, expandtabs, find, find, find, find, find, find, fromInterned, getBuffer, getInt, getString, hashCode, index, index, index, index, index, index, internedString, isalnum, isalpha, isBasicPlane, isdecimal, isdigit, islower, isnumeric, isspace, istitle, isunicode, isupper, join, length, ljust, ljust, lower, lstrip, lstrip, lstrip, partition, replace, replace, rfind, rfind, rfind, rfind, rfind, rfind, rindex, rindex, rindex, rindex, rindex, rindex, rjust, rpartition, rsplit, rsplit, rsplit, rsplit, rsplit, rstrip, rstrip, rstrip, split, split, split, split, split, splitlines, splitlines, str___mod__, strip, strip, strip, subSequence, substring, swapcase, title, toBytes, toCodePoints, toString, translate, translate, translate, translate, upper, zfill
__delitem__, __delslice__, __finditem__, __finditem__, __getitem__, __iter__, __nonzero__, __setitem__, __setitem__, __setslice__, isMappingType, isNumberType, isSequenceType
__abs__, __and__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __coerce__, __coerce_ex__, __delattr__, __delattr__, __delete__, __delitem__, __delslice__, __dir__, __div__, __divmod__, __ensure_finalizer__, __findattr__, __findattr__, __findattr_ex__, __finditem__, __floordiv__, __get__, __getattr__, __getattr__, __getitem__, __getslice__, __hash__, __hex__, __iadd__, __iand__, __idiv__, __idivmod__, __ifloordiv__, __ilshift__, __imod__, __imul__, __index__, __ior__, __ipow__, __irshift__, __isub__, __iternext__, __itruediv__, __ixor__, __lshift__, __not__, __oct__, __or__, __pow__, __pow__, __radd__, __rand__, __rdiv__, __rdivmod__, __reduce__, __reduce_ex__, __reduce_ex__, __rfloordiv__, __rlshift__, __rmod__, __ror__, __rpow__, __rrshift__, __rshift__, __rsub__, __rtruediv__, __rxor__, __set__, __setattr__, __setattr__, __setitem__, __setslice__, __sub__, __truediv__, __trunc__, __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, asIndex, asIndex, asInt, asIterable, asLong, asName, asStringOrNull, asStringOrNull, bit_length, conjugate, delDict, delType, dispatch__init__, equals, fastGetClass, fastGetDict, getDict, getType, implementsDescrDelete, implementsDescrGet, implementsDescrSet, invoke, invoke, invoke, invoke, invoke, invoke, isCallable, isDataDescr, isIndex, isInteger, noAttributeError, object___subclasshook__, readonlyAttributeError, setDict, setType
public static final PyType TYPE
public PyShadowString()
public PyShadowString(java.lang.String primary, java.lang.String shadow)
@Deprecated public PyShadowString(PyObject primary, java.lang.String shadow)
public PyString getshadow()
public final PyString shadowstr_getshadow()
public void addTarget(java.lang.String className, java.lang.String methodName)
className
- class name to match or null to match anything.methodName
- method name to match or null to match anything.public PyList getTargets()
public final PyObject shadowstr_gettargets()
public PyObject __eq__(PyObject other)
PyShadowString
with another PyObject
for equality. A
PyShadowString
is equal to the other object if its primary value is equal to it,
or if its shadow value is equal to the other object and the test is made in one of its target
contexts. (Two PyShadowString
are equal if the primary values are equal, the
primary of one matches the shadow of the other in the shadow's context, or their shadows
match and both are in context.public PyObject __getslice__(PyObject start, PyObject stop, PyObject step)
__getslice__
in class PySequence
public boolean startswith(PyObject prefix)
PyString
str.startswith
method testing whether a string starts
with a specified prefix. prefix
can also be a tuple of prefixes to look for.startswith
in class PyString
prefix
- string to check for (or a PyTuple
of them).true
if this string slice starts with a specified prefix, otherwise
false
.public boolean startswith(PyObject prefix, PyObject start)
PyString
str.startswith
method, testing whether a string starts
with a specified prefix, where a sub-range is specified by [start:]
.
start
is interpreted as in slice notation, with null or Py.None
representing "missing". prefix
can also be a tuple of prefixes to look for.startswith
in class PyString
prefix
- string to check for (or a PyTuple
of them).start
- start of slice.true
if this string slice starts with a specified prefix, otherwise
false
.public boolean startswith(PyObject prefix, PyObject start, PyObject end)
PyString
str.startswith
method, testing whether a string starts
with a specified prefix, where a sub-range is specified by [start:end]
.
Arguments start
and end
are interpreted as in slice notation, with
null or Py.None
representing "missing". prefix
can also be a tuple of
prefixes to look for.startswith
in class PyString
prefix
- string to check for (or a PyTuple
of them).start
- start of slice.end
- end of slice.true
if this string slice starts with a specified prefix, otherwise
false
.