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.
| Modifier and Type | Field and Description |
|---|---|
| protected PyString | shadow
The shadow string is additionally used for some comparisons, especially for __eq__. |
| protected PyList | |
| public static final PyType |
| Access | Constructor and Description |
|---|---|
| public | |
| public | PyShadowString(String primary, String shadow)
Construct an instance specifying primary and shadow values. |
| public | PyShadowString(PyObject primary, String shadow)
Deprecated
use the constructor with strings instead.
Construct an instance specifying primary and shadow values (bytes object expected for primary). |
| private | PyShadowString(PyObject primary, PyObject shadow)
Construct an instance specifying primary and shadow values (bytes objects expected). |
| private | |
| public | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public PyObject | Returns: PyBoolean result (or null if not implemented)to compare other)Overrides org. Compare this |
| public PyObject | __getslice__(PyObject start, PyObject stop, PyObject step)
Overrides org.
|
| public PyString | __repr__()
Overrides org. Equivalent to the standard Python |
| public void | |
| private static PyObject | |
| private static Pattern | |
| public PyString | |
| public PyList | getTargets()
Return a list of the tuples specifying the contexts in which the shadow value will be consulted during matching. |
| private boolean | Returns: true iff in one of the named contextsTest whether the current code is executing in of one of the target contexts, by searching up the stack for a class and method pait that match. |
| pack-priv final PyObject | |
| pack-priv final PyString | |
| public final void | |
| public final PyString | |
| public final PyObject | |
| pack-priv static PyObject | |
| pack-priv final boolean | |
| public boolean | startswith(PyObject
string to check for (or a prefix)PyTuple of them).Overrides org. Equivalent to the Python |
| public boolean | startswith(PyObject
string to check for (or a prefix, PyObject PyTuple of them).start of slice. start)Overrides org. Equivalent to the Python |
| public boolean | startswith(PyObject
string to check for (or a prefix, PyObject PyTuple of them).start of slice. start, PyObject end of slice. end)Overrides org. Equivalent to the Python |
| private static final PyObject |
| shadow | back to summary |
|---|---|
| protected PyString shadow The shadow string is additionally used for some comparisons, especially for __eq__. __eq__ will evaluate positive if the other string equals the primary value *or* the shadow. The shadow persists slicing (is sliced accordingly) and is taken into account by startswith. | |
| targets | back to summary |
|---|---|
| protected PyList targets Contexts (expressed as a | |
| TYPE | back to summary |
|---|---|
| public static final PyType TYPE | |
| PyShadowString | back to summary |
|---|---|
| public PyShadowString() Empty string (not very useful but needed for technical reasons). | |
| PyShadowString | back to summary |
|---|---|
| public PyShadowString(String primary, String shadow) Construct an instance specifying primary and shadow values. | |
| PyShadowString | back to summary |
|---|---|
| public PyShadowString(PyObject primary, String shadow)
Deprecated use the constructor with strings instead. Construct an instance specifying primary and shadow values (bytes object expected for primary). This somewhat uncanonical constructor was removed in Jython 2.7.2. The deprecated version is kept for compatibility with JyNI 2.7-alpha5.
| |
| PyShadowString | back to summary |
|---|---|
| private PyShadowString(PyObject primary, PyObject shadow) Construct an instance specifying primary and shadow values (bytes objects expected). | |
| PyShadowString | back to summary |
|---|---|
| private PyShadowString(PyObject primary, PyObject shadow, PyList targets) | |
| PyShadowString | back to summary |
|---|---|
| public PyShadowString(PyType subtype, PyObject primary, PyObject shadow) | |
| PyShadowString | back to summary |
|---|---|
| private PyShadowString(PyType subtype, PyObject primary, PyObject shadow, PyList targets) | |
| __eq__ | back to summary |
|---|---|
| public PyObject __eq__(PyObject other) Overrides org. Compare this | |
| __getslice__ | back to summary |
|---|---|
| public PyObject __getslice__(PyObject start, PyObject stop, PyObject step) Overrides org.
| |
| __repr__ | back to summary |
|---|---|
| public PyString __repr__() Overrides org. Doc from org. Equivalent to the standard Python
| |
| addTarget | back to summary |
|---|---|
| public void addTarget(String className, String methodName) Specify a context (class, method) in which the shadow string is allowed to match. | |
| asUnicode | back to summary |
|---|---|
| private static PyObject asUnicode(PyObject o) Prepare argument for addtarget, allowing string-like values or None. | |
| getPattern | back to summary |
|---|---|
| private static Pattern getPattern(PyObject o) Convert a PyObject (specifying a regex) to a compiled pattern or null. | |
| getshadow | back to summary |
|---|---|
| public PyString getshadow() Get the shadow value. | |
| getTargets | back to summary |
|---|---|
| public PyList getTargets() Return a list of the tuples specifying the contexts in which the shadow value will be consulted during matching. | |
| isTarget | back to summary |
|---|---|
| private boolean isTarget() Test whether the current code is executing in of one of the target contexts, by searching up the stack for a class and method pait that match.
| |
| shadowstr___eq__ | back to summary |
|---|---|
pack-priv final PyObject shadowstr___eq__(PyObject other)
| |
| shadowstr___repr__ | back to summary |
|---|---|
pack-priv final PyString shadowstr___repr__()
| |
| shadowstr_addtarget | back to summary |
|---|---|
public final void shadowstr_addtarget(PyObject classname, PyObject methodname)
| |
| shadowstr_getshadow | back to summary |
|---|---|
public final PyString shadowstr_getshadow()
| |
| shadowstr_gettargets | back to summary |
|---|---|
public final PyObject shadowstr_gettargets()
| |
| shadowstr_new | back to summary |
|---|---|
pack-priv static PyObject shadowstr_new(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords)
| |
| shadowstr_startswith | back to summary |
|---|---|
pack-priv final boolean shadowstr_startswith(PyObject prefix, PyObject startObj, PyObject endObj)
| |
| startswith | back to summary |
|---|---|
| public boolean startswith(PyObject prefix) Overrides org. Doc from org. Equivalent to the Python | |
| startswith | back to summary |
|---|---|
| public boolean startswith(PyObject prefix, PyObject start) Overrides org. Doc from org. Equivalent to the Python
| |
| startswith | back to summary |
|---|---|
| public boolean startswith(PyObject prefix, PyObject start, PyObject end) Overrides org. Doc from org. Equivalent to the Python
| |
| testEqual | back to summary |
|---|---|
| private static final PyObject testEqual(PyString string, PyObject other) Test for equality, used as a helper to | |