pyds.Label

class pyds.Label(*statements)

Bases: pyds.Statements

Represents a PDS label.

Parameters
Raises

Methods

Label.insert(index, statement)

Insert the statement statement at index index.

Parameters
  • index (int)

    The index at which to insert the statement.

    index can be any integer (positive or negative). If negative, it’s taken to mean the index from the end. For example, s.insert(-10, stmt) is the same as s.insert(len(s)-10, stmt).

    If index is out of range and positive, then statement is appended to the end. If it’s out of range and negative, then statement is prepended to the begining.

  • statement (Attribute, Group or Object)

    The statement to insert. It must be an instance of either Attribute, Group or Object.

    Also, statement‘s identifier must not be the same as any other statement previously inserted.

Raises
Label.append(statement)

Append the statement statement.

Note

Calling s.append(stmt) is the same as calling s.insert(len(s), stmt). See insert() for further documentation.

Label.get(index)

Return the statement at index index.

Parameters
  • index (int)

    The index from where to return the statement.

    index can be any integer (positive or negative). If negative, it’s taken to mean the index from the end. For example, s.get(-10) is the same as s.get(len(s)-10).

Raises
Label.pop(index)

Remove and return the statement at index index.

Parameters
  • index (int)

    The index from where to remove and return the statement.

    index can be any integer (positive or negative). If negative, it’s taken to mean the index from the end. For example, s.pop(-10) is the same as s.pop(len(s)-10).

Raises

Special Methods

Label.__setitem__(key, value)

Create and insert a new statement using key and value.

Parameters
  • key (str)

    The identifier of the new statement.

    If value is an instance of Value, then key must be a valid identifier such that a new Attribute can be instantiated as, Attribute(key, value).

    If value is an instance of GroupStatements, then key must be a valid identifier such that a new Group can be instantiated as, Group(key, value).

    If value is an instance of ObjectStatements, then key must be a valid identifier such that a new Object can be instantiated as, Object(key, value).

  • value (Value, GroupStatements or ObjectStatements)

    value determines the type of the new statement.

    If value is an instance of Value, then an Attribute statement is created.

    If value is an instance of GroupStatements, then a Group statement is created.

    If value is an instance of ObjectStatements, then an Object statement is created.

Raises
Label.__getitem__(key)

Return the value of the statement whose identifier is key.

Parameters
  • key (str)

    The identifier of the statement. key is case-insensitive.

Raises
  • KeyError

    If a statement with an identifier equal to key does not exist.

Label.__delitem__(key)

Remove the statement whose identifier is key.

Parameters
  • key (str)

    The identifier of the statement. key is case-insensitive.

Raises
  • KeyError

    If a statement with an identifier equal to key does not exist.

Label.__contains__(key)

Test if a statement exists whose identifier is key. Return True if it exists, and False otherwise.

Parameters
  • key (str)

    The identifier of the statement. key is case-insensitive.

Label.__iter__()

Return an iterator that iterates over the statements.

Called by iter().

Label.__reversed__()

Return an iterator that iterates over the statements in reverse order.

Called by reversed().

Label.__len__()

Return the number of statements.

Called by len().

Label.__str__()

Return a PDS serialized string (str) representing the object.

Called by str().

Label.__bytes__()

Return the object’s PDS serialization str as an ascii bytes string.

See also

__str__()

Called by bytes().