本文整理汇总了Python中lib.drupy.DrupyPHP.strtr方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.strtr方法的具体用法?Python DrupyPHP.strtr怎么用?Python DrupyPHP.strtr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.drupy.DrupyPHP
的用法示例。
在下文中一共展示了DrupyPHP.strtr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prefix_tables
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import strtr [as 别名]
def prefix_tables(sql):
"""
Append a database prefix to all tables in a query.
Queries sent to Drupal should wrap all table names in curly brackets. This
function searches for this syntax and adds Drupal's table prefix to all
tables, allowing Drupal to coexist with other systems in the same
database if necessary.
@param sql
A string containing a partial or entire SQL query.
@return
The properly-prefixed string.
"""
if (php.is_array(settings.db_prefix)):
if (php.array_key_exists('default', settings.db_prefix)):
tmp = settings.db_prefix;
del(tmp['default']);
for key,val in tmp.items():
sql = php.strtr(sql, {('{' + key + '}') : (val + key)});
return php.strtr(sql, {'{' : settings.db_prefix['default'], '}' : ''});
else:
for key,val in settings.db_prefix.items():
sql = php.strtr(sql, {('{' + key + '}') : (val + key)});
return php.strtr(sql, {'{' : '', '}' : ''});
else:
return php.strtr(sql, {'{' : settings.db_prefix, '}' : ''});