本文整理汇总了Python中lib.drupy.DrupyPHP.str_replace方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.str_replace方法的具体用法?Python DrupyPHP.str_replace怎么用?Python DrupyPHP.str_replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.drupy.DrupyPHP
的用法示例。
在下文中一共展示了DrupyPHP.str_replace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unmunge_filename
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import str_replace [as 别名]
def unmunge_filename(filename):
"""
Undo the effect of upload_munge_filename().
@param filename string filename
@return string
"""
return php.str_replace('_.', '.', filename)
示例2: create_url
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import str_replace [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})
示例3: _query
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import str_replace [as 别名]
def _query(query_, debug = 0):
"""
Helper function for db_query().
"""
if (lib_bootstrap.variable_get('dev_query', 0)):
usec,sec = php.explode(' ', php.microtime())
timer = float(usec) + float(sec)
# If devel.plugin query logging is enabled, prepend a comment
# with the username and calling function
# to the SQL string. This is useful when running mysql's
# SHOW PROCESSLIST to learn what exact
# code is issueing the slow query.
bt = debug_backtrace()
# t() may not be available yet so we don't wrap 'Anonymous'
name = (lib_appglobals.user.name if (lib_appglobals.user.uid > 0) else \
variable_get('anonymous', 'Anonymous'))
# php.str_replace() to prevent SQL injection via username
# or anonymous name.
name = php.str_replace(['*', '/'], '', name)
query_ = '/* ' + name + ' : ' . bt[2]['function'] + ' */ ' + query_
result = DrupyMySQL.mysqli_query(lib_appglobals.active_db, query_)
if (lib_bootstrap.variable_get('dev_query', 0)):
query_ = bt[2]['function'] + "\n" + query_
usec,sec = php.explode(' ', php.microtime())
stop = float(usec) + float(sec)
diff = stop - timer
lib_appglobals.queries.append( [query_, diff] )
if (debug):
print '<p>query: ' + query_ + '<br />error:' + \
DrupyMySQL.mysqli_error(lib_appglobals.active_db) + '</p>'
if (not DrupyMySQL.mysqli_errno(lib_appglobals.active_db)):
return result
else:
# Indicate to drupal_error_handler that this is a database error.
DB_ERROR = True
php.trigger_error(lib_bootstrap.check_plain(\
DrupyMySQL.mysqli_error(lib_appglobals.active_db) + \
"\nquery: " + query_), php.E_USER_WARNING)
return False
示例4: conf_init
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import str_replace [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_))