def init(self, variants, descriptions=None): """ Add the variant list :Parameters: - `variants`: The variant URLs - `descriptions`: variant descriptions, the url is the key :Types: - `variants`: ``iterable`` - `descriptions`: ``dict`` :return: Tuple of unescaped and escaped parameters (``(dict, dict)``) :rtype: ``tuple`` """ if descriptions is None: descriptions = {} variants_esc = '\n'.join( '<li><a href="%(var)s">%(var)s</a>%(desc)s</li>' % dict( var=_webutil.escape_html(var), desc=descriptions.get(var) and (", " + _webutil.escape_html(descriptions[var])) or "", ) for var in variants) return ( dict(variants=variants, descriptions=descriptions), dict(variants=variants_esc, descriptions="") )
def init(self, desc=None): """ Optionally add a error description :Parameters: - `desc`: Optional error description :Types: - `desc`: ``str`` :return: Tuple of unescaped and escaped parameters (``(dict, dict)``) :rtype: ``tuple`` """ desc_esc = desc and _webutil.escape_html(desc) or "" return dict(desc=desc), dict(desc=desc_esc)
def init(self, admin=None): """ Add optional admin address :Parameters: - `admin`: The optional admin contact address :Types: - `admin`: ``str`` :return: Tuple of unescaped and escaped parameters (``(dict, dict)``) :rtype: ``tuple`` """ admin_esc = admin and (" " + _webutil.escape_html(admin)) or "" return dict(admin=admin), dict(admin=admin_esc)
def init(self, tokens): """ Add upgrade tokens :Parameters: - `tokens`: List of upgrade tokens to advertise :Types: - `tokens`: ``iterable`` :return: Tuple of unescaped and escaped parameters (``(dict, dict)``) :rtype: ``tuple`` """ tokens_esc = _webutil.escape_html(", ".join(tokens)) return dict(tokens=tokens), dict(tokens=tokens_esc)
def init(self, desc=None): """ Add optional description :Parameters: - `desc`: Optional additional description :Types: - `desc`: ``str`` :return: Tuple of unescaped and escaped parameters (``(dict, dict)``) :rtype: ``tuple`` """ desc_esc = desc and ("<br>\n" + _webutil.escape_html(desc)) or "" return dict(desc=desc), dict(desc=desc_esc)
def init(self, hint=None): """ Add an error hint :Parameters: - `hint`: Optional hint describing the error (unescaped HTML) :Types: - `hint`: ``str`` :return: Tuple of unescaped and escaped parameters (``(dict, dict)``) :rtype: ``tuple`` """ hint_esc = hint and _webutil.escape_html(hint) or "" return dict(hint=hint), dict(hint=hint_esc)
def init(self, variants): """ Add list of variants :Parameters: - `variants`: List of choosable variants (``('uri', ...)``) :Types: - `variants`: ``iterable`` :return: Tuple of unescaped and escaped parameters (``(dict, dict)``) :rtype: ``tuple`` """ variantlist = "\n".join("<li>%(variant)s</li>" % _webutil.escape_html(variant) for variant in variants) return dict(variants=variants), dict(variants=variantlist)
def init(self, allowed): """ Add the allowed method list :Parameters: - `allowed`: List of allowed methods (``('method', ...)``) :Types: - `allowed`: ``iterable`` :return: Tuple of unescaped and escaped parameters (``(dict, dict)``) :rtype: ``tuple`` """ allowed = list(sorted(set(allowed))) allowed_esc = '\n'.join("<li>%s</li>" % _webutil.escape_html(method) for method in allowed) return dict(allowed=allowed), dict(allowed=allowed_esc)
def body(self): """ Compute the response body :return: The response body :rtype: ``str`` """ if self.message is None: return "" elif not self._replace: return self.message param = dict(self.param) param.update({'status': str(self.status), 'reason': str(self.reason)}) param = dict((key, _webutil.escape_html(str(val))) for key, val in param.iteritems()) param.update(self._escaped) return self.message % param
def init(self, location, additional=()): """ Add main location and (optional) less significant URIs :Parameters: - `location`: Main location of the created resource - `additional`: List of additional (less significant) locations (``('uri', ...)``) :Types: - `location`: ``str`` - `additional`: ``iterable`` :return: Tuple of unescaped and escaped parameters (``(dict, dict)``) :rtype: ``tuple`` """ urilist = "\n".join("<li><a href=\"%(uri)s\">%(uri)s</a></li>" % _webutil.escape_html(uri) for uri in additional) return dict(location=location, uris=additional), dict(uris=urilist)