当前位置: 首页>>代码示例>>Python>>正文


Python DrupyPHP.preg_replace方法代码示例

本文整理汇总了Python中lib.drupy.DrupyPHP.preg_replace方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.preg_replace方法的具体用法?Python DrupyPHP.preg_replace怎么用?Python DrupyPHP.preg_replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.drupy.DrupyPHP的用法示例。


在下文中一共展示了DrupyPHP.preg_replace方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: drupal_match_path

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import preg_replace [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
开发者ID:brendoncrawford,项目名称:drupy,代码行数:29,代码来源:path.py

示例2: transfer

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import preg_replace [as 别名]
def transfer(source, headers):
  """
   Transfer file using http to client + Pipes a file through Drupal to the
   client.
  
   @param source File to transfer.
   @param headers An array of http headers to send along with file.
  """
  ob_end_clean()
  for php.header in headers:
    # To prevent HTTP php.header injection, we delete new lines that are
    # not followed by a space or a tab.
    # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
    php.header = php.preg_replace('/\r?\n(?not \t| )/', '', php.header)
    drupal_set_header(php.header)
  source = file_create_path(source)
  # Transfer file in 1024 byte chunks to save memory usage.
  fd = fopen(source, 'rb')
  if (fd):
    while (not feof(fd)):
      print fread(fd, 1024)
    fclose(fd)
  else:
    drupal_not_found()
  exit()
开发者ID:brendoncrawford,项目名称:drupy,代码行数:27,代码来源:file.py

示例3: query_temporary

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import preg_replace [as 别名]
def query_temporary(query):
  """
   Runs a SELECT query and stores its results in a temporary table.
  
   Use this as a substitute for db_query() when the results need to stored
   in a temporary table. Temporary tables exist for the duration of the page
   request.
   User-supplied arguments to the query should be passed in as
   separate parameters
   so that they can be properly escaped to avoid SQL injection attacks.
  
   Note that if you need to know how many results were returned, you should do
   a SELECT COUNT(*) on the temporary table afterwards. db_affected_rows() does
   not give consistent result across different database types in this case.
  
   @param query
     A string containing a normal SELECT SQL query.
   @param ...
     A variable number of arguments which are substituted into the query
     using printf() syntax. The query arguments can be enclosed in one
     array instead.
     Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose
     in '') and %%.
  
     NOTE: using this syntax will cast None and False values to decimal 0,
     and True values to decimal 1.
  
   @param table
     The name of the temporary table to select into. This name will not be
     prefixed as there is no risk of collision.
   @return
     A database query result resource, or False if the query was not executed
     correctly.
  """
  args = func_get_args()
  tablename = php.array_pop(args)
  php.array_shift(args)
  query = php.preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE ' +  \
    tablename  + ' Engine=HEAP SELECT', db_prefix_tables(query))
  # 'All arguments in one array' syntax
  if (php.isset(args, 0) and php.is_array(args, 0)): 
    args = args[0]
  _db_query_callback(args, True)
  query = php.preg_replace_callback(DB_QUERY_REGEXP, \
    '_db_query_callback', query)
  return _db_query(query)
开发者ID:brendoncrawford,项目名称:drupy,代码行数:48,代码来源:database_mysqli.py

示例4: distinct_field

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import preg_replace [as 别名]
def distinct_field(table, field, query):
  """
   Wraps the given table.field entry with a DISTINCT(). The wrapper is added to
   the SELECT list entry of the given query and the resulting query is
   returned. This function only applies the wrapper if a DISTINCT doesn't
   already exist in the query.
  
   @param table Table containing the field to set as DISTINCT
   @param field Field to set as DISTINCT
   @param query Query to apply the wrapper to
   @return SQL query with the DISTINCT wrapper surrounding the given
   table.field.
  """
  field_to_select = 'DISTINCT(' +  table  + '.' + field + ')'
  # (?<not text) is a negative look-behind
  # (no need to rewrite queries that already use DISTINCT).
  return php.preg_replace('/(SELECT.*)(?:' +  table  + \
    '\.|\s)(?<not DISTINCT\()(?<not DISTINCT\(' + table + '\.)' + field + \
    '(.*FROM )/AUsi', '\1 ' + field_to_select + '\2', query)
开发者ID:brendoncrawford,项目名称:drupy,代码行数:21,代码来源:database_mysqli.py

示例5: escape_table

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import preg_replace [as 别名]
def escape_table(string_):
  return php.preg_replace('/[^A-Za-z0-9_]+/', '', string_)
开发者ID:brendoncrawford,项目名称:drupy,代码行数:4,代码来源:database.py

示例6: conf_init

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import preg_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_))
开发者ID:sabren,项目名称:drupy,代码行数:70,代码来源:bootstrap.py


注:本文中的lib.drupy.DrupyPHP.preg_replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。