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


Python dispatch_table.get方法代碼示例

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


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

示例1: load

# 需要導入模塊: from copy_reg import dispatch_table [as 別名]
# 或者: from copy_reg.dispatch_table 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: copy

# 需要導入模塊: from copy_reg import dispatch_table [as 別名]
# 或者: from copy_reg.dispatch_table import get [as 別名]
def copy(x):
    """Shallow copy operation on arbitrary Python objects.

    See the module's __doc__ string for more info.
    """

    cls = type(x)

    copier = _copy_dispatch.get(cls)
    if copier:
        return copier(x)

    copier = getattr(cls, "__copy__", None)
    if copier:
        return copier(x)

    reductor = dispatch_table.get(cls)
    if reductor:
        rv = reductor(x)
    else:
        reductor = getattr(x, "__reduce_ex__", None)
        if reductor:
            rv = reductor(2)
        else:
            reductor = getattr(x, "__reduce__", None)
            if reductor:
                rv = reductor()
            else:
                raise Error("un(shallow)copyable object of type %s" % cls)

    return _reconstruct(x, rv, 0) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:33,代碼來源:copy.py

示例3: get

# 需要導入模塊: from copy_reg import dispatch_table [as 別名]
# 或者: from copy_reg.dispatch_table 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

示例4: save_global

# 需要導入模塊: from copy_reg import dispatch_table [as 別名]
# 或者: from copy_reg.dispatch_table 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

示例5: get_extension

# 需要導入模塊: from copy_reg import dispatch_table [as 別名]
# 或者: from copy_reg.dispatch_table import get [as 別名]
def get_extension(self, code):
        nil = []
        obj = _extension_cache.get(code, nil)
        if obj is not nil:
            self.append(obj)
            return
        key = _inverted_registry.get(code)
        if not key:
            raise ValueError("unregistered extension code %d" % code)
        obj = self.find_class(*key)
        _extension_cache[code] = obj
        self.append(obj) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:14,代碼來源:pickle.py


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