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

public Class MarkupIterator

extends PyObject
Class Inheritance
Annotations
@Untraversable
@ExposedType
name:formatteriterator
base:PyObject
isBaseType:false
Imports
org.python.core.Py, .PyObject, .PyString, .PyTuple, .PyType, .PyUnicode, .Untraversable, org.python.expose.ExposedMethod, .ExposedType

Provides an implementation of the object that str._formatter_parser() returns, which is an iterator returning successive 4-tuples, the sequence being equivalent to the original string.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
pack-priv static class
MarkupIterator.FieldNumbering

Class used locally to assign indexes to the automatically-numbered arguments (see String Formatting section of the Python Standard Library).

Field Summary

Modifier and TypeField and Description
private final boolean
bytes

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

private int
index

How far along that string we are.

private final String
markup

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

private final MarkupIterator.FieldNumbering
numbering

A counter used to auto-number fields when not explicitly numbered in the format.

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

Constructor Summary

AccessConstructor and Description
public
MarkupIterator(PyString markupObject)

Constructor used at top-level to enumerate a format.

public
MarkupIterator(MarkupIterator enclosingIterator, String subMarkup)

Variant constructor used when formats are nested.

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

Returns:

PyTuple chunk or null
formatteriterator___iternext__
()

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

private int
indexOfFirst(String s, int start, char c1, char c2)

Find the first of two characters, or return -1.

public final boolean

Returns:

true if originally given a PyString
isBytes
()

If originally given a PyString, string elements in the returned tuples must be PyString not PyUnicode.

public MarkupIterator.Chunk

Returns:

the chunk
nextChunk
()

Return the next Chunk from the iterator, which is a structure containing parsed elements of the replacement field (if any), and its preceding text.

private void
parseField(MarkupIterator.Chunk
destination chunk
result
,
String
specifying a replacement field, possibly with nesting
fieldMarkup
)

Parse a "replacement field" consisting of a name, conversion and format specification.

private String
private PyObject

Returns:

object for tuple
wrap
(String
to wrap as a PyObject or null if defaultValue should be wrapped.
value
,
String
to return or null if default return is None.
defaultValue
)

Convenience method for populating the return tuple, returning a PyString or PyUnicode according to the type of the original markup string, or Py.None if both arguments are null.

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.

numberingback to summary
private final MarkupIterator.FieldNumbering numbering

A counter used to auto-number fields when not explicitly numbered in the format.

TYPEback to summary
public static final PyType TYPE

Hides org.python.core.PyObject.TYPE.

Constructor Detail

MarkupIteratorback to summary
public MarkupIterator(PyString markupObject)

Constructor used at top-level to enumerate a format.

MarkupIteratorback to summary
public MarkupIterator(MarkupIterator enclosingIterator, String subMarkup)

Variant constructor used when formats are nested.

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
formatteriterator___iter__back to summary
pack-priv final PyObject formatteriterator___iter__()
Annotations
@ExposedMethod
formatteriterator___iternext__back to summary
pack-priv final PyObject formatteriterator___iternext__()

Return the next "chunk" of the format (or return null if ended). A chunk is a 4-tuple describing

  1. the text leading up to the next format field,
  2. the field name or number (as a string) for accessing the value,
  3. the format specifier such as "#12x", and
  4. any conversion that should be applied (the 's' or 'r' codes for str() and repr())
Elements 1-3 are None if this chunk contains no format specifier. Elements 0-2 are zero-length strings if missing from the format, while element 3 will be None if missing.
Returns:PyObject

PyTuple chunk or null

Annotations
@ExposedMethod

indexOfFirstback to summary
private int indexOfFirst(String s, int start, char c1, char c2)

Find the first of two characters, or return -1.

isBytesback to summary
public final boolean isBytes()

If originally given a PyString, string elements in the returned tuples must be PyString not PyUnicode.

Returns:boolean

true if originally given a PyString

nextChunkback to summary
public MarkupIterator.Chunk nextChunk()

Return the next Chunk from the iterator, which is a structure containing parsed elements of the replacement field (if any), and its preceding text. This is the Java equivalent of the tuple returned by __iternext__(). This finds use in the implementation of str.format and unicode.format.

Returns:MarkupIterator.Chunk

the chunk

parseFieldback to summary
private void parseField(MarkupIterator.Chunk result, String fieldMarkup)

Parse a "replacement field" consisting of a name, conversion and format specification. According to the Python Standard Library documentation, a replacement field has the structure:

replacement_field ::=  "{" [field_name] ["!" conversion] [":" format_spec] "}"
field_name        ::=  arg_name ("." attribute_name | "[" element_index "]")*
arg_name          ::=  [identifier | integer]
attribute_name    ::=  identifier
element_index     ::=  integer | index_string
except at this point, we have already discarded the outer braces.
Parameters
result:MarkupIterator.Chunk

destination chunk

fieldMarkup:String

specifying a replacement field, possibly with nesting

unescapeBracesback to summary
private String unescapeBraces(String substring)
wrapback to summary
private PyObject wrap(String value, String defaultValue)

Convenience method for populating the return tuple, returning a PyString or PyUnicode according to the type of the original markup string, or Py.None if both arguments are null.

Parameters
value:String

to wrap as a PyObject or null if defaultValue should be wrapped.

defaultValue:String

to return or null if default return is None.

Returns:PyObject

object for tuple

org.python.core.stringlib back to summary

public final Class MarkupIterator.Chunk

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public String
conversion

Conversion to be applied, e.g. 'r' for repr().

public String
fieldName

The field name or number (as a string) for accessing the value.

public String
formatSpec

The format specifier such as "#12x".

public boolean
formatSpecNeedsExpanding

Signals the formatSpec needs expanding recursively.

public String
literalText

The text leading up to the next format field.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

conversionback to summary
public String conversion

Conversion to be applied, e.g. 'r' for repr().

fieldNameback to summary
public String fieldName

The field name or number (as a string) for accessing the value.

formatSpecback to summary
public String formatSpec

The format specifier such as "#12x".

formatSpecNeedsExpandingback to summary
public boolean formatSpecNeedsExpanding

Signals the formatSpec needs expanding recursively.

literalTextback to summary
public String literalText

The text leading up to the next format field.

Constructor Detail

Chunkback to summary
public Chunk()
org.python.core.stringlib back to summary

pack-priv final Class MarkupIterator.FieldNumbering

extends Object
Class Inheritance

Class used locally to assign indexes to the automatically-numbered arguments (see String Formatting section of the Python Standard Library).

Field Summary

Modifier and TypeField and Description
private int
private boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv String

Returns:

index as string
nextAutomaticFieldNumber
()

Generate a numeric argument index automatically, or raise an error if already started numbering manually.

pack-priv void
useManualFieldNumbering()

Remember we are numbering manually, and raise an error if already started numbering automatically.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

automaticFieldNumberback to summary
private int automaticFieldNumber
manualFieldNumberSpecifiedback to summary
private boolean manualFieldNumberSpecified

Constructor Detail

FieldNumberingback to summary
pack-priv FieldNumbering()

Method Detail

nextAutomaticFieldNumberback to summary
pack-priv String nextAutomaticFieldNumber()

Generate a numeric argument index automatically, or raise an error if already started numbering manually.

Returns:String

index as string

useManualFieldNumberingback to summary
pack-priv void useManualFieldNumbering()

Remember we are numbering manually, and raise an error if already started numbering automatically.