summaryrefslogtreecommitdiff
path: root/python/skytools/quoting.py
diff options
context:
space:
mode:
authorMarko Kreen2010-11-25 12:03:52 +0000
committerMarko Kreen2010-11-25 12:03:52 +0000
commit2c219ec87ee729c9ed21ad3b7234e8349893fbf5 (patch)
treef3126a34eec64fc1553f4955524090e0779c5598 /python/skytools/quoting.py
parent2b5c465ded44790233eade6dd3538c5b6a981389 (diff)
skytools.unquote_(fq)ident: tests, relax fq
unquote_fqident does not require both parts anymore
Diffstat (limited to 'python/skytools/quoting.py')
-rw-r--r--python/skytools/quoting.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/python/skytools/quoting.py b/python/skytools/quoting.py
index e46f42dd..b143ee2b 100644
--- a/python/skytools/quoting.py
+++ b/python/skytools/quoting.py
@@ -133,18 +133,29 @@ def unescape_copy(val):
return unescape(val)
def unquote_ident(val):
- """Unquotes possibly quoted SQL identifier."""
+ """Unquotes possibly quoted SQL identifier.
+
+ >>> unquote_ident('foo')
+ 'foo'
+ >>> unquote_ident('"Wei "" rd"')
+ 'Wei " rd'
+ """
if val[0] == '"' and val[-1] == '"':
return val[1:-1].replace('""', '"')
+ if val.find('"') > 0:
+ raise Exception('unsupported syntax')
return val
def unquote_fqident(val):
"""Unquotes fully-qualified possibly quoted SQL identifier.
- It must be prefixed schema, which does not contain dots.
+ >>> unquote_fqident('foo')
+ 'foo'
+ >>> unquote_fqident('"Foo"."Bar "" z"')
+ 'Foo.Bar " z'
"""
tmp = val.split('.', 1)
- return "%s.%s" % (unquote_ident(tmp[0]), unquote_ident(tmp[1]))
+ return '.'.join([unquote_ident(i) for i in tmp])
# accept simplejson or py2.6+ json module
# search for simplejson first as there exists