当前位置: 首页>>代码示例>>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;未经允许,请勿转载。