Example #1
0
    def __call__(self, path, target, normalizer, **data):
        assert isinstance(path, deque), 'Invalid path %s' % path
        assert isinstance(normalizer,
                          Normalizer), 'Invalid normalizer %s' % normalizer

        if not path: return False

        key = path.popleft()
        if not isinstance(key, str): return False
        assert isinstance(key, str), 'Invalid path element %s' % key

        if path and normalizer.normalize(self.name) == key:
            key = path.popleft()
            if not isinstance(key, str): return False

        if self.getter is not None: target = self.getter(target)

        for keyProp, decodeProp in self.properties.items():
            assert isinstance(keyProp,
                              str), 'Invalid property key %s' % keyProp
            if normalizer.normalize(keyProp) == key: break
        else: return False
        try:
            return decodeProp(path=path,
                              target=target,
                              normalizer=normalizer,
                              **data)
        except InputError:
            raise
        except:
            handleExploitError(decodeProp)
Example #2
0
    def __call__(self, value, render, normalizer, encoderPath, name=None, dataModel=None, fetcher=None, **data):
        assert isinstance(render, IRender), 'Invalid render %s' % render
        assert isinstance(normalizer, Normalizer), 'Invalid normalizer %s' % normalizer
        assert isinstance(encoderPath, IEncoderPath), 'Invalid encoder path %s' % encoderPath
        assert name is None or isinstance(name, str), 'Invalid name %s' % name

        if dataModel is None: return super().__call__(value, render, normalizer, name, **data)
        assert isinstance(dataModel, DataModel), 'Invalid data model %s' % dataModel

        if self.getter: value = self.getter(value)
        if value is None: return

        data.update(render=render, normalizer=normalizer, encoderPath=encoderPath)

        attrs = None
        if fetcher:
            assert isinstance(fetcher, IFetcher), 'Invalid fetcher %s' % fetcher
            data.update(fetcher=fetcher)
            if dataModel.fetchEncode and dataModel.fetchReference:
                valueModel = fetcher.fetch(dataModel.fetchReference, value)
                if valueModel is not None:
                    return dataModel.fetchEncode(value=valueModel, name=name, dataModel=dataModel.fetchData, **data)
                attrs = {normalizer.normalize(self.encoder.nameXFilter): self.encoder.valueDenied}

        data.update(value=value)  # Here we actually also update the accessible paths.
        if DataModel.modelPaths in dataModel:
            # We update the model paths with the currently encoded model
            self._updateModelPaths(dataModel.modelPaths, value)

        if not dataModel.flag & NO_MODEL_PATH and dataModel.path and dataModel.path.isValid():
            assert isinstance(dataModel.path, Path), 'Invalid path model %s' % dataModel.path
            if attrs is None: attrs = {}
            attrs[normalizer.normalize(self.encoder.nameRef)] = encoderPath.encode(dataModel.path)

        render.objectStart(normalizer.normalize(name or self.name), attrs)

        for nameProp, encodeProp in self.properties.items():
            if DataModel.filter in dataModel and nameProp not in dataModel.filter: continue
            if DataModel.datas in dataModel: data.update(dataModel=dataModel.datas.get(nameProp))
            try: encodeProp(name=nameProp, **data)
            except: handleExploitError(encodeProp)

        # The accessible paths are already updated when the model path is updated.
        if DataModel.accessible in dataModel:
            for namePath, path in dataModel.accessible.items():
                if not path.isValid(): continue
                if DataModel.filter in dataModel and namePath not in dataModel.filter: continue
                attrs = {normalizer.normalize(self.encoder.nameRef):encoderPath.encode(path)}
                render.objectStart(normalizer.normalize(namePath), attrs)
                render.objectEnd()

        render.objectEnd()
Example #3
0
    def __call__(self, value, render, normalizer, encoderPath, name=None, dataModel=None, fetcher=None, **data):
        assert isinstance(render, IRender), 'Invalid render %s' % render
        assert isinstance(normalizer, Normalizer), 'Invalid normalizer %s' % normalizer
        assert isinstance(encoderPath, IEncoderPath), 'Invalid encoder path %s' % encoderPath
        assert name is None or isinstance(name, str), 'Invalid name %s' % name

        if dataModel is None: return super().__call__(value, render, normalizer, name, **data)
        assert isinstance(dataModel, DataModel), 'Invalid data model %s' % dataModel

        if self.getter: value = self.getter(value)
        if value is None: return

        data.update(render=render, normalizer=normalizer, encoderPath=encoderPath)

        attrs = None
        if fetcher:
            assert isinstance(fetcher, IFetcher), 'Invalid fetcher %s' % fetcher
            data.update(fetcher=fetcher)
            if dataModel.fetchEncode and dataModel.fetchReference:
                valueModel = fetcher.fetch(dataModel.fetchReference, value)
                if valueModel is not None:
                    return dataModel.fetchEncode(value=valueModel, name=name, dataModel=dataModel.fetchData, **data)
                attrs = {normalizer.normalize(self.encoder.nameXFilter): self.encoder.valueDenied}

        data.update(value=value)  # Here we actually also update the accessible paths.
        if DataModel.modelPaths in dataModel:
            # We update the model paths with the currently encoded model
            self._updateModelPaths(dataModel.modelPaths, value)

        if not dataModel.flag & NO_MODEL_PATH and dataModel.path and dataModel.path.isValid():
            assert isinstance(dataModel.path, Path), 'Invalid path model %s' % dataModel.path
            if attrs is None: attrs = {}
            attrs[normalizer.normalize(self.encoder.nameRef)] = encoderPath.encode(dataModel.path)

        render.objectStart(normalizer.normalize(name or self.name), attrs)

        for nameProp, encodeProp in self.properties.items():
            if DataModel.filter in dataModel and nameProp not in dataModel.filter: continue
            if DataModel.datas in dataModel: data.update(dataModel=dataModel.datas.get(nameProp))
            try: encodeProp(name=nameProp, **data)
            except: handleExploitError(encodeProp)

        # The accessible paths are already updated when the model path is updated.
        if DataModel.accessible in dataModel:
            for namePath, path in dataModel.accessible.items():
                if not path.isValid(): continue
                if DataModel.filter in dataModel and namePath not in dataModel.filter: continue
                attrs = {normalizer.normalize(self.encoder.nameRef):encoderPath.encode(path)}
                render.objectStart(normalizer.normalize(namePath), attrs)
                render.objectEnd()

        render.objectEnd()
Example #4
0
    def __call__(self, value, render, normalizer, name=None, **data):
        assert isinstance(normalizer, Normalizer), 'Invalid normalizer %s' % normalizer
        assert isinstance(render, IRender), 'Invalid render %s' % render
        assert name is None or isinstance(name, str), 'Invalid name %s' % name

        if self.getter: value = self.getter(value)
        if value is None: return

        render.objectStart(normalizer.normalize(name or self.name))
        data.update(value=value, render=render, normalizer=normalizer)
        for nameProp, encodeProp in self.properties.items():
            try: encodeProp(name=nameProp, **data)
            except: handleExploitError(encodeProp)
        render.objectEnd()
Example #5
0
    def __call__(self, value, render, normalizer, name=None, **data):
        assert isinstance(normalizer, Normalizer), 'Invalid normalizer %s' % normalizer
        assert isinstance(render, IRender), 'Invalid render %s' % render
        assert name is None or isinstance(name, str), 'Invalid name %s' % name

        if self.getter: value = self.getter(value)
        if value is None: return

        render.objectStart(normalizer.normalize(name or self.name))
        data.update(value=value, render=render, normalizer=normalizer)
        for nameProp, encodeProp in self.properties.items():
            try: encodeProp(name=nameProp, **data)
            except: handleExploitError(encodeProp)
        render.objectEnd()
Example #6
0
    def __call__(self, path, target, normalizer, **data):
        assert isinstance(path, deque), 'Invalid path %s' % path
        assert isinstance(normalizer, Normalizer), 'Invalid normalizer %s' % normalizer

        if not path: return False

        key = path.popleft()
        if not isinstance(key, str): return False
        assert isinstance(key, str), 'Invalid path element %s' % key

        if path and normalizer.normalize(self.name) == key:
            key = path.popleft()
            if not isinstance(key, str): return False

        if self.getter is not None: target = self.getter(target)

        for keyProp, decodeProp in self.properties.items():
            assert isinstance(keyProp, str), 'Invalid property key %s' % keyProp
            if normalizer.normalize(keyProp) == key: break
        else: return False
        try: return decodeProp(path=path, target=target, normalizer=normalizer, **data)
        except InputError: raise
        except: handleExploitError(decodeProp)