Ejemplo n.º 1
0
Archivo: dill.py Proyecto: brstrat/dill
def save_module_dict(pickler, obj):
    if is_dill(pickler) and obj == pickler._main.__dict__ and not pickler._session:
        log.info("D1: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        if PY3:
            pickler.write(bytes('c__builtin__\n__main__\n', 'UTF-8'))
        else:
            pickler.write('c__builtin__\n__main__\n')
        log.info("# D1")
    elif not is_dill(pickler) and obj == _main_module.__dict__:
        log.info("D3: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        if PY3:
            pickler.write(bytes('c__main__\n__dict__\n', 'UTF-8'))
        else:
            pickler.write('c__main__\n__dict__\n')   #XXX: works in general?
        log.info("# D3")
    elif '__name__' in obj and obj != _main_module.__dict__ \
    and obj is getattr(_import_module(obj['__name__'],True), '__dict__', None):
        log.info("D4: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        if PY3:
            pickler.write(bytes('c%s\n__dict__\n' % obj['__name__'], 'UTF-8'))
        else:
            pickler.write('c%s\n__dict__\n' % obj['__name__'])
        log.info("# D4")
    else:
        log.info("D2: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        if is_dill(pickler) and pickler._session:
            # we only care about session the first pass thru
            pickler._session = False
        StockPickler.save_dict(pickler, obj)
        log.info("# D2")
    return
Ejemplo n.º 2
0
def save_module_dict(pickler, obj):
    if is_dill(pickler) and obj == pickler._main_module.__dict__ and not pickler._session:
        log.info("D1: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        if PY3:
            pickler.write(bytes('c__builtin__\n__main__\n', 'UTF-8'))
        else:
            pickler.write('c__builtin__\n__main__\n')
    elif not is_dill(pickler) and obj == _main_module.__dict__:
        log.info("D3: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        if PY3:
            pickler.write(bytes('c__main__\n__dict__\n', 'UTF-8'))
        else:
            pickler.write('c__main__\n__dict__\n')   #XXX: works in general?
    elif '__name__' in obj and obj != _main_module.__dict__ \
    and obj is getattr(_import_module(obj['__name__'],True), '__dict__', None):
        log.info("D4: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        if PY3:
            pickler.write(bytes('c%s\n__dict__\n' % obj['__name__'], 'UTF-8'))
        else:
            pickler.write('c%s\n__dict__\n' % obj['__name__'])
    else:
        log.info("D2: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        if is_dill(pickler) and pickler._session:
            # we only care about session the first pass thru
            pickler._session = False 
        StockPickler.save_dict(pickler, obj)
    return
Ejemplo n.º 3
0
def save_module_dict(pickler, obj):
    if is_dill(pickler) and obj == pickler._main.__dict__ and not pickler._session:
        log.info("D1: <dict%s" % str(obj.__repr__).split("dict")[-1])  # obj
        if PY3:
            pickler.write(bytes("c__builtin__\n__main__\n", "UTF-8"))
        else:
            pickler.write("c__builtin__\n__main__\n")
        log.info("# D1")
    elif not is_dill(pickler) and obj == _main_module.__dict__:
        log.info("D3: <dict%s" % str(obj.__repr__).split("dict")[-1])  # obj
        if PY3:
            pickler.write(bytes("c__main__\n__dict__\n", "UTF-8"))
        else:
            pickler.write("c__main__\n__dict__\n")  # XXX: works in general?
        log.info("# D3")
    elif (
        "__name__" in obj
        and obj != _main_module.__dict__
        and obj is getattr(_import_module(obj["__name__"], True), "__dict__", None)
    ):
        log.info("D4: <dict%s" % str(obj.__repr__).split("dict")[-1])  # obj
        if PY3:
            pickler.write(bytes("c%s\n__dict__\n" % obj["__name__"], "UTF-8"))
        else:
            pickler.write("c%s\n__dict__\n" % obj["__name__"])
        log.info("# D4")
    else:
        log.info("D2: <dict%s" % str(obj.__repr__).split("dict")[-1])  # obj
        if is_dill(pickler) and pickler._session:
            # we only care about session the first pass thru
            pickler._session = False
        StockPickler.save_dict(pickler, obj)
        log.info("# D2")
    return
Ejemplo n.º 4
0
Archivo: dill.py Proyecto: wxiang7/dill
def save_module_dict(pickler, obj):
    if is_dill(pickler) and obj == pickler._main.__dict__:
        log.info("D1: <dict%s" % str(obj.__repr__).split('dict')[-1])  # obj
        pickler.write_lines('c__builtin__\n__main__\n')
        log.info("# D1 <dict%s" % str(obj.__repr__).split('dict')[-1])
    elif is_dill(pickler) and obj == __builtin__.__dict__:
        log.info("D6: <dict%s" % str(obj.__repr__).split('dict')[-1])  # obj
        pickler.write('c__builtin__\n__dict__\n')
        log.info("# D6 <dict%s" % str(obj.__repr__).split('dict')[-1])
    elif not is_dill(pickler) and obj == _main_module.__dict__:
        log.info("D3: <dict%s" % str(obj.__repr__).split('dict')[-1])  # obj
        pickler.write('c__main__\n__dict__\n')
        log.info("# D3 <dict%s" % str(obj.__repr__).split('dict')[-1])
    elif '__name__' in obj and obj != _main_module.__dict__ \
            and obj is getattr(_importable(obj['__name__'], True), '__dict__', None) \
            and '__file__' in obj and _from_ship_path(obj['__file__'], pickler.ship_path):
        log.info("D5: <dict%s" % str(obj.__repr__).split('dict')[-1])  # obj
        StockPickler.save_dict(pickler, obj)
        log.info("# D5 <dict%s" % str(obj.__repr__).split('dict')[-1])
    elif '__name__' in obj and obj != _main_module.__dict__ \
            and obj is getattr(_importable(obj['__name__'], True), '__dict__', None):
        log.info("D4: <dict%s" % str(obj.__repr__).split('dict')[-1])  # obj
        pickler.write('c%s\n__dict__\n' % obj['__name__'])
        log.info("# D4 <dict%s" % str(obj.__repr__).split('dict')[-1])
    else:
        log.info("D2: <dict%s" % str(obj.__repr__).split('dict')[-1])  # obj
        StockPickler.save_dict(pickler, obj)
        log.info("# D2 <dict%s" % str(obj.__repr__).split('dict')[-1])
    return
Ejemplo n.º 5
0
Archivo: dill.py Proyecto: numpand/dill
def save_module_dict(pickler, obj):
    if is_dill(pickler) and obj is pickler._main_module.__dict__:
        log.info("D1: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        if PYTHON3:
            pickler.write(bytes('c__builtin__\n__main__\n', 'UTF-8'))
        else:
            pickler.write('c__builtin__\n__main__\n')
    elif not is_dill(pickler) and obj is _main_module.__dict__:
        log.info("D3: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        if PYTHON3:
            pickler.write(bytes('c__main__\n__dict__\n', 'UTF-8'))
        else:
            pickler.write('c__main__\n__dict__\n')   #XXX: works in general?
    else:
        log.info("D2: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        StockPickler.save_dict(pickler, obj)
    return
Ejemplo n.º 6
0
def save_module_dict(pickler, obj):
    if is_dill(pickler) and obj == pickler._main_module.__dict__:
        log.info("D1: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        if PYTHON3:
            pickler.write(bytes('c__builtin__\n__main__\n', 'UTF-8'))
        else:
            pickler.write('c__builtin__\n__main__\n')
    elif not is_dill(pickler) and obj == _main_module.__dict__:
        log.info("D3: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        if PYTHON3:
            pickler.write(bytes('c__main__\n__dict__\n', 'UTF-8'))
        else:
            pickler.write('c__main__\n__dict__\n')   #XXX: works in general?
    elif '__name__' in obj and obj != _main_module.__dict__ \
    and obj is getattr(_import_module(obj['__name__'],True), '__dict__', None):
        log.info("D4: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        if PYTHON3:
            pickler.write(bytes('c%s\n__dict__\n' % obj['__name__'], 'UTF-8'))
        else:
            pickler.write('c%s\n__dict__\n' % obj['__name__'])
    else:
        log.info("D2: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
        StockPickler.save_dict(pickler, obj)
    return