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


Python DrupyPHP.static方法代码示例

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


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

示例1: drupal_load

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [as 别名]
def drupal_load(type_, name):
    """
   Includes a file with the provided type and name. This prevents
   including a theme, engine, plugin, etc., more than once.
  
   @param type
     The type of item to load (i.e. theme, theme_engine, plugin).
   @param name
     The name of the item to load.
  
   @return
     TRUE if the item is loaded or has already been loaded.
  """
    php.static(drupal_load, "files", {})
    if not php.isset(drupal_load.files, type):
        drupal_load.files[type_] = {}
    if php.isset(drupal_load.files[type_], name):
        return True
    else:
        filename = drupal_get_filename(type_, name)
        if filename != False:
            lib_plugin.plugins[name] = DrupyImport.import_file(filename)
            drupal_load.files[type_][name] = True
            return True
        else:
            return False
开发者ID:sabren,项目名称:drupy,代码行数:28,代码来源:bootstrap.py

示例2: language_list

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [as 别名]
def language_list(field="language", reset=False):
    """
   Get a list of languages set up indexed by the specified key
  
   @param field The field to index the list with.
   @param reset Boolean to request a reset of the list.
  """
    php.static(language_list, "languages")
    # Reset language list
    if reset:
        languages_list.languages = {}
    # Init language list
    if languages_list.languages == None:
        if variable_get("language_count", 1) > 1 or plugin_exists("locale"):
            result = db_query("SELECT# FROM {languages} ORDER BY weight ASC, name ASC")
            while True:
                row = db_fetch_object(result)
                if row == None:
                    break
                languages_list.languages["language"][row.language] = row
        else:
            # No locale plugin, so use the default language only.
            default_ = language_default()
            languages_list.languages["language"][default_.language] = default_
    # Return the array indexed by the right field
    if not php.isset(languages_list.languages, field):
        languages_list.languages[field] = {}
        for lang in languages_list.languages["language"]:
            # Some values should be collected into an array
            if php.in_array(field, ["enabled", "weight"]):
                languages_list.languages[field][lang.field][lang.language] = lang
            else:
                languages_list.languages[field][lang.field] = lang
    return languages_list.languages[field]
开发者ID:sabren,项目名称:drupy,代码行数:36,代码来源:bootstrap.py

示例3: arg

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [as 别名]
def arg(index = None, path = None):
  """
   Return a component of the current Drupal path.
  
   When viewing a page at the path "admin/build/types", for example, arg(0)
   would return "admin", arg(1) would return "content", and arg(2) would return
   "types".
  
   Avoid use of this function where possible, as resulting code is hard to read.
   Instead, attempt to use named arguments in menu callback functions. See the
   explanation in menu.inc for how to construct callbacks that take arguments.
  
   @param index
     The index of the component, where each component is separated by a '/'
     (forward-slash), and where the first component has an index of 0 (zero).
  
   @return
     The component specified by index, or NULL if the specified component was
     not found.
  """
  php.static(arg, 'arguments', {})
  if (path is None):
    path = php.GET['q'];
  if (not php.isset(arg.arguments, path)):
    arg.arguments[path] = php.explode('/', path);
  if (index is None):
    return arg.arguments[path];
  if (php.isset(arg.arguments[path], index)):
    return arg.arguments[path][index];
开发者ID:brendoncrawford,项目名称:drupy,代码行数:31,代码来源:path.py

示例4: ip_address

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [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

示例5: drupal_match_path

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [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

示例6: _query_callback

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [as 别名]
def _query_callback(match, init = False):
  """
   Helper function for db_query().
  """
  php.static(_query_callback, 'args')
  if (init):
    _query_callback.args = list(match);
    return;
  # We must use type casting to int to convert FALSE/NULL/(TRUE?)
  if match[1] == '%d': 
    # We don't need db_escape_string as numbers are db-safe
    return str(int(php.array_shift(_query_callback.args))); 
  elif match[1] == '%s':
    return db.escape_string(php.array_shift(_query_callback.args));
  elif match[1] == '%n':
    # Numeric values have arbitrary precision, so can't be treated as float.
    # is_numeric() allows hex values (0xFF), but they are not valid.
    value = php.trim(php.array_shift(args));
    return  (value if (php.is_numeric(value) and not \
      php.stripos(value, 'x')) else '0')
  elif match[1] == '%%':
    return '%';
  elif match[1] == '%f':
    return float(php.array_shift(_query_callback.args));
  elif match[1] == '%b': # binary data
    return db.encode_blob(php.array_shift(_query_callback.args));
开发者ID:brendoncrawford,项目名称:drupy,代码行数:28,代码来源:database.py

示例7: list_

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [as 别名]
def list_(refresh = False, bootstrap = True, sort = False, \
    fixed_list = None):
  """
   Collect a list of all loaded plugins. During the bootstrap, return only
   vital plugins. See bootstrap.inc
  
   @param refresh
     Whether to force the plugin list to be regenerated (such as after the
     administrator has changed the system settings).
   @param bootstrap
     Whether to return the reduced set of plugins loaded in "bootstrap mode"
     for cached pages. See bootstrap.inc.
   @param sort
     By default, plugins are ordered by weight and filename,
     settings this option
     to True, plugin list will be ordered by plugin name.
   @param fixed_list
     (Optional) Override the plugin list with the given plugins.
     Stays until the
     next call with refresh = True.
   @return
     An associative array whose keys and values are the names of all loaded
     plugins.
  """
  php.static(list_, 'list_', {})
  php.static(list_, 'sorted_list')
  if (refresh or fixed_list):
    list_.sorted_list = None
    list_.list_ = {}
    if (fixed_list):
      for name,plugin in fixed_list.items():
        lib_bootstrap.drupal_get_filename('plugin', name, plugin['filename'])
        list_.list_[name] = name
    else:
      if (bootstrap):
        result = lib_database.query(\
          "SELECT name, filename FROM {system} " + \
          "WHERE type = 'plugin' AND status = 1 AND " + \
          "bootstrap = 1 ORDER BY weight ASC, filename ASC")
      else:
        result = lib_database.query(\
          "SELECT name, filename FROM {system} " + \
          "WHERE type = 'plugin' AND status = 1 " + \
          "ORDER BY weight ASC, filename ASC")
      while True:
        plugin_ = lib_database.fetch_object(result)
        if (plugin_ == None or plugin_ == False):
          break
        if (DrupyImport.exists(plugin_.filename)):
          lib_bootstrap.drupal_get_filename('plugin', \
            plugin_.name, plugin_.filename)
          list_.list_[plugin_.name] = plugin_.name
  if (sort):
    if (list_.sorted_list == None):
      list_.sorted_list = plugin_list.list_
      p.ksort(list_.sorted_list)
    return list_.sorted_list
  return list_.list_
开发者ID:brendoncrawford,项目名称:drupy,代码行数:60,代码来源:plugin.py

示例8: get_t

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [as 别名]
def get_t():
    """
   Return the name of the localisation function. Use in code that needs to
   run both during installation and normal operation.
  """
    php.static(get_t, "t")
    if get_t.t == None:
        get_t.t = "st" if php.function_exists("install_main") else "t"
    return get_t.t
开发者ID:sabren,项目名称:drupy,代码行数:11,代码来源:bootstrap.py

示例9: set_active

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [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

示例10: drupal_get_schema

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [as 别名]
def drupal_get_schema(table=None, rebuild=False):
    """
   Get the schema definition of a table, or the whole database schema.
  
   The returned schema will include any modifications made by any
   module that implements hook_schema_alter().
  
   @param $table
     The name of the table. If not given, the schema of all tables is returned.
   @param $rebuild
     If true, the schema will be rebuilt instead of retrieved from the cache.
  """
    php.static(drupal_get_schema, "schema", [])
    if php.empty(drupal_get_schema.schema) or rebuild:
        # Try to load the schema from cache.
        cached = lib_cache.get("schema")
        if not rebuild and cached:
            drupal_get_schema.schema = cached.data
        # Otherwise, rebuild the schema cache.
        else:
            drupal_get_schema.schema = []
            # Load the .install files to get hook_schema.
            # On some databases this function may be called before bootstrap has
            # been completed, so we force the functions we need to load just in case.
            if drupal_function_exists("module_load_all_includes"):
                # There is currently a bug in module_list() where it caches what it
                # was last called with, which is not always what you want.
                # module_load_all_includes() calls module_list(), but if this function
                # is called very early in the bootstrap process then it will be
                # uninitialized and therefore return no modules.  Instead, we have to
                # "prime" module_list() here to to values we want, specifically
                # "yes rebuild the list and don't limit to bootstrap".
                # TODO: Remove this call after http://drupal.org/node/222109 is fixed.
                lib_plugin.list(True, False)
                lib_plugin.load_all_includes("install")
            # Invoke hook_schema for all modules.
            for module in module_implements("schema"):
                current = lib_plugin.invoke(module, "schema")
                if drupal_function_exists("_drupal_initialize_schema"):
                    _drupal_initialize_schema(module, current)
                schema = php.array_merge(schema, current)
            if drupal_function_exists("drupal_alter"):
                drupal_alter("schema", schema)
            if drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL:
                cache_set("schema", schema)
    if table is None:
        return schema
    elif php.isset(schema, table):
        return schema[table]
    else:
        return False
开发者ID:sabren,项目名称:drupy,代码行数:53,代码来源:bootstrap.py

示例11: registry_load_path_files

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [as 别名]
def registry_load_path_files(return_=False):
    """
   registry_load_path_files
  """
    php.static(registry_load_path_files, "file_cache_data", [])
    if return_:
        sort(registry_load_path_files.file_cache_data)
        return registry_load_path_files.file_cache_data
    menu = menu_get_item()
    cache = cache_get("registry:" + menu["path"], "cache_registry")
    if not php.empty(cache.data):
        for file in php.explode(";", cache.data):
            php.require_once(file)
            registry_load_path_files.file_cache_data.append(file)
开发者ID:sabren,项目名称:drupy,代码行数:16,代码来源:bootstrap.py

示例12: upload_max_size

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [as 别名]
def upload_max_size():
  """
   Determine the maximum file upload size by querying the PHP settings.
  
   @return
     A file size limit in bytes based on the PHP
     upload_max_filesize and post_max_size
  """
  php.static(file_upload_max_size, 'max_size', -1)
  if (file_upload_max_size.max_size < 0):
    upload_max = parse_size(ini_get('upload_max_filesize'))
    post_max = parse_size(ini_get('post_max_size'))
    file_upload_max_size.max_size = (upload_max if \
      (upload_max < post_max) else post_max)
  return max_size
开发者ID:brendoncrawford,项目名称:drupy,代码行数:17,代码来源:file.py

示例13: drupal_set_title

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [as 别名]
def drupal_set_title(title = None):
  """
   Set the title of the current page, for display on the
   page and in the title bar.
  
   @param title
     Optional string value to assign to the page title; or if set to NULL
     (default), leaves the current title unchanged.
  
   @return
     The updated title of the current page.
  """
  php.static(drupal_set_title, 'stored_title')
  if (title == None):
    drupal_set_title.stored_title = title;
  return drupal_set_title.stored_title;
开发者ID:brendoncrawford,项目名称:drupy,代码行数:18,代码来源:path.py

示例14: watchdog

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [as 别名]
def watchdog(type, message, variables=[], severity=WATCHDOG_NOTICE, link=None):
    """
   Log a system message.
  
   @param type
     The category to which this message belongs.
   @param message
     The message to store in the log. See t() for documentation
     on how message and variables interact. Keep message
     translatable by not concatenating dynamic values into it!
   @param variables
     Array of variables to replace in the message on display or
     NULL if message is already translated or not possible to
     translate.
   @param severity
     The severity of the message, as per RFC 3164
   @param link
     A link to associate with the message.
  
   @see watchdog_severity_levels()
  """
    php.static(watchdog, "in_error_state", False)
    # It is possible that the error handling will itself trigger an error.
    # In that case, we could
    # end up in an infinite loop.  To avoid that, we implement a simple
    # static semaphore.
    if not watchdog.in_error_state:
        watchdog.in_error_state = True
        # Prepare the fields to be logged
        log_message = {
            "type": type,
            "message": message,
            "variables": variables,
            "severity": severity,
            "link": link,
            "user": lib_appglobals.user,
            "request_uri": lib_appglobals.base_root + request_uri(),
            "referer": php.SERVER["HTTP_REFERER"],
            "ip": ip_address(),
            "timestamp": REQUEST_TIME,
        }
        # Call the logging hooks to log/process the message
        for plugin_ in lib_plugin.implements("watchdog", True):
            lib_plugin.invoke(plugin_, "watchdog", log_message)
    watchdog.in_error_state = False
开发者ID:sabren,项目名称:drupy,代码行数:47,代码来源:bootstrap.py

示例15: registry_cache_hook_implementations

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import static [as 别名]
def registry_cache_hook_implementations(hook, write_to_persistent_cache=False):
    """
   Save hook implementations cache.
  
   @param hook
     Array with the hook name and list of plugins that implement it.
   @param write_to_persistent_cache
     Whether to write to the persistent cache.
  """
    php.static(registry_cache_hook_implementations, "implementations", {})
    if hook:
        # Newer is always better, so overwrite anything that's come before.
        registry_cache_hook_implementations.implementations[hook["hook"]] = hook["plugins"]
    if write_to_persistent_cache == True:
        # Only write this to cache if the implementations data we are going to cache
        # is different to what we loaded earlier in the request.
        if registry_cache_hook_implementations.implementations != lib_plugin.implements():
            cache_set("hooks", registry_cache_hook_implementations.implementations, "cache_registry")
开发者ID:sabren,项目名称:drupy,代码行数:20,代码来源:bootstrap.py


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