本文整理汇总了Python中lib.drupy.DrupyPHP.strlen方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.strlen方法的具体用法?Python DrupyPHP.strlen怎么用?Python DrupyPHP.strlen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.drupy.DrupyPHP
的用法示例。
在下文中一共展示了DrupyPHP.strlen方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rewrite_sql
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import strlen [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
示例2: drupal_validate_utf8
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import strlen [as 别名]
def drupal_validate_utf8(text):
"""
Checks whether a string is valid UTF-8.
All functions designed to filter input should use drupal_validate_utf8
to ensure they operate on valid UTF-8 strings to prevent bypass of the
filter.
When text containing an invalid UTF-8 lead byte (0xC0 - 0xFF) is presented
as UTF-8 to Internet Explorer 6, the program may misinterpret subsequent
bytes. When these subsequent bytes are HTML control characters such as
quotes or angle brackets, parts of the text that were deemed safe by filters
end up in locations that are potentially unsafe; An onerror attribute that
is outside of a tag, and thus deemed safe by a filter, can be interpreted
by the browser as if it were inside the tag.
This def exploits preg_match behaviour (since PHP 4.3.5) when used
with the u modifier, as a fast way to find invalid UTF-8. When the matched
string contains an invalid byte sequence, it will fail silently.
preg_match may not fail on 4 and 5 octet sequences, even though they
are not supported by the specification.
The specific preg_match behaviour is present since PHP 4.3.5.
@param text
The text to check.
@return
TRUE if the text is valid UTF-8, FALSE if not.
"""
if php.strlen(text) == 0:
return True
return php.preg_match("/^./us", text) == 1
示例3: validate_name_length
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import strlen [as 别名]
def validate_name_length(file):
"""
Check for files with names longer than we can store in the database.
@param file
A Drupal file object.
@return
An array + If the file name is too long, it will contain an error message.
"""
errors = []
if (php.strlen(file.filename) > 255):
errors.append( t('Its name exceeds the 255 characters limit. ' + \
'Please rename the file and try again.') )
return errors
示例4: create_url
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import strlen [as 别名]
def create_url(path):
"""
Create the download path to a file.
@param path A string containing the path of the file to generate URL for.
@return A string containing a URL that can be used to download the file.
"""
# Strip file_directory_path from path + We only include relative paths in urls.
if (php.strpos(path, file_directory_path() + '/') == 0):
path = php.trim(php.substr(path, php.strlen(file_directory_path())), '\\/')
dls = variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC);
if dls == FILE_DOWNLOADS_PUBLIC:
return settings.base_url + '/' + file_directory_path() + '/' + \
php.str_replace('\\', '/', path)
elif dls == FILE_DOWNLOADS_PRIVATE:
return url('system/files/' + path, {'absolute' : True})
示例5: conf_init
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import strlen [as 别名]
def conf_init():
"""
Loads the configuration and sets the base URL, cookie domain, and
session name correctly.
"""
# These will come from settings
# db_url, db_prefix, cookie_domain, conf, installed_profile, update_free_access
if lib_appglobals.base_url != None:
# Parse fixed base URL from settings.php.
parts = php.parse_url(lib_appglobals.base_url)
if not php.isset(parts, "path"):
parts["path"] = ""
lib_appglobals.base_path = parts["path"] + "/"
# Build base_root (everything until first slash after "scheme://").
lib_appglobals.base_root = php.substr(
lib_appglobals.base_url, 0, php.strlen(lib_appglobals.base_url) - php.strlen(parts["path"])
)
else:
# Create base URL
lib_appglobals.base_root = (
"https" if (php.isset(php.SERVER, "HTTPS") and php.SERVER["HTTPS"] == "on") else "http"
)
# As php.SERVER['HTTP_HOST'] is user input, ensure it only contains
# characters allowed in hostnames.
lib_appglobals.base_root += "://" + php.preg_replace("/[^a-z0-9-:._]/i", "", php.SERVER["HTTP_HOST"])
lib_appglobals.base_url = lib_appglobals.base_root
# php.SERVER['SCRIPT_NAME'] can, in contrast to php.SERVER['PHP_SELF'], not
# be modified by a visitor.
dir = php.trim(php.dirname(php.SERVER["SCRIPT_NAME"]), "\,/")
if len(dir) > 0:
lib_appglobals.base_path = "/dir"
lib_appglobals.base_url += lib_appglobals.base_path
lib_appglobals.base_path += "/"
else:
lib_appglobals.base_path = "/"
if settings.cookie_domain != None:
# If the user specifies the cookie domain, also use it for session name.
session_name_ = settings.cookie_domain
else:
# Otherwise use base_url as session name, without the protocol
# to use the same session identifiers across http and https.
session_name_ = php.explode("://", lib_appglobals.base_url, 2)[1]
# We escape the hostname because it can be modified by a visitor.
if not php.empty(php.SERVER["HTTP_HOST"]):
settings.cookie_domain = check_plain(php.SERVER["HTTP_HOST"])
# To prevent session cookies from being hijacked, a user can configure the
# SSL version of their website to only transfer session cookies via SSL by
# using PHP's session.cookie_secure setting. The browser will then use two
# separate session cookies for the HTTPS and HTTP versions of the site. So we
# must use different session identifiers for HTTPS and HTTP to prevent a
# cookie collision.
if php.ini_get("session.cookie_secure"):
session_name_ += "SSL"
# Strip leading periods, www., and port numbers from cookie domain.
settings.cookie_domain = php.ltrim(settings.cookie_domain, ".")
if php.strpos(settings.cookie_domain, "www.") == 0:
settings.cookie_domain = php.substr(settings.cookie_domain, 4)
settings.cookie_domain = php.explode(":", settings.cookie_domain)
settings.cookie_domain = "." + settings.cookie_domain[0]
# Per RFC 2109, cookie domains must contain at least one dot other than the
# first. For hosts such as 'localhost' or IP Addresses we don't set a
# cookie domain.
if php.count(php.explode(".", settings.cookie_domain)) > 2 and not php.is_numeric(
php.str_replace(".", "", settings.cookie_domain)
):
php.ini_set("session.cookie_domain", settings.cookie_domain)
# print session_name;
lib_session.name("SESS" + php.md5(session_name_))