def flag_property(flag):
    """ A factory function which creates a flag accessor property.

    """
    def getter(self):
        return (self._flags & flag) != 0
    def setter(self, value):
        if value:
            self._flags |= flag
        else:
            self._flags &= ~flag
    return property(getter, setter)