diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-06-26 03:11:32 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-06-26 03:11:32 +0000 |
| commit | 915001ad0bd61600781d58ead798c8cae6e5cd25 (patch) | |
| tree | b2fa17fa3b7350eac1252dba19dbb1d880618869 /django/utils/datastructures.py | |
| parent | 002dbd16b4453fc9c89533002ab17189a8122e70 (diff) | |
Fixed #7109 -- Quote certain values before passing them for substitution in
Field.db_type().
This fixes a problem with using reserved words for field names in Oracle. Only
affects Oracle at the moment, but the same changes could easily be used by
other backends if they are required (requires changing creation.py, only).
This commit also reverts [7501] so that if the fix doesn't work, it will show
up in the tests (and if it does work, the tests will prevent us from breaking
it again).
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7743 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/datastructures.py')
| -rw-r--r-- | django/utils/datastructures.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index 4c278c0d8e..21a72f2d1e 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -343,3 +343,34 @@ class FileDict(dict): d = dict(self, content='<omitted>') return dict.__repr__(d) return dict.__repr__(self) + +class DictWrapper(dict): + """ + Wraps accesses to a dictionary so that certain values (those starting with + the specified prefix) are passed through a function before being returned. + The prefix is removed before looking up the real value. + + Used by the SQL construction code to ensure that values are correctly + quoted before being used. + """ + def __init__(self, data, func, prefix): + super(DictWrapper, self).__init__(data) + self.func = func + self.prefix = prefix + + def __getitem__(self, key): + """ + Retrieves the real value after stripping the prefix string (if + present). If the prefix is present, pass the value through self.func + before returning, otherwise return the raw value. + """ + if key.startswith(self.prefix): + use_func = True + key = key[len(self.prefix):] + else: + use_func = False + value = super(DictWrapper, self).__getitem__(key) + if use_func: + return self.func(value) + return value + |
