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


Python DrupyPHP.unserialize方法代码示例

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


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

示例1: get

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import unserialize [as 别名]
def get(cid, table = 'cache'):
  """
   Return data from the persistent cache. Data may be stored as either plain 
   text or as serialized data. cache_get will automatically return 
   unserialized objects and arrays.
  
   @param cid
     The cache ID of the data to retrieve.
   @param table
     The table table to store the data in.
     Valid core values are 'cache_filter',
     'cache_menu', 'cache_page', or 'cache' for the default cache.
   @return The cache or FALSE on failure.
  """
  # Garbage collection necessary when enforcing a minimum cache lifetime
  cache_flush = lib_bootstrap.variable_get('cache_flush', 0);
  if (cache_flush and (cache_flush + \
      variable_get('cache_lifetime', 0) <= REQUEST_TIME)):
    # Reset the variable immediately to prevent a meltdown in heavy
    # load situations.
    variable_set('cache_flush', 0);
    # Time to php.flush old cache data
    lib_database.query(\
      "DELETE FROM {" + table + "} WHERE expire != %d AND expire <= %d", \
      CACHE_PERMANENT, cache_flush);
  cache = lib_database.fetch_object(lib_database.query(\
    "SELECT data, created, headers, expire, serialized " + \
    "FROM {" + table + "} WHERE cid = '%s'", cid));
  if (php.isset(cache, 'data')):
    # If the data is permanent or we're not enforcing a minimum cache lifetime
    # always return the cached data.
    if (cache.expire == CACHE_PERMANENT or not \
        variable_get('cache_lifetime', 0)):
      if (cache.serialized):
        cache.data = php.unserialize(cache.data);
    # If enforcing a minimum cache lifetime, validate that the data is
    # currently valid for this user before we return it by making sure the
    # cache entry was created before the timestamp in the current session's
    # cache timer. The cache variable is loaded into the user object by
    # _sess_read() in session.inc.
    else:
      if (lib_appglobals.user.cache > cache.created):
        # This cache data is too old and thus not valid for us, ignore it.
        return False;
      else:
        if (cache.serialized):
          cache.data = php.unserialize(cache.data);
    return cache;
  return False;
开发者ID:brendoncrawford,项目名称:drupy,代码行数:51,代码来源:cache.py

示例2: variable_init

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import unserialize [as 别名]
def variable_init(conf_={}):
    """
   Load the persistent variable table.
  
   The variable table is composed of values that have been saved in the table
   with variable_set() as well as those explicitly specified
   in the configuration file.
  """
    # NOTE: caching the variables improves performance by 20% when serving
    # cached pages.
    cached = lib_cache.get("variables", "cache")
    if cached:
        variables = cached.data
    else:
        variables = {}
        result = lib_database.query("SELECT * FROM {variable}")
        while True:
            variable = lib_database.fetch_object(result)
            if not variable:
                break
            variables[variable.name] = php.unserialize(variable.value)
        lib_cache.set("variables", variables)
    for name, value in conf_.items():
        variables[name] = value
    return variables
开发者ID:sabren,项目名称:drupy,代码行数:27,代码来源:bootstrap.py

示例3: drupal_unpack

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import unserialize [as 别名]
def drupal_unpack(obj, field="data"):
    """
   Unserializes and appends elements from a serialized string.
  
   @param obj
     The object to which the elements are appended.
   @param field
     The attribute of obj whose value should be unserialized.
  """
    if hasattr(obj, field) and not php.empty(getattr(obj, field)):
        data = php.unserialize(getattr(obj, field))
    else:
        data = None
    if hasattr(obj, field) and not php.empty(data):
        for key, value in data.items():
            if not php.isset(obj, key):
                setattr(obj, key, value)
    return obj
开发者ID:sabren,项目名称:drupy,代码行数:20,代码来源:bootstrap.py


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