Mercurial > cgi-bin > hgweb.cgi > tincan
comparison tests/suite_12_methods/files/WEB-INF/lib/jsdict.py @ 71:88adf10be709 draft
Add tests.
author | David Barts <n5jrn@me.com> |
---|---|
date | Mon, 15 Jul 2019 13:16:31 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
70:a78c74c73d98 | 71:88adf10be709 |
---|---|
1 #!/usr/bin/env python3 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 class JSDict(dict): | |
5 """ | |
6 Make a dict that acts something like a JavaScript object, in that we can | |
7 use both x["name"] and x.name to access something. Note that the latter | |
8 method fails for keys like x["get"] that duplicate dict methods, and keys | |
9 like x["1"] which are not legal Python identifiers. | |
10 """ | |
11 def __getattr__(self, name): | |
12 return self[name] | |
13 | |
14 def __setattr__(self, name, value): | |
15 self[name] = value | |
16 | |
17 def __delattr__(self, name): | |
18 del self[name] | |
19 | |
20 @classmethod | |
21 def from_dict(cls, d): | |
22 return cls(d) |