Package perforce :: Module api :: Class Spec
[frames] | no frames]

Class Spec



object --+
         |
        Spec

A Perforce form specification.

A form specification is a collection of field specifictaions that are used to parse and format Perforce text-based forms.

Spec objects can be treated as Python dict-like objects that map from the field name to the field's SpecElem.

For example:
 | spec = Spec(specdef)
 | for fieldName in spec:
 |   specElem = spec[fieldName]
 |   assert specElem.tag == fieldName
If the specdef parameter passed to the constructor is a unicode string then all string operations will be performed using unicode strings. Otherwise all string operations will be performed using str strings.

Instance Methods
 
__getitem__(x, y)
x[y]
 
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
__iter__(x)
iter(x)
 
__len__(x)
len(x)
 
__new__(T, S, ...)
Returns: a new object with type S, a subtype of T
 
__str__(x)
str(x)
 
format(data)
Format a Python dictionary into a Perforce form using this specification.
 
parse(form)
Parse a form into a python dictionary using this form specification.

Inherited from object: __delattr__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__

Properties

Inherited from object: __class__

Method Details

__init__(...)
(Constructor)

 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Overrides: object.__init__

__new__(T, S, ...)

 
Returns:
a new object with type S, a subtype of T

Overrides: object.__new__

__str__(x)
(Informal representation operator)

 
str(x)
Overrides: object.__str__

format(data)

 
Format a Python dictionary into a Perforce form using this specification.
Parameters:
  • data - The form data values in a Python dictionary of field names to values (str or unicode, list and tuple data types).
Returns:
str or unicode

Note: If the values of any fields in data don't have the correct type then they will be ignored and treated as if they didn't exist.

See Also: parse

parse(form)

 

Parse a form into a python dictionary using this form specification.

Each field that has a value in the form will have a corresponding value populated in the returned dictionary.
  • Basic values are populated as str or unicode values.
  • Multi-line list values are populated as a list with one element per line of the form.
  • Multi-word fields are populated as a tuple of str or unicode for each line.
Parameters:
  • form (str or unicode) - The Perforce form contents to parse. This value will be coerced to the required string type, if required, using the default codec.
Returns:
dict

Raises:
  • ParseError - If an error occurred parsing the form.

See Also: format