本文整理汇总了Python中lib.drupy.DrupyPHP.strpos方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.strpos方法的具体用法?Python DrupyPHP.strpos怎么用?Python DrupyPHP.strpos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.drupy.DrupyPHP
的用法示例。
在下文中一共展示了DrupyPHP.strpos方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_location
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import strpos [as 别名]
def check_location(source, directory = ''):
"""
Check if a file is really located inside directory + Should be used to make
sure a file specified is really located within the directory to prevent
exploits.
@code
// Returns False:
file_check_location('/www/example.com/files/../../../etc/passwd', \
'/www/example.com/files')
@endcode
@param source A string set to the file to check.
@param directory A string where the file should be located.
@return FALSE for invalid path or the real path of the source.
"""
check = realpath(source)
if (check):
source = check
else:
# This file does not yet exist
source = realpath(php.dirname(source)) + '/' + basename(source)
directory = realpath(directory)
if (directory and php.strpos(source, directory) != 0):
return False
return source
示例2: set_active
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import strpos [as 别名]
def set_active(name = 'default'):
"""
Activate a database for future queries.
If it is necessary to use external databases in a project, this function can
be used to change where database queries are sent. If the database has not
yet been used, it is initialized using the URL specified for that name in
Drupal's configuration file. If this name is not defined, a duplicate of the
default connection is made instead.
Be sure to change the connection back to the default when done with custom
code.
@param name
The name assigned to the newly active database connection. If omitted, the
default connection will be made active.
@return the name of the previously active database or FALSE if non was
found.
@todo BC: Need to eventually resolve the database importing mechanism here
right now we are statically loading mysql at the top, but eventually we need
to get this figured out
"""
php.static(set_active, 'db_conns', {})
php.static(set_active, 'active_name', False)
if (settings.db_url == None):
install_goto('install.py');
if (not php.isset(set_active.db_conns, name)):
# Initiate a new connection, using the named DB URL specified.
if (isinstance(settings.db_url, dict)):
connect_url = (settings.db_url[name] if \
php.array_key_exists(name, settings.db_url) else \
settings.db_url['default']);
else:
connect_url = settings.db_url;
lib_appglobals.db_type = \
php.substr(connect_url, 0, php.strpos(connect_url, '://'));
#handler = "includes/database_%(db_type)s.py" % {'db_type' : db_type};
#try:
# import db file here
#except ImportError:
# _db_error_page("The database type '" + db_type + \
# "' is unsupported. Please use either 'mysql' or " + \
# "'mysqli' for MySQL, or 'pgsql' for PostgreSQL databases.");
set_active.db_conns[name] = db.connect(connect_url);
# We need to pass around the simpletest database prefix in the request
# and we put that in the user_agent php.header.
if (php.preg_match("/^simpletest\d+$/", php.SERVER['HTTP_USER_AGENT'])):
settings.db_prefix = php.SERVER['HTTP_USER_AGENT'];
previous_name = set_active.active_name;
# Set the active connection.
set_active.active_name = name;
lib_appglobals.active_db = set_active.db_conns[name];
return previous_name;
示例3: drupal_page_cache_header
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import strpos [as 别名]
def drupal_page_cache_header(cache):
"""
Set HTTP headers in preparation for a cached page response.
The general approach here is that anonymous users can keep a local
cache of the page, but must revalidate it on every request. Then,
they are given a '304 Not Modified' response as long as they stay
logged out and the page has not been modified.
"""
# Set default values:
last_modified = php.gmdate("D, d M Y H:i:s", cache.created) + " GMT"
etag = '"' + drupy_md5(last_modified) + '"'
# See if the client has provided the required HTTP headers:
if_modified_since = (
php.stripslashes(php.SERVER["HTTP_IF_MODIFIED_SINCE"])
if php.isset(php.SERVER, "HTTP_IF_MODIFIED_SINCE")
else False
)
if_none_match = (
php.stripslashes(php.SERVER["HTTP_IF_NONE_MATCH"]) if php.isset(php.SERVER, "HTTP_IF_NONE_MATCH") else False
)
if (
if_modified_since
and if_none_match
and if_none_match == etag # etag must match
and if_modified_since == last_modified
): # if-modified-since must match
php.header(php.SERVER["SERVER_PROTOCOL"] + " 304 Not Modified")
# All 304 responses must send an etag if the 200 response for the same
# object contained an etag
php.header("Etag: %(etag)s" % {"etag": etag})
exit()
# Send appropriate response:
php.header("Last-Modified: %(last_modified)s" % {"last_modified": last_modified})
php.header("Etag: %(etag)s" % {"etag": etag})
# The following headers force validation of cache:
php.header("Expires: Sun, 19 Nov 1978 05:00:00 GMT")
php.header("Cache-Control: must-revalidate")
if variable_get("page_compression", True):
# Determine if the browser accepts gzipped data.
if php.strpos(php.SERVER["HTTP_ACCEPT_ENCODING"], "gzip") == False and php.function_exists("gzencode"):
# Strip the gzip php.header and run uncompress.
cache.data = php.gzinflate(php.substr(php.substr(cache.data, 10), 0, -8))
elif php.function_exists("gzencode"):
php.header("Content-Encoding: gzip")
# Send the original request's headers. We send them one after
# another so PHP's php.header() def can deal with duplicate
# headers.
headers = php.explode("\n", cache.headers)
for php.header_ in headers:
php.header(php.header_)
print cache.data
示例4: rewrite_sql
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import strpos [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
示例5: create_url
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import strpos [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})
示例6: conf_init
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import strpos [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_))