Esempio n. 1
0
 def getUriGroups(self, name, strict=None):
     groups = TaurusAttributeNameValidator.getUriGroups(self, name, strict)
     if groups is not None:
         if groups.get('arch_db', None) is not None:
             # add devname to the groups
             groups['devname'] = '?db={arch_db}'.format(**groups)
     return groups
Esempio n. 2
0
    def getModelMimeData(self):
        """ Used for drag events """

        model,mimeData = '',None
        try:
            #model = getattr(self.scene().itemAt(*self.mousePos),'_name','')
            selected = self.scene()._selectedItems
            if not selected:
                self.debug('jdrawView.getModelMimeData(%s): nothing to drag'%model)
                return
            model = getattr(([s for s in selected if getattr(s,'_name','')] or [selected])[0],'_name','')
            self.debug('getModelMimeData(%s)'%model)
            mimeData = Qt.QMimeData()
            if model:
                # self.debug('getMimeData(): DeviceModel at %s: %s',self.mousePos,model)
                mimeData.setText(model)
                mimeData.setData(TAURUS_MODEL_MIME_TYPE, model)
                if TaurusDeviceNameValidator().getParams(model):
                    self.debug('getMimeData(): DeviceModel at %s: %s',self.mousePos,model)
                    mimeData.setData(TAURUS_DEV_MIME_TYPE,model)
                elif TaurusAttributeNameValidator().getParams(model):
                    self.debug('getMimeData(): AttributeModel at %s: %s',self.mousePos,model)
                    mimeData.setData(TAURUS_ATTR_MIME_TYPE,model)
                    mimeData.setData(TAURUS_DEV_MIME_TYPE,model.rsplit('/',1)[0])
                else:
                    self.debug('getMimeData(): UnknownModel at %s: %s',self.mousePos,model)
        except:
            self.debug('jdrawView.getModelMimeData(%s): unable to get MimeData'%model)
            self.debug(traceback.format_exc())
        return mimeData
Esempio n. 3
0
 def getUriGroups(self, name, strict=None):
     '''Reimplementation of getUriGroups to fix the host and authority
     name using fully qualified domain name for the host.
     '''
     ret = TaurusAttributeNameValidator.getUriGroups(self, name, strict)
     if ret is not None and ret.get("host", None) is not None:
         fqdn = fqdn_no_alias(ret["host"])
         ret["host"] = fqdn
         ret["authority"] = "//{host}:{port}".format(**ret)
     return ret
Esempio n. 4
0
    def getUriGroups(self, name, strict=None):
        '''reimplemented from :class:`TaurusAttributeNameValidator` to provide
        backwards compatibility with old syntax'''

        # mangle refs before matching the pattern to sanitize them
        refs = self.getRefs(name, ign_quoted=False)
        refs_dict = {}
        _name = name
        for i, ref in enumerate(refs):
            refs_dict['__EVALREF_%d__' % i] = '{%s}' % ref
            _name = _name.replace('{%s}' % ref, '{__EVALREF_%d__}' % i, 1)

        _groups = TaurusAttributeNameValidator.getUriGroups(self,
                                                            _name,
                                                            strict=strict)
        if _groups is None:
            return None

        # create the groups dict with unmangled refs in its values
        groups = {}
        for n, g in _groups.items():
            if isinstance(g, str):  # avoid None or boolean values
                g = g.format(**refs_dict)
            groups[n] = g

        if not groups['__STRICT__']:
            # adapt attrname to what would be in strict mode
            _subst = groups['_subst'] or ''
            _expr = groups['_expr']
            if _subst:
                groups['attrname'] = "%s;%s" % (_subst.rstrip(';'), _expr)
            else:
                groups['attrname'] = _expr

            # adapt devname to what would be in strict mode
            old_devname = groups['_old_devname']
            if old_devname is None:
                groups['devname'] = None
            else:
                groups['devname'] = '@%s' % old_devname

        # check that there are not ";" in the expr (ign. quoted text and refs)
        sanitized_expr = QUOTED_TEXT_RE.sub('', groups['_expr'])
        for ref in self.getRefs(sanitized_expr, ign_quoted=False):
            sanitized_expr = sanitized_expr.replace(ref, '')
        if ";" in sanitized_expr:
            return None

        # add a group containing refs in attrname (ign. those in quoted text)
        groups['_evalrefs'] = self.getRefs(groups['attrname'], ign_quoted=True)

        return groups
Esempio n. 5
0
    def getUriGroups(self, name, strict=None):
        '''reimplemented from :class:`TaurusAttributeNameValidator` to provide
        backwards compatibility with old syntax'''

        # mangle refs before matching the pattern to sanitize them
        refs = self.getRefs(name, ign_quoted=False)
        refs_dict = {}
        _name = name
        for i, ref in enumerate(refs):
            refs_dict['__EVALREF_%d__' % i] = '{%s}' % ref
            _name = _name.replace('{%s}' % ref, '{__EVALREF_%d__}' % i, 1)

        _groups = TaurusAttributeNameValidator.getUriGroups(self, _name,
                                                            strict=strict)
        if _groups is None:
            return None

        # create the groups dict with unmangled refs in its values
        groups = {}
        for n, g in _groups.items():
            if isinstance(g, str):  # avoid None or boolean values
                g = g.format(**refs_dict)
            groups[n] = g

        if not groups['__STRICT__']:
            # adapt attrname to what would be in strict mode
            _subst = groups['_subst'] or ''
            _expr = groups['_expr']
            if _subst:
                groups['attrname'] = "%s;%s" % (_subst.rstrip(';'), _expr)
            else:
                groups['attrname'] = _expr

            # adapt devname to what would be in strict mode
            old_devname = groups['_old_devname']
            if old_devname is None:
                groups['devname'] = None
            else:
                groups['devname'] = '@%s' % old_devname

        # check that there are not ";" in the expr (ign. quoted text and refs)
        sanitized_expr = QUOTED_TEXT_RE.sub('', groups['_expr'])
        for ref in self.getRefs(sanitized_expr, ign_quoted=False):
            sanitized_expr = sanitized_expr.replace(ref, '')
        if ";" in sanitized_expr:
            return None

        # add a group containing refs in attrname (ign. those in quoted text)
        groups['_evalrefs'] = self.getRefs(groups['attrname'], ign_quoted=True)

        return groups
Esempio n. 6
0
    def _getKey(self, name):

        if self._elementType == TaurusElementType.Attribute:
            g = TaurusAttributeNameValidator.getUriGroups(self, name)
        elif self._elementType == TaurusElementType.Device:
            g = TaurusDeviceNameValidator.getUriGroups(self, name)
        elif self._elementType == TaurusElementType.Authority:
            g = TaurusAuthorityNameValidator.getUriGroups(self, name)
        else:
            msg = '_elementType must be one of (Authority, Device, Attribute)'
            raise Exception(msg)
        if g is None:
            return None
        else:
            return g['_resname']
Esempio n. 7
0
    def _getKey(self, name):

        if self._elementType == TaurusElementType.Attribute:
            g = TaurusAttributeNameValidator.getUriGroups(self, name)
        elif self._elementType == TaurusElementType.Device:
            g = TaurusDeviceNameValidator.getUriGroups(self, name)
        elif self._elementType == TaurusElementType.Authority:
            g = TaurusAuthorityNameValidator.getUriGroups(self, name)
        else:
            msg = '_elementType must be one of (Authority, Device, Attribute)'
            raise Exception(msg)
        if g is None:
            return None
        else:
            return g['_resname']
Esempio n. 8
0
    def getUriGroups(self, name, strict=None):
        """reimplemented from :class:`TaurusAttributeNameValidator`."""
        groups = TaurusAttributeNameValidator.getUriGroups(self, name, strict)

        if groups is None:
            return None

        attrname = groups.get('attrname')
        if attrname is None:
            return None

        if attrname != '':
            try:
                import ast
                ast.literal_eval(attrname)
            except:
                return None
        return groups