Top Description Inners Fields Constructors Methods
org.python.core.stringlib

public Class FieldNameIterator

extends PyObject
implements Traverseproc
Class Inheritance
All Implemented Interfaces
org.python.core.Traverseproc
Annotations
@ExposedType
name:fieldnameiterator
base:PyObject
isBaseType:false
Imports
org.python.core.Py, .PyBoolean, .PyInteger, .PyObject, .PyString, .PyTuple, .PyType, .PyUnicode, .Traverseproc, .Visitproc, org.python.expose.ExposedMethod, .ExposedType, org.python.modules.gc

This class is an implementation of the iterator object returned by str._formatter_field_name_split() and unicode._formatter_field_name_split(). The function _formatter_field_name_split() returns a pair (tuple) consisting of a head element and an instance of this iterator. The constructor of this class effectively implements that function, since as well as "being" the iterator, the object has an extra method head() to return the required first member of the pair.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final boolean
bytes

True if originally given a PyString (so must return PyString not PyUnicode).

private Object
private int
index

How far along that string we are.

private final String
markup

The UTF-16 string from which elements are being returned.

public static final PyType
Inherited from org.python.core.PyObject:
attributesgcMonitorGlobalobjtype

Constructor Summary

AccessConstructor and Description
public
FieldNameIterator(String
the field name as UTF-16
fieldName
,
boolean
true if elements returned should be PyString, else PyUnicode
bytes
)

Create an iterator for the parts of this field name (and extract the head name field, which may be an empty string).

public
FieldNameIterator(PyString fieldNameObject)

Create an iterator for the parts of this field name (and extract the head name field, which may be an empty string).

Method Summary

Modifier and TypeMethod and Description
public PyObject
__iter__()

Overrides org.python.core.PyObject.__iter__.

Return an iterator that is used to iterate the element of this sequence.

public PyObject
__iternext__()

Overrides org.python.core.PyObject.__iternext__.

Return the next element of the sequence that this is an iterator for.

pack-priv final PyObject
pack-priv final PyObject
public Object

Returns:

the isolated head object from the field name.
head
()

public final boolean

Returns:

true if originally given a PyString
isBytes
()

If originally given a PyString, the iterator must return PyString not PyUnicode.

public FieldNameIterator.Chunk

Returns:

next element of the field name
nextChunk
()

Return the next "chunk" of the field name (or return null if ended).

private int
private void
private void
public PyObject

Returns:

the isolated head object from the field name.
pyHead
()

Return the head object from the field name, as PyInteger, PyString or PyUnicode.

public boolean
public int
traverse(Visitproc visit, Object arg)

Implements org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects.

private PyObject

Returns:

PyObject equivalent field specifier
wrap
(Object
to wrap as a PyObject.
value
)

Convenience method to wrap a value as a PyInteger, if it is an Integer, or as PyString or PyUnicode according to the type of the original field name string.

Inherited from org.python.core.PyObject:
__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____rawdir____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_unsupportedop_xoradaptToCoerceTupleasDoubleasIndexasIndexasIntasIntasIterableasLongasLongasNameasNameasStringasStringasStringOrNullasStringOrNullbit_lengthconjugatedelDictdelTypedispatch__init__equalsfastGetClassfastGetDictfinalizegetDictgetJavaProxygetTypehashCodeimpAttrimplementsDescrDeleteimplementsDescrGetimplementsDescrSetinvokeinvokeinvokeinvokeinvokeinvokeisCallableisDataDescrisIndexisIntegerisMappingTypeisNumberTypeisSequenceTypemergeClassDictmergeDictAttrmergeListAttrnoAttributeErrorobject___subclasshook__readonlyAttributeErrorrunsupportedopMessagesetDictsetTypetoStringunsupportedopMessage

Field Detail

bytesback to summary
private final boolean bytes

True if originally given a PyString (so must return PyString not PyUnicode).

indexback to summary
private int index

How far along that string we are.

markupback to summary
private final String markup

The UTF-16 string from which elements are being returned.

TYPEback to summary
public static final PyType TYPE

Hides org.python.core.PyObject.TYPE.

Constructor Detail

FieldNameIteratorback to summary
public FieldNameIterator(String fieldName, boolean bytes)

Create an iterator for the parts of this field name (and extract the head name field, which may be an empty string). According to the Python Standard Library documentation, a replacement field name has the structure:

field_name        ::=  arg_name ("." attribute_name | "[" element_index "]")*
arg_name          ::=  [identifier | integer]
attribute_name    ::=  identifier
element_index     ::=  integer | index_string
The object is used from PyUnicode and from PyString, and we have to signal which it is, so that returned values may match in type.
Parameters
fieldName:String

the field name as UTF-16

bytes:boolean

true if elements returned should be PyString, else PyUnicode

FieldNameIteratorback to summary
public FieldNameIterator(PyString fieldNameObject)

Create an iterator for the parts of this field name (and extract the head name field, which may be an empty string).

Method Detail

__iter__back to summary
public PyObject __iter__()

Overrides org.python.core.PyObject.__iter__.

Doc from org.python.core.PyObject.__iter__.

Return an iterator that is used to iterate the element of this sequence. From version 2.2, this method is the primary protocol for looping over sequences.

If a PyObject subclass should support iteration based in the __finditem__() method, it must supply an implementation of __iter__() like this:

public PyObject __iter__() {
    return new PySequenceIter(this);
}
When iterating over a python sequence from java code, it should be done with code like this:
for (PyObject item : seq.asIterable()) {
    // Do something with item
}
Annotations
@Override
__iternext__back to summary
public PyObject __iternext__()

Overrides org.python.core.PyObject.__iternext__.

Doc from org.python.core.PyObject.__iternext__.

Return the next element of the sequence that this is an iterator for. Returns null when the end of the sequence is reached.

Annotations
@Override
fieldnameiterator___iter__back to summary
pack-priv final PyObject fieldnameiterator___iter__()
Annotations
@ExposedMethod
fieldnameiterator___iternext__back to summary
pack-priv final PyObject fieldnameiterator___iternext__()
Annotations
@ExposedMethod
headback to summary
public Object head()
Returns:Object

the isolated head object from the field name.

isBytesback to summary
public final boolean isBytes()

If originally given a PyString, the iterator must return PyString not PyUnicode.

Returns:boolean

true if originally given a PyString

nextChunkback to summary
public FieldNameIterator.Chunk nextChunk()

Return the next "chunk" of the field name (or return null if ended). A chunk is a 2-tuple describing:

  1. whether the chunk is an attribute name,
  2. the name or number (as a String or Integer) for accessing the value.
Returns:FieldNameIterator.Chunk

next element of the field name

nextDotOrBracketback to summary
private int nextDotOrBracket(String markup)
parseAttrChunkback to summary
private void parseAttrChunk(FieldNameIterator.Chunk chunk)
parseItemChunkback to summary
private void parseItemChunk(FieldNameIterator.Chunk chunk)
pyHeadback to summary
public PyObject pyHead()

Return the head object from the field name, as PyInteger, PyString or PyUnicode.

Returns:PyObject

the isolated head object from the field name.

refersDirectlyToback to summary
public boolean refersDirectlyTo(PyObject ob) throws UnsupportedOperationException

Implements org.python.core.Traverseproc.refersDirectlyTo.

Doc from org.python.core.Traverseproc.refersDirectlyTo.

Optional operation. Should only be implemented if it is more efficient than calling traverse(Visitproc, Object) with a visitproc that just watches out for ob. Must return false if ob is null.

Annotations
@Override
traverseback to summary
public int traverse(Visitproc visit, Object arg)

Implements org.python.core.Traverseproc.traverse.

Doc from org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects. Like in CPython, arg must be passed unmodified to visit as its second parameter. If Visitproc#visit(PyObject, Object) returns nonzero, this return value must be returned immediately by traverse. Visitproc#visit(PyObject, Object) must not be called with a null PyObject-argument.

Annotations
@Override
wrapback to summary
private PyObject wrap(Object value)

Convenience method to wrap a value as a PyInteger, if it is an Integer, or as PyString or PyUnicode according to the type of the original field name string. These objects are being used as field specifiers in navigating arguments to a format statement.

Parameters
value:Object

to wrap as a PyObject.

Returns:PyObject

PyObject equivalent field specifier

org.python.core.stringlib back to summary

public Class FieldNameIterator.Chunk

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public boolean
public Object
value

Integer or String.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

is_attrback to summary
public boolean is_attr
valueback to summary
public Object value

Integer or String.

Constructor Detail

Chunkback to summary
public Chunk()