diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-01-01 02:30:46 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-01-01 02:30:46 +0200 |
commit | 0455931755ea14fef45d4702a0a9ba2af9531de5 (patch) | |
tree | 0b5a67d2eb9531ccfb4b28a0a29cdd24be475c47 | |
parent | bed21e8e6fd044b53cc762f81dc2a0ca1c974afe (diff) | |
download | summain-0455931755ea14fef45d4702a0a9ba2af9531de5.tar.gz |
Make FilesystemObject handle names that require URL
quoting by URL quoting everything. Implement this by
having a hook for each key (named 'hook_foo' for key
'foo') which gets called automatically if the key
exists.
-rw-r--r-- | summainlib.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/summainlib.py b/summainlib.py index b0d9782..81cc973 100644 --- a/summainlib.py +++ b/summainlib.py @@ -14,6 +14,9 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. +import urllib + + class FilesystemObject(object): '''An object in the file system. @@ -27,7 +30,13 @@ class FilesystemObject(object): self.values = dict() self['Name'] = filename + def hook_name(self, value): + return urllib.quote(value) + def __setitem__(self, key, value): + hook_name = 'hook_%s' % key.lower() + if hasattr(self, hook_name): + value = getattr(self, hook_name)(value) self.values[key] = value def __getitem__(self, key): |