LLWNameAttr

class igwn_ligolw.ligolw.LLWNameAttr(name)

Bases: str

Baseclass to hide pattern-matching of various element names. Subclasses must provide a .dec_pattern compiled regular expression defining a group “Name” that identifies the meaningful portion of the string, and a .enc_pattern that gives a format string to be used with “%” to reconstrct the full string.

This is intended to be used to provide the enc and dec functions for an attributeproxy instance.

Example:

>>> import re
>>> class Test(Element):
...     class TestName(LLWNameAttr):
...         dec_pattern = re.compile(r"(?P<Name>[a-z0-9_]+):test\Z")
...         enc_pattern = "%s:test"
...
...     Name = attributeproxy("Name", enc = TestName.enc, dec = TestName)
...
>>> x = Test()
>>> x.Name = "blah"
>>> # internally, suffix has been appended
>>> print(x.getAttribute("Name"))
blah:test
>>> # but attributeproxy reports original value
>>> print(x.Name)
blah
>>> # only lower-case Latin letters, numerals, and '_' are allowed
>>> x.Name = "Hello-world"
Traceback (most recent call last):
    ...
ValueError: invalid Name 'Hello-world'

Methods Summary

enc(name)

Methods Documentation

classmethod enc(name)