本文整理汇总了Python中lib.drupy.DrupyPHP.preg_quote方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.preg_quote方法的具体用法?Python DrupyPHP.preg_quote怎么用?Python DrupyPHP.preg_quote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.drupy.DrupyPHP
的用法示例。
在下文中一共展示了DrupyPHP.preg_quote方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drupal_match_path
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import preg_quote [as 别名]
def drupal_match_path(path_, patterns):
"""
Check if a path matches any pattern in a set of patterns.
@note DRUPY:
This function was substantially modified
@param path
The path to match.
@param patterns
String containing a set of patterns separated by \n, \r or \r\n.
@return
Boolean value: TRUE if the path matches a pattern, FALSE otherwise.
"""
php.static(drupal_match_path, 'regexps')
if (not php.isset(drupal_match_path.regexps, patterns)):
frnt = variable_get('site_frontpage', 'node');
frnt_q = php.preg_quote(frnt, '/');
frnt_p = '\1' + frnt_q + '\2';
pra2 = ['|', '.*', frnt_p];
pra1 = ['/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'];
pat_q = php.preg_quote(patterns, '/');
pat_prep = php.preg_replace(pra1, pra2, pat_q);
pat_final = '/^(' + pat_prep + ')$/';
drupal_match_path.regexps[patterns] = pat_final;
return (php.preg_match(drupal_match_path.regexps[patterns], path_) > 0)
else:
return False
示例2: validate_extensions
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import preg_quote [as 别名]
def validate_extensions(file, extensions):
"""
Check that the filename ends with an allowed extension + This check is not
enforced for the user #1.
@param file
A Drupal file object.
@param extensions
A string with a space separated
@return
An array + If the file extension is not allowed,
it will contain an error message.
"""
errors = []
# Bypass validation for uid = 1.
if (lib_appglobals.user.uid != 1):
regex = '/\.(' + ereg_replace(' +', '|', \
php.preg_quote(extensions)) + ')$/i'
if (not php.preg_match(regex, file.filename)):
errors.append( t('Only files with the following extensions ' + \
'are allowed: %files-allowed.', {'%files-allowed' : extensions}) )
return errors