Package perforce :: Module forms :: Class Form
[frames] | no frames]

Class Form



object --+
         |
        Form

A Perforce form object.

A form consists of a collection of named fields, each with a particular type and format. The form object handles parsing and formatting of Perforce forms to/from Python values.

The field values are accessed using dictionary notation. ie. form['FieldName']

The field attributes are accessed using attribute notation. ie. form.FieldName

Instance Methods
 
__init__(self, specdef, data)
Construct a Form object from the specdef and form data.
 
__getattribute__(self, fieldName)
Return the details of a particular field in a perforce.api.SpecElem value.
 
__setattr__(self, fieldName, value)
Setting of field details is not allowed.
 
__delattr__(self, fieldName)
Deleting field details is not allowed.
 
__getitem__(self, fieldName)
Return the value of a particular field.
 
__setitem__(self, fieldName, value)
Set the value of a particular field.
 
__delitem__(self, fieldName)
Clear the value of a particular field.
 
__str__(self)
Format the form's values as a Perforce form.
 
__contains__(self, fieldName)
Query whether a particular field exists in this form.
int
__len__(self)
Query the number of fields in this form.
 
__iter__(self)
Iterate over the names of the fields in this form.

Inherited from object: __hash__, __new__, __reduce__, __reduce_ex__, __repr__

Properties
  spec
  values

Inherited from object: __class__

Method Details

__init__(self, specdef, data)
(Constructor)

 
Construct a Form object from the specdef and form data.
Parameters:
  • specdef (str) - The Perforce form specification string. Typically obtained from the Perforce server via the outputStat() method.
  • data (str) - The formatted Perforce form data to parse.
Raises:
  • SpecError - If the specdef is not a valid Perforce form specification.
  • ParseError - If the form data is incorrectly formatted or references invalid fields.
Overrides: object.__init__

__getattribute__(self, fieldName)

 
Return the details of a particular field in a perforce.api.SpecElem value.
Raises:
  • AttributeError - if there is no such field.
Overrides: object.__getattribute__

__setattr__(self, fieldName, value)

 
Setting of field details is not allowed.
Raises:
  • AttributeError - Unconditionally.
Overrides: object.__setattr__

__delattr__(self, fieldName)

 
Deleting field details is not allowed.
Raises:
  • AttributeError - Unconditionally.
Overrides: object.__delattr__

__getitem__(self, fieldName)
(Indexing operator)

 
Return the value of a particular field.
Returns:
The value of the field. The type of the field can be determined from the field's corresponding perforce.api.SpecElem. Multi-word fields are stored as tuples, list fields are stored as lists and single-line fields or multi-line text fields are stored as strs.
Raises:
  • KeyError - if there is no such field.

See Also: __setitem__

__setitem__(self, fieldName, value)
(Index assignment operator)

 
Set the value of a particular field.
Raises:
  • KeyError - if there is no such field.

__delitem__(self, fieldName)
(Index deletion operator)

 
Clear the value of a particular field.
Raises:
  • KeyError - if there is no such field.

See Also: __setitem__

__str__(self)
(Informal representation operator)

 
Format the form's values as a Perforce form.
Overrides: object.__str__

Note: Fields with values that do not have the correct Python type (list, tuple, str etc) will be treated as though the field has no value associated.

__contains__(self, fieldName)
(In operator)

 

Query whether a particular field exists in this form.

Enables code such as:
 | if 'FieldName' in form:
 |   value = form['FieldName']

__iter__(self)

 

Iterate over the names of the fields in this form.

Enables code such as:
 | for fieldName in form:
 |   print form[fieldName]