Mercurial > p > roundup > code
diff roundup/cgi/templating.py @ 4878:f6e76a03b502
HTML* classes for cgi are now all new-style
Add regression test for old behaviour: Lookup of a value of a
HTMLProperty was possibly via getitem -- for old-style classes this
worked because __getattr__ returned the __getitem__ of a newly created
HTMLItem object, this does no longer work for new-style classes as these
look up special method only on the class not the instance.
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Sat, 29 Mar 2014 10:52:20 +0100 |
| parents | cdec6ed210d0 |
| children | 302c967d710c |
line wrap: on
line diff
--- a/roundup/cgi/templating.py Fri Mar 28 16:47:36 2014 +0100 +++ b/roundup/cgi/templating.py Sat Mar 29 10:52:20 2014 +0100 @@ -398,7 +398,7 @@ _set_input_default_args(attrs) return '<input %s/>'%cgi_escape_attrs(**attrs) -class HTMLInputMixin: +class HTMLInputMixin(object): """ requires a _client property """ def __init__(self): html_version = 'html4' @@ -421,7 +421,7 @@ _ = gettext -class HTMLPermissions: +class HTMLPermissions(object): def view_check(self): """ Raise the Unauthorised exception if the user's not permitted to @@ -1903,7 +1903,7 @@ return self.input(name=self._formname, value=value, size=size, **kwargs) -class LinkHTMLProperty(HTMLProperty, object): +class LinkHTMLProperty(HTMLProperty): """ Link HTMLProperty Include the above as well as being able to access the class information. Stringifying the object itself results in the value @@ -1912,9 +1912,6 @@ property accessed (so item/assignedto/name would look up the user entry identified by the assignedto property on item, and then the name property of that user) - - (Has been turned into a new-style class to enable comparisons - of values with None, see issue2550830.) """ def __init__(self, *args, **kw): HTMLProperty.__init__(self, *args, **kw) @@ -1936,6 +1933,14 @@ i = HTMLItem(self._client, self._prop.classname, self._value) return getattr(i, attr) + def __getitem__(self, item): + """Explicitly define __getitem__ -- this used to work earlier + due to __getattr__ returning the __getitem__ of HTMLItem -- this + lookup doesn't work for new-style classes. + """ + i = HTMLItem(self._client, self._prop.classname, self._value) + return i[item] + def plain(self, escape=0): """ Render a "plain" representation of the property """ @@ -3006,7 +3011,7 @@ res.append('</table></td></tr></table>') return "\n".join(res) -class MissingValue: +class MissingValue(object): def __init__(self, description, **kwargs): self.__description = description for key, value in kwargs.items():
