本文整理汇总了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"])