Ejemplo n.º 1
0
    def __getattr__(self, name):
        if name not in self.__dict__["schema"]:
            raise AttributeError(name)

        context = self.__dict__["context"]
        key_name = self.__dict__["prefix"] + name
        field = self.__dict__["schema"][name]
        if not hasattr(context, key_name):
            return get_default_from_schema(self, self.__dict__["schema"], name, field.missing_value)

        return getattr(context, key_name)
Ejemplo n.º 2
0
    def __get__(self, inst, klass):
        if inst is None:
            return self

        result = getattr(inst.context, self.__name__, self.default)
        if callable(result):
            result = result(context=inst.context, name=self.__name__)
        if result == _EMPTY:
            return get_default_from_schema(inst.context, inst.schema,
                                           self.__name__)
        return result
Ejemplo n.º 3
0
    def __getattr__(self, name):
        if name not in self.__dict__["schema"]:
            return super(AnnotationBehavior, self).__getattr__(name)

        key_name = self.__dict__["prefix"] + name
        data = self.__dict__["data"]

        if key_name not in data:
            return get_default_from_schema(
                self, self.__dict__["schema"], name, self.__dict__["schema"][name].missing_value
            )

        return data[key_name]
Ejemplo n.º 4
0
    def __getattr__(self, name):
        # python basics:  __getattr__ is only invoked if the attribute wasn't
        # found by __getattribute__
        #
        # optimization: sometimes we're asked for special attributes
        # such as __conform__ that we can disregard (because we
        # wouldn't be in here if the class had such an attribute
        # defined).
        # also handle special dynamic providedBy cache here.
        # also handle the get_current_request call
        if name.startswith("__") or name == "_v__providedBy__" or name == "request":
            raise AttributeError(name)

        # attribute was not found; try to look it up in the schema and return
        # a default
        value = get_default_from_schema(
            self, SCHEMA_CACHE.get(self.type_name, {}).get("schema"), name, _marker
        )
        if value is not _marker:
            setattr(self, name, value)
            return value
        raise AttributeError(name)