summaryrefslogtreecommitdiff
path: root/misc/pylib/extractor/tools.py
blob: f0750d7c33c120c06709af3c35ecdae104a5d8b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from ufoLib import fontInfoAttributesVersion3, validateFontInfoVersion3ValueForAttribute


class RelaxedInfo(object):

    """
    This object that sets only valid info values
    into the given info object.
    """

    def __init__(self, info):
        self._object = info

    def __getattr__(self, attr):
        if attr in fontInfoAttributesVersion3:
            return getattr(self._object, attr)
        else:
            return super(RelaxedInfo, self).__getattr__(attr)

    def __setattr__(self, attr, value):
        if attr in fontInfoAttributesVersion3:
            if validateFontInfoVersion3ValueForAttribute(attr, value):
                setattr(self._object, attr, value)
        else:
            super(RelaxedInfo, self).__setattr__(attr, value)


def copyAttr(src, srcAttr, dest, destAttr):
    if not hasattr(src, srcAttr):
        return
    value = getattr(src, srcAttr)
    setattr(dest, destAttr, value)