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


Python DrupyPHP.array_key_exists方法代码示例

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


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

示例1: ip_address

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import array_key_exists [as 别名]
def ip_address(reset=False):
    """
   If Drupal is behind a reverse proxy, we use the X-Forwarded-For header
   instead of $_SERVER['REMOTE_ADDR'], which would be the IP address of 
   the proxy server, and not the client's.  If Drupal is run in a cluster
   we use the X-Cluster-Client-Ip header instead.

   @param $reset
     Reset the current IP address saved in static.
   @return
     IP address of client machine, adjusted for reverse proxy and/or cluster
     environments.
  """
    php.static(ip_address, "ip_address")
    if ip_address.ip_address is None or reset:
        ip_address.ip_address = php.SERVER["REMOTE_ADDR"]
        if variable_get("reverse_proxy", 0):
            if php.array_key_exists("HTTP_X_FORWARDED_FOR", php.SERVER):
                # If an array of known reverse proxy IPs is provided, then trust
                # the XFF header if request really comes from one of them.
                reverse_proxy_addresses = variable_get("reverse_proxy_addresses", tuple())
                if not php.empty(reverse_proxy_addresses) and php.in_array(
                    ip_address.ip_address, reverse_proxy_addresses, True
                ):
                    # If there are several arguments, we need to check the most
                    # recently added one, i.e. the last one.
                    ip_address.ip_address = php.array_pop(php.explode(",", php.SERVER["HTTP_X_FORWARDED_FOR"]))
            # When Drupal is run in a cluster environment,
            # REMOTE_ADDR contains the IP
            # address of a server in the cluster, while the IP address
            # of the client is
            # stored in HTTP_X_CLUSTER_CLIENT_IP.
            if php.array_key_exists("HTTP_X_CLUSTER_CLIENT_IP", php.SERVER):
                ip_address.ip_address = php.SERVER["HTTP_X_CLUSTER_CLIENT_IP"]
    return ip_address.ip_address
开发者ID:sabren,项目名称:drupy,代码行数:37,代码来源:bootstrap.py

示例2: prefix_tables

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import array_key_exists [as 别名]
def prefix_tables(sql):
  """
   Append a database prefix to all tables in a query.
  
   Queries sent to Drupal should wrap all table names in curly brackets. This
   function searches for this syntax and adds Drupal's table prefix to all
   tables, allowing Drupal to coexist with other systems in the same
   database if necessary.
  
   @param sql
     A string containing a partial or entire SQL query.
   @return
     The properly-prefixed string.
  """
  if (php.is_array(settings.db_prefix)):
    if (php.array_key_exists('default', settings.db_prefix)):
      tmp = settings.db_prefix;
      del(tmp['default']);
      for key,val in tmp.items():
        sql = php.strtr(sql, {('{' + key + '}') : (val + key)});
      return php.strtr(sql, {'{' : settings.db_prefix['default'], '}' : ''});
    else:
      for key,val in settings.db_prefix.items():
        sql = php.strtr(sql, {('{' + key + '}') : (val + key)});
      return php.strtr(sql, {'{' : '', '}' : ''});
  else:
    return php.strtr(sql, {'{' : settings.db_prefix, '}' : ''});
开发者ID:brendoncrawford,项目名称:drupy,代码行数:29,代码来源:database.py

示例3: set_active

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

示例4: get_sort

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import array_key_exists [as 别名]
def get_sort(headers):
  """
   Determine the current sort direction.

   @param headers
     An array of column headers in the format described in theme_table().
   @return
     The current sort direction ("asc" or "desc").
  """
  if php.isset(php.GET['sort']):
    return 'desc' if (php.GET['sort'] == 'desc')  else 'asc';
  # User has not specified a sort. Use default if specified; otherwise use
  # "asc".
  else:
    for header in headers:
      if php.is_array(header) and php.array_key_exists('sort', header):
        return header['sort']
  return 'asc'
开发者ID:brendoncrawford,项目名称:drupy,代码行数:20,代码来源:tablesort.py


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