gavo.formal.util module

class gavo.formal.util.CaseSemisensitiveDict(*args, **kwargs)[source]

Bases: dict

A dictionary allowing case-insensitive access to its content.

This is used for DAL renderers which, unfortunately, are supposed to be case insensitive. Since case insensitivity is at least undesirable for service-specific keys, we go a semi-insenstitve approach here: First, we try literal matches, if that does not work, we try matching against an all-uppercase version.

Name clashes resulting from different names being mapped to the same normalized version are handled in some random way. Don’t do this. And don’t rely on case normalization if at all possible.

Only strings are allowed as keys here. This class is not concerned with the values. >>> d = CaseSemisensitiveDict({“a”: 1, “A”: 2, “b”: 3}) >>> d[“a”], d[“A”], d[“b”], d[“B”] (1, 2, 3, 3) >>> d[“B”] = 9; d[“b”], d[“B”] (3, 9) >>> del d[“b”]; d[“b”], d[“B”] (9, 9) >>> “B” in d, “b” in d, “u” in d (True, True, False) >>> d.pop(“a”), list(d.keys()) (1, [‘A’, ‘B’])

classmethod fromDict(aDict)[source]
get(key, default=None)[source]

Return the value for key if key is in the dictionary, else default.

pop(k[, d]) v, remove specified key and return the corresponding value.[source]

If the key is not found, return the default if given; otherwise, raise a KeyError.

class gavo.formal.util.SequenceKeyLabelAdapter(original)[source]

Bases: object

key()[source]
label()[source]
class gavo.formal.util.StringableLabelAdapter(original)[source]

Bases: object

label()[source]
gavo.formal.util.keytocssid(fieldKey, *extras)[source]
gavo.formal.util.render_cssid(fieldKey, *extras)[source]

Render the CSS id for the form field’s key.

gavo.formal.util.titleFromName(name)[source]
gavo.formal.util.validIdentifier(name)[source]

Test that name is a valid Python identifier.