Ejemplo n.º 1
0
    def processAccessible(self, encode, data):
        '''
        Process the accessible paths for the provided data.
        '''
        assert isinstance(encode, EncodeModel), 'Invalid encode model %s' % encode
        assert isinstance(data, DataModel), 'Invalid data model %s' % data

        if data.accessibleIsProcessed: return
        data.accessibleIsProcessed = True
        if data.accessiblePath is None: return
        assert isinstance(data.accessiblePath, Path), 'Invalid path %s' % data.accessiblePath

        #TODO: Make sure when placing the accessible paths that there isn't already an accessible path
        # that already returns the inherited model see the example for MetaData and ImageData in relation
        # with MetaInfo and ImageInfo
        accessible = list(findGetAllAccessible(data.accessiblePath))
        # These paths will get updated in the encode model when the data model path is updated
        # because they are extended from the base path.
        assert isinstance(encode.modelType, TypeModel)
        for parentType in encode.modelType.parents():
            parentPath = findGetModel(data.accessiblePath, parentType)
            if parentPath:
                accessiblePaths = findGetAllAccessible(parentPath)
                if accessiblePaths:
                    data.modelPaths[parentType] = parentPath
                    accessible.extend(accessiblePaths)

        if accessible:
            data.accessible = OrderedDict()
            for acc in accessible:
                pathName = pathLongName(acc)
                if pathName not in data.accessible: data.accessible[pathName] = acc
Ejemplo n.º 2
0
    def processAccessible(self, encode, data):
        '''
        Process the accessible paths for the provided data.
        '''
        assert isinstance(encode, EncodeModel), 'Invalid encode model %s' % encode
        assert isinstance(data, DataModel), 'Invalid data model %s' % data

        if data.accessibleIsProcessed: return
        data.accessibleIsProcessed = True
        if data.accessiblePath is None: return
        assert isinstance(data.accessiblePath, Path), 'Invalid path %s' % data.accessiblePath

        # TODO: Make sure when placing the accessible paths that there isn't already an accessible path
        # that already returns the inherited model see the example for MetaData and ImageData in relation
        # with MetaInfo and ImageInfo
        accessible = list(findGetAllAccessible(data.accessiblePath))
        # These paths will get updated in the encode model when the data model path is updated
        # because they are extended from the base path.
        assert isinstance(encode.modelType, TypeModel)
        for parentType in encode.modelType.parents():
            parentPath = findGetModel(data.accessiblePath, parentType)
            if parentPath:
                accessiblePaths = findGetAllAccessible(parentPath)
                if accessiblePaths:
                    data.modelPaths[parentType] = parentPath
                    accessible.extend(accessiblePaths)

        if accessible:
            data.accessible = OrderedDict()
            for acc in accessible:
                pathName = pathLongName(acc)
                if pathName not in data.accessible: data.accessible[pathName] = acc
Ejemplo n.º 3
0
    def processAccessible(self, data):
        '''
        Process the accessible paths for the provided data.
        '''
        assert isinstance(data, DataModel), 'Invalid data model %s' % data

        if data.accessibleIsProcessed: return
        data.accessibleIsProcessed = True
        if data.accessiblePath is None: return
        assert isinstance(data.accessiblePath, Path), 'Invalid path %s' % data.accessiblePath

        accessible = data.accessiblePath.findGetAllAccessible()
        if accessible:
            accessible = [(pathLongName(acc), acc) for acc in accessible]
            accessible.sort(key=firstOf)
            data.accessible = OrderedDict(accessible)
Ejemplo n.º 4
0
    def __call__(self, value, render, normalizer, encoderPath, name=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

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

        if isinstance(value, Path):
            assert isinstance(value, Path)
            if not value.isValid(): return
            name = name or normalizer.normalize(pathLongName(value))
        else:
            assert isinstance(value, str), 'Invalid path %s' % value
        assert isinstance(name, str), 'Invalid name %s' % name

        attrs = {normalizer.normalize(self.nameRef):encoderPath.encode(value)}
        render.objectStart(name, attrs)
        render.objectEnd()
Ejemplo n.º 5
0
    def __call__(self, value, render, normalizer, encoderPath, name=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

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

        if isinstance(value, Path):
            assert isinstance(value, Path)
            if not value.isValid(): return
            name = name or normalizer.normalize(pathLongName(value))
        else:
            assert isinstance(value, str), 'Invalid path %s' % value
        assert isinstance(name, str), 'Invalid name %s' % name

        attrs = {normalizer.normalize(self.nameRef):encoderPath.encode(value)}
        render.objectStart(name, attrs)
        render.objectEnd()
Ejemplo n.º 6
0
    def createDataModel(self, encode, path, showAccessible):
        '''
        Create the data model for the provided encode model.
        '''
        assert isinstance(encode, EncodeModel), 'Invalid encode model %s' % encode

        data = DataModel()
        if path:
            assert isinstance(path, Path), 'Invalid request path %s' % path
            data.path = path.findGetModel(encode.modelType)
            if showAccessible:
                accessible = path.findGetAllAccessible()
                if accessible:
                    accessible = [(pathLongName(acc), acc) for acc in accessible]
                    accessible.sort(key=firstOf)
                    data.accessible = OrderedDict(accessible)

        for nameProp, encodeProp in encode.properties.items():
            if isinstance(encodeProp, EncodeModel):
                assert isinstance(encodeProp, EncodeModel)
                data.datas[nameProp] = self.createDataModel(encodeProp, path.findGetModel(encodeProp.modelType), False)

        return data