<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> import contextlib <EOL> from . dill import PY3 <EOL> @ contextlib . contextmanager <EOL> def capture ( stream = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> import sys <EOL> if PY3 : <EOL> from io import StringIO <EOL> else : <EOL> from StringIO import StringIO <EOL> orig = getattr ( sys , stream ) <EOL> setattr ( sys , stream , StringIO ( ) ) <EOL> try : <EOL> yield getattr ( sys , stream ) <EOL> finally : <EOL> setattr ( sys , stream , orig ) <EOL> def b ( x ) : <EOL> import codecs <EOL> return codecs . latin_1_encode ( x ) [ <NUM_LIT:0> ] <EOL> def load_source ( file , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> alias = kwds . pop ( '<STR_LIT>' , None ) <EOL> mode = kwds . pop ( '<STR_LIT>' , '<STR_LIT:r>' ) <EOL> fname = getattr ( file , '<STR_LIT:name>' , file ) <EOL> source = open ( fname , mode = mode , ** kwds ) . read ( ) <EOL> if not alias : <EOL> tag = source . strip ( ) . splitlines ( ) [ - <NUM_LIT:1> ] . split ( ) <EOL> if tag [ <NUM_LIT:0> ] != '<STR_LIT>' : <EOL> stub = source . splitlines ( ) [ <NUM_LIT:0> ] <EOL> raise IOError ( "<STR_LIT>" % stub ) <EOL> alias = tag [ - <NUM_LIT:1> ] <EOL> local = { } <EOL> exec ( source , local ) <EOL> _ = eval ( "<STR_LIT:%s>" % alias , local ) <EOL> return _ <EOL> def dump_source ( object , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> from . source import importable , getname <EOL> import tempfile <EOL> kwds . pop ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> alias = kwds . pop ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> name = str ( alias ) or getname ( object ) <EOL> name = "<STR_LIT>" % name <EOL> file = tempfile . NamedTemporaryFile ( suffix = '<STR_LIT>' , ** kwds ) <EOL> file . write ( b ( '<STR_LIT>' . join ( [ importable ( object , alias = alias ) , name ] ) ) ) <EOL> file . flush ( ) <EOL> return file <EOL> def load ( file , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> import dill as pickle <EOL> mode = kwds . pop ( '<STR_LIT>' , '<STR_LIT:rb>' ) <EOL> name = getattr ( file , '<STR_LIT:name>' , file ) <EOL> return pickle . load ( open ( name , mode = mode , ** kwds ) ) <EOL> def dump ( object , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> import dill as pickle <EOL> import tempfile <EOL> file = tempfile . NamedTemporaryFile ( ** kwds ) <EOL> pickle . dump ( object , file ) <EOL> file . flush ( ) <EOL> return file <EOL> def loadIO ( buffer , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> import dill as pickle <EOL> if PY3 : <EOL> from io import BytesIO as StringIO <EOL> else : <EOL> from StringIO import StringIO <EOL> value = getattr ( buffer , '<STR_LIT>' , buffer ) <EOL> if value != buffer : value = value ( ) <EOL> return pickle . load ( StringIO ( value ) ) <EOL> def dumpIO ( object , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> import dill as pickle <EOL> if PY3 : <EOL> from io import BytesIO as StringIO <EOL> else : <EOL> from StringIO import StringIO <EOL> file = StringIO ( ) <EOL> pickle . dump ( object , file ) <EOL> file . flush ( ) <EOL> return file <EOL> def loadIO_source ( buffer , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> alias = kwds . pop ( '<STR_LIT>' , None ) <EOL> source = getattr ( buffer , '<STR_LIT>' , buffer ) <EOL> if source != buffer : source = source ( ) <EOL> if PY3 : source = source . decode ( ) <EOL> if not alias : <EOL> tag = source . strip ( ) . splitlines ( ) [ - <NUM_LIT:1> ] . split ( ) <EOL> if tag [ <NUM_LIT:0> ] != '<STR_LIT>' : <EOL> stub = source . splitlines ( ) [ <NUM_LIT:0> ] <EOL> raise IOError ( "<STR_LIT>" % stub ) <EOL> alias = tag [ - <NUM_LIT:1> ] <EOL> local = { } <EOL> exec ( source , local ) <EOL> _ = eval ( "<STR_LIT:%s>" % alias , local ) <EOL> return _ <EOL> def dumpIO_source ( object , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> from . source import importable , getname <EOL> if PY3 : <EOL> from io import BytesIO as StringIO <EOL> else : <EOL> from StringIO import StringIO <EOL> alias = kwds . pop ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> name = str ( alias ) or getname ( object ) <EOL> name = "<STR_LIT>" % name <EOL> file = StringIO ( ) <EOL> file . write ( b ( '<STR_LIT>' . join ( [ importable ( object , alias = alias ) , name ] ) ) ) <EOL> file . flush ( ) <EOL> return file <EOL> del absolute_import , contextlib </s>
