當前位置: 首頁>>代碼示例>>Python>>正文


Python pickle.__builtins__方法代碼示例

本文整理匯總了Python中pickle.__builtins__方法的典型用法代碼示例。如果您正苦於以下問題:Python pickle.__builtins__方法的具體用法?Python pickle.__builtins__怎麽用?Python pickle.__builtins__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pickle的用法示例。


在下文中一共展示了pickle.__builtins__方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _make_skel_func

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import __builtins__ [as 別名]
def _make_skel_func(code, num_closures, base_globals = None):
    """ Creates a skeleton function object that contains just the provided
        code and the correct number of cells in func_closure.  All other
        func attributes (e.g. func_globals) are empty.
    """
    #build closure (cells):
    if not ctypes:
        raise Exception('ctypes failed to import; cannot build function')

    cellnew = ctypes.pythonapi.PyCell_New
    cellnew.restype = ctypes.py_object
    cellnew.argtypes = (ctypes.py_object,)
    dummy_closure = tuple(map(lambda i: cellnew(None), range(num_closures)))

    if base_globals is None:
        base_globals = {}
    base_globals['__builtins__'] = __builtins__

    return types.FunctionType(code, base_globals,
                              None, None, dummy_closure)

# this piece of opaque code is needed below to modify 'cell' contents 
開發者ID:adobe-research,項目名稱:spark-cluster-deployment,代碼行數:24,代碼來源:cloudpickle.py

示例2: _make_skel_func

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import __builtins__ [as 別名]
def _make_skel_func(code, cell_count, base_globals=None):
    """ Creates a skeleton function object that contains just the provided
        code and the correct number of cells in func_closure.  All other
        func attributes (e.g. func_globals) are empty.
    """
    if base_globals is None:
        base_globals = {}
    base_globals['__builtins__'] = __builtins__

    closure = (
        tuple(_make_empty_cell() for _ in range(cell_count))
        if cell_count >= 0 else
        None
    )
    return types.FunctionType(code, base_globals, None, None, closure) 
開發者ID:FederatedAI,項目名稱:FATE,代碼行數:17,代碼來源:cloudpickle.py

示例3: save_dict

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import __builtins__ [as 別名]
def save_dict(self, obj):
        """hack fix
        If the dict is a global, deal with it in a special way
        """
        #print 'saving', obj
        if obj is __builtins__:
            self.save_reduce(_get_module_builtins, (), obj=obj)
        else:
            pickle.Pickler.save_dict(self, obj) 
開發者ID:adobe-research,項目名稱:spark-cluster-deployment,代碼行數:11,代碼來源:cloudpickle.py

示例4: _make_skel_func

# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import __builtins__ [as 別名]
def _make_skel_func(code, cell_count, base_globals=None):
  """ Creates a skeleton function object that contains just the provided
      code and the correct number of cells in func_closure.  All other
      func attributes (e.g. func_globals) are empty.
  """
  if base_globals is None:
    base_globals = {}
  base_globals['__builtins__'] = __builtins__

  closure = (
    tuple(_make_empty_cell() for _ in range(cell_count))
    if cell_count >= 0 else
    None
  )
  return types.FunctionType(code, base_globals, None, None, closure) 
開發者ID:WeBankFinTech,項目名稱:eggroll,代碼行數:17,代碼來源:cloudpickle.py


注:本文中的pickle.__builtins__方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。