def linked_item(url, body, source=None, line=None, selector=None): """Creates a link, if we have a log context""" body = html_quote(body) if log is None or url is None: return body link = log.link_to(url, source=source, line=line, selector=selector) return '<a href="%s" target="_blank">%s</a>' % (html_quote(link), body)
def log_description(self, log=None): """ A text description of this rule, for use in log messages and errors """ def linked_item(url, body, source=None, line=None, selector=None): """Creates a link, if we have a log context""" body = html_quote(body) if log is None or url is None: return body link = log.link_to(url, source=source, line=line, selector=selector) return '<a href="%s" target="_blank">%s</a>' % (html_quote(link), body) if log: request_url = log.request.url else: request_url = None parts = ['<%s' % linked_item(self.source_location, self.name, source=True)] if getattr(self, 'content', None): body = 'content="%s"' % html_quote(self.content) if getattr(self, 'content_href', None): if request_url: content_url = urlparse.urljoin(request_url, self.content_href) else: content_url = self.content_href else: content_url = request_url parts.append(linked_item(content_url, body, selector=self.content)) if getattr(self, 'content_href', None): dest = self.content_href if request_url: dest = urlparse.urljoin(request_url, dest) body = 'href="%s"' % html_quote(self.content_href) parts.append(linked_item(dest, body, source=True)) if self.move_supported and not getattr(self, 'move', False): parts.append('move="0"') v = getattr(self, 'nocontent', 'warn') if v != 'warn': parts.append(self.format_error('nocontent', v)) v = getattr(self, 'manycontent', ('warn', None)) if v != ('warn', 'first'): parts.append(self.format_error('manycontent', v)) if getattr(self, 'theme', None): body = 'theme="%s"' % html_quote(self.theme) theme_url = getattr(log, 'theme_url', None) parts.append(linked_item(theme_url, body, selector=self.theme)) v = getattr(self, 'notheme', 'warn') if v != 'warn': parts.append(self.format_error('notheme', v)) v = getattr(self, 'manytheme', ('warn', None)) if v != ('warn', 'first'): parts.append(self.format_error('manytheme', v)) ## FIXME: add source_location return html(' '.join(parts) + ' />')
def __unicode__(self): assert self.element_name, ("You must set element_name in subclasses") parts = ['<%s' % self.element_name] parts.extend(self._uni_early_args()) for attr, value in [('path', self.path), ('domain', self.domain), ('request-header', self.request_header), ('response-header', self.response_header), ('response-status', self.response_status), ('environ', self.environ)]: if value: parts.append('%s="%s"' % (attr, html_quote(str(value)))) if self.pyref: parts.append(str(self.pyref)) parts.extend(self._uni_late_args()) parts.append('/>') return ' '.join(parts)
def __unicode__(self): assert self.element_name, ( "You must set element_name in subclasses") parts = [u'<%s' % self.element_name] parts.extend(self._uni_early_args()) for attr, value in [ ('path', self.path), ('domain', self.domain), ('request-header', self.request_header), ('response-header', self.response_header), ('environ', self.environ)]: if value: parts.append(u'%s="%s"' % (attr, html_quote(unicode(value)))) if self.pyref: parts.append(unicode(self.pyref)) parts.extend(self._uni_late_args()) parts.append(u'/>') return ' '.join(parts)
def format_error(self, attr, value): """ Takes the result of :meth:`convert_error` and serializes it back into ``attribute="value"`` """ if attr in ('manytheme', 'manycontent'): assert isinstance(value, tuple), ( "Unexpected value: %r (for attribute %s)" % ( value, attr)) if value == ('warn', 'first'): return None handler, pos = value if pos == 'last': text = '%s:%s' % (handler, pos) else: text = handler else: text = value if text == 'warn': return None return '%s="%s"' % (attr, html_quote(text))
def _uni_early_args(self): """Add the extra args <match> uses""" if self.classes: return ['class="%s"' % html_quote(' '.join(self.classes))] else: return []
def _uni_early_args(self): """Add the extra args <match> uses""" if self.classes: return [u'class="%s"' % html_quote(' '.join(self.classes))] else: return []