Python sqlalchemy.sql.compiler.IdentifierPreparer() Examples
The following are 2
code examples of sqlalchemy.sql.compiler.IdentifierPreparer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sqlalchemy.sql.compiler
, or try the search function
.
Example #1
Source File: test_quote.py From sqlalchemy with MIT License | 6 votes |
def test_unformat(self): prep = compiler.IdentifierPreparer(default.DefaultDialect()) unformat = prep.unformat_identifiers def a_eq(have, want): if have != want: print("Wanted %s" % want) print("Received %s" % have) self.assert_(have == want) a_eq(unformat("foo"), ["foo"]) a_eq(unformat('"foo"'), ["foo"]) a_eq(unformat("'foo'"), ["'foo'"]) a_eq(unformat("foo.bar"), ["foo", "bar"]) a_eq(unformat('"foo"."bar"'), ["foo", "bar"]) a_eq(unformat('foo."bar"'), ["foo", "bar"]) a_eq(unformat('"foo".bar'), ["foo", "bar"]) a_eq(unformat('"foo"."b""a""r"."baz"'), ["foo", 'b"a"r', "baz"])
Example #2
Source File: test_quote.py From sqlalchemy with MIT License | 5 votes |
def test_unformat_custom(self): class Custom(compiler.IdentifierPreparer): def __init__(self, dialect): super(Custom, self).__init__( dialect, initial_quote="`", final_quote="`" ) def _escape_identifier(self, value): return value.replace("`", "``") def _unescape_identifier(self, value): return value.replace("``", "`") prep = Custom(default.DefaultDialect()) unformat = prep.unformat_identifiers def a_eq(have, want): if have != want: print("Wanted %s" % want) print("Received %s" % have) self.assert_(have == want) a_eq(unformat("foo"), ["foo"]) a_eq(unformat("`foo`"), ["foo"]) a_eq(unformat(repr("foo")), ["'foo'"]) a_eq(unformat("foo.bar"), ["foo", "bar"]) a_eq(unformat("`foo`.`bar`"), ["foo", "bar"]) a_eq(unformat("foo.`bar`"), ["foo", "bar"]) a_eq(unformat("`foo`.bar"), ["foo", "bar"]) a_eq(unformat("`foo`.`b``a``r`.`baz`"), ["foo", "b`a`r", "baz"])