本文整理汇总了Python中lib.drupy.DrupyPHP.strrev方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.strrev方法的具体用法?Python DrupyPHP.strrev怎么用?Python DrupyPHP.strrev使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.drupy.DrupyPHP
的用法示例。
在下文中一共展示了DrupyPHP.strrev方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rewrite_sql
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import strrev [as 别名]
def rewrite_sql(query, primary_table = 'n', primary_field = 'nid', args = []):
join_, where, distinct = _rewrite_sql(query, primary_table, \
primary_field, args)
if (distinct):
query = distinct_field(primary_table, primary_field, query)
if (not php.empty(where) or not php.empty(join_)):
pattern = \
'{ ' + \
' # Beginning of the string ' + \
' ^ ' + \
' ((?P<anonymous_view> ' + \
' # Everything within this set of parentheses ' + \
' # is named "anonymous view ' + \
' (?: ' + \
' # anything not parentheses ' + \
' [^()]++ ' + \
' | ' + \
' # an open parenthesis, more anonymous view and ' + \
' # finally a close parenthesis. ' + \
' \( (?P>anonymous_view) \) ' + \
' )* ' + \
' )[^()]+WHERE) ' + \
'}X'
matches = []
php.preg_match(pattern, query, matches)
if (where):
n = php.strlen(matches[1])
second_part = php.substr(query, n)
first_part = php.substr(matches[1], 0, n - 5) + \
" join WHERE where AND ( "
# PHP 4 does not support strrpos for strings. We emulate it.
haystack_reverse = php.strrev(second_part)
# No need to use strrev on the needle, we supply GROUP, ORDER, LIMIT
# reversed.
for needle_reverse in ('PUORG', 'REDRO', 'TIMIL'):
pos = php.strpos(haystack_reverse, needle_reverse)
if (pos != False):
# All needles are five characters long.
pos += 5
break
if (pos == False):
query = first_part + second_part + ')'
else:
query = first_part + substr(second_part, 0, -pos) + ')' + \
php.substr(second_part, -pos)
else:
query = matches[1] + " join " + \
php.substr(query, php.strlen(matches[1]))
return query