本文整理匯總了Python中sqlalchemy.sql.compiler.IdentifierPreparer方法的典型用法代碼示例。如果您正苦於以下問題:Python compiler.IdentifierPreparer方法的具體用法?Python compiler.IdentifierPreparer怎麽用?Python compiler.IdentifierPreparer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy.sql.compiler
的用法示例。
在下文中一共展示了compiler.IdentifierPreparer方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_unformat
# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import IdentifierPreparer [as 別名]
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"])
示例2: test_unformat_custom
# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import IdentifierPreparer [as 別名]
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"])