diff options
author | Martin Pihlak | 2009-11-06 08:57:06 +0000 |
---|---|---|
committer | Martin Pihlak | 2009-11-06 08:57:06 +0000 |
commit | d7db381ed4365848e7fefdfbee2ffa7f99da4903 (patch) | |
tree | 4d3c09ef2029cbd92c86eee45eab55dc291b604e /python/skytools/quoting.py | |
parent | 0f31618dc5b868123f278efb37ce1064ef4675b2 (diff) | |
parent | 661a2e367246d3915c387679c13f6e56aade9c82 (diff) |
Merge branch 'master' of git://github.com/markokr/skytools-dev
Diffstat (limited to 'python/skytools/quoting.py')
-rw-r--r-- | python/skytools/quoting.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/python/skytools/quoting.py b/python/skytools/quoting.py index ce860040..e83d2495 100644 --- a/python/skytools/quoting.py +++ b/python/skytools/quoting.py @@ -82,8 +82,17 @@ def quote_fqident(s): The '.' is taken as namespace separator and all parts are quoted separately + + Example: + >>> quote_fqident('tbl') + 'public.tbl' + >>> quote_fqident('Baz.Foo.Bar') + '"Baz"."Foo.Bar"' """ - return '.'.join(map(quote_ident, s.split('.', 1))) + tmp = s.split('.', 1) + if len(tmp) == 1: + return 'public.' + quote_ident(s) + return '.'.join(map(quote_ident, tmp)) # # quoting for JSON strings @@ -110,7 +119,14 @@ def quote_json(s): return '"%s"' % _jsre.sub(_json_quote_char, s) def unescape_copy(val): - """Removes C-style escapes, also converts "\N" to None.""" + r"""Removes C-style escapes, also converts "\N" to None. + + Example: + >>> unescape_copy(r'baz\tfo\'o') + "baz\tfo'o" + >>> unescape_copy(r'\N') is None + True + """ if val == r"\N": return None return unescape(val) @@ -129,3 +145,6 @@ def unquote_fqident(val): tmp = val.split('.', 1) return "%s.%s" % (unquote_ident(tmp[0]), unquote_ident(tmp[1])) +if __name__ == '__main__': + import doctest + doctest.testmod() |