Current File : //usr/lib64/python2.7/site-packages/numpy/numarray/session.pyo
�
E�`Qc@sSdZddgZddlZddlZdZead�Zee�ee�ed�fZ
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zddd��YZdefd��YZd�Zdefd��YZdefd��YZdefd��YZd�Zdeded�Zdeded�Zd�ZdS(s� This module contains a "session saver" which saves the state of a
NumPy session to a file.  At a later time, a different Python
process can be started and the saved session can be restored using
load().

The session saver relies on the Python pickle protocol to save and
restore objects.  Objects which are not themselves picklable (e.g.
modules) can sometimes be saved by "proxy",  particularly when they
are global constants of some kind.  If it's not known that proxying
will work,  a warning is issued at save time.  If a proxy fails to
reload properly (e.g. because it's not a global constant),  a warning
is issued at reload time and that name is bound to a _ProxyFailure
instance which tries to identify what should have been restored.

First, some unfortunate (probably unnecessary) concessions to doctest
to keep the test run free of warnings.

>>> del _PROXY_ALLOWED
>>> del __builtins__

By default, save() stores every variable in the caller's namespace:

>>> import numpy as na
>>> a = na.arange(10)
>>> save()

Alternately,  save() can be passed a comma seperated string of variables:

>>> save("a,na")

Alternately,  save() can be passed a dictionary, typically one you already
have lying around somewhere rather than created inline as shown here:

>>> save(dictionary={"a":a,"na":na})

If both variables and a dictionary are specified, the variables to be
saved are taken from the dictionary.

>>> save(variables="a,na",dictionary={"a":a,"na":na})

Remove names from the session namespace

>>> del a, na

By default, load() restores every variable/object in the session file
to the caller's namespace.

>>> load()

load() can be passed a comma seperated string of variables to be
restored from the session file to the caller's namespace:

>>> load("a,na")

load() can also be passed a dictionary to *restore to*:

>>> d = {}
>>> load(dictionary=d)

load can be passed both a list variables of variables to restore and a
dictionary to restore to:

>>> load(variables="a,na", dictionary=d)

>>> na.all(a == na.arange(10))
1
>>> na.__name__
'numpy'

NOTE:  session saving is faked for modules using module proxy objects.
Saved modules are re-imported at load time but any "state" in the module
which is not restored by a simple import is lost.

tloadtsavei����Nssession.datcCsdS(N((((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt_fooTscCsdS(s?Suppress warnings for known un-picklables with working proxies.N((((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt_update_proxy_typesZscCs|dk	o|tkS(s1returns True iff _type isn't known as OK to proxyN(tNonet_PROXY_ALLOWED(t_type((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt_unknown^scCs*yddWntjjjjjSXdS(s;caller() returns the frame object of the function's caller.itN(tsyst
exc_tracebackttb_frametf_back(((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt_callerhscCst�}|jS(s>callers_globals() returns the global dictionary of the caller.(R
t	f_globals(tframe((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt_callers_globalsos	cCsat�}g}xK|j�D]=\}}t|�tt�kr|jt|d��qqW|S(s\returns a list containing the names of all the modules in the caller's
    global namespace.t__name__(RtitemsttypeR	tappendtgetattr(tgtmodstktv((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt_callers_modulests	cGs)x|D]}tj|IqWtjJdS(N(R	tstderr(targsta((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt_errout~s
cGstrt|�ndS(N(tVERBOSER(R((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt_verbose�st_ProxyingFailurecBs#eZdZdd�Zd�ZRS(sMObject which is bound to a variable for a proxy pickle which failed to reloadcCs||_||_||_dS(N(tmoduletnameR(tselfR"R#R((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt__init__�s		cCsd|j|j|jfS(NsProxyingFailure('%s','%s','%s')(R"R#R(R$((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt__repr__�sN(Rt
__module__t__doc__RR%R&(((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR!�st_ModuleProxycBs,eZdZed�Zd�Zd�ZRS(s*Proxy object which fakes pickling a modulecCss|r.td|�tj|�}||_nAtd|�yt|�}Wn!tk
rntd|d�nX|S(Nsproxying modulesloading module proxyswarning: modulesimport failed.(R tobjectt__new__R#t_loadmoduletImportErrorR(RR#RR$((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR+�s


cCs
|jfS(N(R#(R$((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt__getnewargs__�scCstS(N(tFalse(R$((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt__getstate__�s(RR'R(R/R+R.R0(((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR)�s
	cBsr|ejkrg|jd�}d}x@ee|��D])}dj||d �}d|dUq7Wnej|S(Nt.Risimport (R	tmodulestsplittrangetlentjoin(R"R2tsti((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR,�st_ObjectProxycBs,eZdZed�Zd�Zd�ZRS(shProxy object which fakes pickling an arbitrary object.  Only global
    constants can really be proxied.cCs-|r{t|�r6td|d|d|dd�ntd||�tj|�}||t|�|_|_|_n�td||�yt	|�}Wn<t
tfk
r�td|d|d	�t|||�SXyt
||�}Wn9tk
r(td
|d|d|�t|||�SX|S(Nswarning: proxying objectR1sof typesbecause it wouldn't pickle...sit may not reload later.sproxying objectsloading object proxyswarning: loading object proxysmodule import failed.swarning: object proxyswouldn't reload from(RRR R*R+tstrR"R#RR,R-tKeyErrorR!RtAttributeError(RR"R#t_type2RR$tm((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR+�s,	
&

cCs|j|j|jfS(N(R"R#R(R$((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR.�scCstS(N(R/(R$((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR0�s(RR'R(R/R+R.R0(((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR9�s	t_SaveSessioncBs,eZdZed�Zd�Zd�ZRS(s�Tag object which marks the end of a save session and holds the
    saved session variable names as a list of strings in the same
    order as the session pickles.cCs?|rtd|�n
td|�tj|�}||_|S(Nssaving sessionsloading session(R R*R+tkeys(RR@RR$((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR+�s
	cCs
|jfS(N(R@(R$((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR.�scCstS(N(R/(R$((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR0�s(RR'R(R/R+R.R0(((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR?�s		tObjectNotFoundcBseZRS((RR'(((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyRA�scCspxi|D]U}tj|}|rx9|jj�D]%\}}||kr0|j|fSq0WqqWt|��dS(N(R	R2t__dict__RRRA(R2R*tmnameR>RR((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt_locate�s

c
Cs�|at�t|t�r.t|d�}n|dkrFt�}n|dkra|j�}n|jd�}t	�t
jj�}tj
|dd�}td|�x|D]�}||}td|t|��y|j|�td|�Wq�tjttfk
r�t|tt
��r<t|jdt�}	n^yt||�\}
}Wn$tk
r{td	|d
�q�nXt|
|t|�dt�}	|j|	�q�Xq�Wt|dt�}|j|�|j�dS(s�saves variables from a numpy session to a file.  Variables
    which won't pickle are "proxied" if possible.

    'variables'       a string of comma seperated variables: e.g. "a,b,c"
                      Defaults to dictionary.keys().

    'file'            a filename or file object for the session file.

    'dictionary'      the dictionary in which to look up the variables.
                      Defaults to the caller's globals()

    'verbose'         print additional debug output when True.
    twbt,tprotocolis
variables:tsavingtpickledRswarning: couldn't find objectsin any module... skipping.N(RRt
isinstanceR:topenRRR@R3RR	R2tpickletPicklerR Rtdumpt
PicklingErrort	TypeErrortSystemErrorR)RtTrueRDRARR9R?tclose(
t	variablestfilet
dictionarytverboseR@tsource_modulestpRRtproxyR"R#to((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR�s@




	
c
Cs|at|t�r't|d�}n|dkr?t�}ng}tj|�}x�|j�}t|t	�r�t
t|j|��}t
d�|dkr�|j�}n|jd�}x|D]}	||	||	<q�WdSt
dt|��|j|�qWdS(s�load a numpy session from a file and store the specified
    'variables' into 'dictionary'.

    'variables'       a string of comma seperated variables: e.g. "a,b,c"
                      Defaults to dictionary.keys().

    'file'            a filename or file object for the session file.

    'dictionary'      the dictionary in which to look up the variables.
                      Defaults to the caller's globals()

    'verbose'         print additional debug output when True.
    trbs+updating dictionary with session variables.RFsunpickled objectN(RRJR:RKRRRLt	UnpicklerRR?tdicttzipR@R R3R(
RTRURVRWtvaluesRYR[tsessionR@R((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyR/s(

cCs+ddl}ddl}|j|jj�S(Ni����(tdoctesttnumpy.numarray.sessionttestmodtnumarrayRa(Rbtnumpy((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyttestXs((R(t__all__R	RLtSAVEFILER/RRRRRRRR
RRRR R!R*R)R,R9R?tRuntimeErrorRARDRRRg(((s</usr/lib64/python2.7/site-packages/numpy/numarray/session.pyt<module>Js4					
			
					$	
=)