def attrAction(self, item): name, value, action = item[:3] if action == 'insert': return () macs = self.macroStack if action == 'metal' and self.metal and macs: # Drop all METAL attributes at a use-depth beyond the first # use-macro and its extensions if len(macs) > 1: for macro in macs[1:]: if not macro.extending: return () if not macs[-1].entering: return () macs[-1].entering = False # Convert or drop depth-one METAL attributes. i = name.rfind(":") + 1 prefix, suffix = name[:i], name[i:] if suffix == "define-macro": # Convert define-macro as we enter depth one. useName = macs[0].macroName defName = macs[0].definingName res = [] if defName: res.append('%sdefine-macro=%s' % (prefix, quote(defName))) if useName: res.append('%suse-macro=%s' % (prefix, quote(useName))) return res elif suffix == "define-slot": name = prefix + "fill-slot" elif suffix == "fill-slot": pass else: return () if value is None: value = name else: value = "%s=%s" % (name, quote(value)) return [value]
def attrAction_tal(self, item): name, value, action = item[:3] ok = 1 expr, xlat, msgid = item[3:] if self.html and name.lower() in BOOLEAN_HTML_ATTRS: evalue = self.engine.evaluateBoolean(item[3]) if evalue is self.Default: if action == 'insert': # Cancelled insert ok = 0 elif evalue: value = None else: ok = 0 elif expr is not None: evalue = self.engine.evaluateText(item[3]) if evalue is self.Default: if action == 'insert': # Cancelled insert ok = 0 else: if evalue is None: ok = 0 value = evalue if ok: if xlat: translated = self.translate(msgid or value, value) if translated is not None: value = translated elif isinstance(value, I18nMessageTypes): translated = self.translate(value) if translated is not None: value = translated if value is None: value = name return ["%s=%s" % (name, quote(value))] else: return ()