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


Python _extension_registry.get方法代碼示例

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


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

示例1: load

# 需要導入模塊: from copy_reg import _extension_registry [as 別名]
# 或者: from copy_reg._extension_registry import get [as 別名]
def load(self):
        """Read a pickled object representation from the open file.

        Return the reconstituted object hierarchy specified in the file.
        """
        self.mark = object() # any new unique object
        self.stack = []
        self.append = self.stack.append
        read = self.read
        dispatch = self.dispatch
        try:
            while 1:
                key = read(1)
                dispatch[key](self)
        except _Stop, stopinst:
            return stopinst.value

    # Return largest index k such that self.stack[k] is self.mark.
    # If the stack doesn't contain a mark, eventually raises IndexError.
    # This could be sped by maintaining another stack, of indices at which
    # the mark appears.  For that matter, the latter stack would suffice,
    # and we wouldn't need to push mark objects on self.stack at all.
    # Doing so is probably a good thing, though, since if the pickle is
    # corrupt (or hostile) we may get a clue from finding self.mark embedded
    # in unpickled objects. 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:27,代碼來源:pickle.py

示例2: get

# 需要導入模塊: from copy_reg import _extension_registry [as 別名]
# 或者: from copy_reg._extension_registry import get [as 別名]
def get(self, i, pack=struct.pack):
        if self.bin:
            if i < 256:
                return BINGET + chr(i)
            else:
                return LONG_BINGET + pack("<i", i)

        return GET + repr(i) + '\n' 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:10,代碼來源:pickle.py

示例3: save_global

# 需要導入模塊: from copy_reg import _extension_registry [as 別名]
# 或者: from copy_reg._extension_registry import get [as 別名]
def save_global(self, obj, name=None, pack=struct.pack):
        write = self.write
        memo = self.memo

        if name is None:
            name = obj.__name__

        module = getattr(obj, "__module__", None)
        if module is None:
            module = whichmodule(obj, name)

        try:
            __import__(module)
            mod = sys.modules[module]
            klass = getattr(mod, name)
        except (ImportError, KeyError, AttributeError):
            raise PicklingError(
                "Can't pickle %r: it's not found as %s.%s" %
                (obj, module, name))
        else:
            if klass is not obj:
                raise PicklingError(
                    "Can't pickle %r: it's not the same object as %s.%s" %
                    (obj, module, name))

        if self.proto >= 2:
            code = _extension_registry.get((module, name))
            if code:
                assert code > 0
                if code <= 0xff:
                    write(EXT1 + chr(code))
                elif code <= 0xffff:
                    write("%c%c%c" % (EXT2, code&0xff, code>>8))
                else:
                    write(EXT4 + pack("<i", code))
                return

        write(GLOBAL + module + '\n' + name + '\n')
        self.memoize(obj) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:41,代碼來源:pickle.py

示例4: whichmodule

# 需要導入模塊: from copy_reg import _extension_registry [as 別名]
# 或者: from copy_reg._extension_registry import get [as 別名]
def whichmodule(func, funcname):
    """Figure out the module in which a function occurs.

    Search sys.modules for the module.
    Cache in classmap.
    Return a module name.
    If the function cannot be found, return "__main__".
    """
    # Python functions should always get an __module__ from their globals.
    mod = getattr(func, "__module__", None)
    if mod is not None:
        return mod
    if func in classmap:
        return classmap[func]

    for name, module in sys.modules.items():
        if module is None:
            continue # skip dummy package entries
        if name != '__main__' and getattr(module, funcname, None) is func:
            break
    else:
        name = '__main__'
    classmap[func] = name
    return name


# Unpickling machinery 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:29,代碼來源:pickle.py


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