ok

Mini Shell

Direktori : /proc/self/root/opt/alt/python33/lib64/python3.3/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python33/lib64/python3.3/__pycache__/shelve.cpython-33.pyo

�
nyMa3 c@s�dZddlmZmZddlmZddlZddddgZGd	d
�d
ej�Z	Gdd�dej�Z
Gdd�de
�ZGd
d�de
�Zddddd�ZdS(u�
Manage shelves of pickled objects.

A "shelf" is a persistent, dictionary-like object.  The difference
with dbm databases is that the values (not the keys!) in a shelf can
be essentially arbitrary Python objects -- anything that the "pickle"
module can handle.  This includes most class instances, recursive data
types, and objects containing lots of shared sub-objects.  The keys
are ordinary strings.

To summarize the interface (key is a string, data is an arbitrary
object):

        import shelve
        d = shelve.open(filename) # open, with (g)dbm filename -- no suffix

        d[key] = data   # store data at key (overwrites old data if
                        # using an existing key)
        data = d[key]   # retrieve a COPY of the data at key (raise
                        # KeyError if no such key) -- NOTE that this
                        # access returns a *copy* of the entry!
        del d[key]      # delete data stored at key (raises KeyError
                        # if no such key)
        flag = key in d # true if the key exists
        list = d.keys() # a list of all existing keys (slow!)

        d.close()       # close it

Dependent on the implementation, closing a persistent dictionary may
or may not be necessary to flush changes to disk.

Normally, d[key] returns a COPY of the entry.  This needs care when
mutable entries are mutated: for example, if d[key] is a list,
        d[key].append(anitem)
does NOT modify the entry d[key] itself, as stored in the persistent
mapping -- it only modifies the copy, which is then immediately
discarded, so that the append has NO effect whatsoever.  To append an
item to d[key] in a way that will affect the persistent mapping, use:
        data = d[key]
        data.append(anitem)
        d[key] = data

To avoid the problem with mutable entries, you may pass the keyword
argument writeback=True in the call to shelve.open.  When you use:
        d = shelve.open(filename, writeback=True)
then d keeps a cache of all entries you access, and writes them all back
to the persistent mapping when you call d.close().  This ensures that
such usage as d[key].append(anitem) works as intended.

However, using keyword argument writeback=True may consume vast amount
of memory for the cache, and it may make d.close() very slow, if you
access many of d's entries after opening it in this way: d has no way to
check which of the entries you access are mutable and/or which ones you
actually mutate, so it must cache, and write back at close, all of the
entries that you access.  You can call d.sync() to write back all the
entries in the cache, and empty the cache (d.sync() also synchronizes
the persistent dictionary on disk, if feasible).
i(uPickleru	Unpickler(uBytesIONuShelfu
BsdDbShelfuDbfilenameShelfuopencBsL|EeZdZdZdd�ZeZZZZZ	Z
dd�ZdS(u_ClosedDictu>Marker for a closed dict.  Access attempts raise a ValueError.cGstd��dS(Nu!invalid operation on closed shelf(u
ValueError(uselfuargs((u+/opt/alt/python33/lib64/python3.3/shelve.pyuclosedEsu_ClosedDict.closedcCsdS(Nu<Closed Dictionary>((uself((u+/opt/alt/python33/lib64/python3.3/shelve.pyu__repr__Isu_ClosedDict.__repr__N(u__name__u
__module__u__qualname__u__doc__uclosedu__iter__u__len__u__getitem__u__setitem__u__delitem__ukeysu__repr__(u
__locals__((u+/opt/alt/python33/lib64/python3.3/shelve.pyu_ClosedDictBsu_ClosedDictcBs�|EeZdZdZddddd�Zdd�Zdd�Zd	d
�Z	ddd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS(uShelfu�Base class for shelf implementations.

    This is initialized with a dictionary-like object.
    See the module's __doc__ string for an overview of the interface.
    uutf-8cCsF||_|dkrd}n||_||_i|_||_dS(Ni(udictuNoneu	_protocolu	writebackucacheukeyencoding(uselfudictuprotocolu	writebackukeyencoding((u+/opt/alt/python33/lib64/python3.3/shelve.pyu__init__Ts					uShelf.__init__ccs/x(|jj�D]}|j|j�VqWdS(N(udictukeysudecodeukeyencoding(uselfuk((u+/opt/alt/python33/lib64/python3.3/shelve.pyu__iter__^suShelf.__iter__cCs
t|j�S(N(ulenudict(uself((u+/opt/alt/python33/lib64/python3.3/shelve.pyu__len__bsu
Shelf.__len__cCs|j|j�|jkS(N(uencodeukeyencodingudict(uselfukey((u+/opt/alt/python33/lib64/python3.3/shelve.pyu__contains__esuShelf.__contains__cCs'|j|j�|jkr#||S|S(N(uencodeukeyencodingudict(uselfukeyudefault((u+/opt/alt/python33/lib64/python3.3/shelve.pyugethsu	Shelf.getcCsty|j|}Wn\tk
rot|j|j|j��}t|�j�}|jrk||j|<nYnX|S(N(	ucacheuKeyErroruBytesIOudictuencodeukeyencodingu	Unpickleruloadu	writeback(uselfukeyuvalueuf((u+/opt/alt/python33/lib64/python3.3/shelve.pyu__getitem__ms
	uShelf.__getitem__cCsd|jr||j|<nt�}t||j�}|j|�|j�|j|j|j	�<dS(N(
u	writebackucacheuBytesIOuPickleru	_protocoludumpugetvalueudictuencodeukeyencoding(uselfukeyuvalueufup((u+/opt/alt/python33/lib64/python3.3/shelve.pyu__setitem__ws		
uShelf.__setitem__cCs=|j|j|j�=y|j|=Wntk
r8YnXdS(N(udictuencodeukeyencodingucacheuKeyError(uselfukey((u+/opt/alt/python33/lib64/python3.3/shelve.pyu__delitem__s

uShelf.__delitem__cCsh|j�y|jj�Wntk
r/YnXyt�|_Wn!ttfk
rcd|_YnXdS(N(usyncudictucloseuAttributeErroru_ClosedDictu	NameErroru	TypeErroruNone(uself((u+/opt/alt/python33/lib64/python3.3/shelve.pyuclose�s

uShelf.closecCs!t|d�sdS|j�dS(Nu	writeback(uhasattruclose(uself((u+/opt/alt/python33/lib64/python3.3/shelve.pyu__del__�su
Shelf.__del__cCs�|jrZ|jrZd|_x'|jj�D]\}}|||<q+Wd|_i|_nt|jd�r||jj�ndS(NusyncFT(u	writebackucacheuFalseuitemsuTrueuhasattrudictusync(uselfukeyuentry((u+/opt/alt/python33/lib64/python3.3/shelve.pyusync�s		u
Shelf.syncNF(u__name__u
__module__u__qualname__u__doc__uNoneuFalseu__init__u__iter__u__len__u__contains__ugetu__getitem__u__setitem__u__delitem__ucloseu__del__usync(u
__locals__((u+/opt/alt/python33/lib64/python3.3/shelve.pyuShelfMs	

cBsk|EeZdZdZddddd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�ZdS(u
BsdDbShelfu�Shelf implementation using the "BSD" db interface.

    This adds methods first(), next(), previous(), last() and
    set_location() that have no counterpart in [g]dbm databases.

    The actual database must be opened using one of the "bsddb"
    modules "open" routines (i.e. bsddb.hashopen, bsddb.btopen or
    bsddb.rnopen) and passed to the constructor.

    See the module's __doc__ string for an overview of the interface.
    uutf-8cCstj|||||�dS(N(uShelfu__init__(uselfudictuprotocolu	writebackukeyencoding((u+/opt/alt/python33/lib64/python3.3/shelve.pyu__init__�suBsdDbShelf.__init__cCsF|jj|�\}}t|�}|j|j�t|�j�fS(N(udictuset_locationuBytesIOudecodeukeyencodingu	Unpickleruload(uselfukeyuvalueuf((u+/opt/alt/python33/lib64/python3.3/shelve.pyuset_location�suBsdDbShelf.set_locationcCsCt|j�\}}t|�}|j|j�t|�j�fS(N(unextudictuBytesIOudecodeukeyencodingu	Unpickleruload(uselfukeyuvalueuf((u+/opt/alt/python33/lib64/python3.3/shelve.pyunext�suBsdDbShelf.nextcCsC|jj�\}}t|�}|j|j�t|�j�fS(N(udictupreviousuBytesIOudecodeukeyencodingu	Unpickleruload(uselfukeyuvalueuf((u+/opt/alt/python33/lib64/python3.3/shelve.pyuprevious�suBsdDbShelf.previouscCsC|jj�\}}t|�}|j|j�t|�j�fS(N(udictufirstuBytesIOudecodeukeyencodingu	Unpickleruload(uselfukeyuvalueuf((u+/opt/alt/python33/lib64/python3.3/shelve.pyufirst�suBsdDbShelf.firstcCsC|jj�\}}t|�}|j|j�t|�j�fS(N(udictulastuBytesIOudecodeukeyencodingu	Unpickleruload(uselfukeyuvalueuf((u+/opt/alt/python33/lib64/python3.3/shelve.pyulast�suBsdDbShelf.lastNF(u__name__u
__module__u__qualname__u__doc__uNoneuFalseu__init__uset_locationunextupreviousufirstulast(u
__locals__((u+/opt/alt/python33/lib64/python3.3/shelve.pyu
BsdDbShelf�scBs/|EeZdZdZddddd�ZdS(uDbfilenameShelfu�Shelf implementation using the "dbm" generic dbm interface.

    This is initialized with the filename for the dbm database.
    See the module's __doc__ string for an overview of the interface.
    uccCs2ddl}tj||j||�||�dS(Ni(udbmuShelfu__init__uopen(uselfufilenameuflaguprotocolu	writebackudbm((u+/opt/alt/python33/lib64/python3.3/shelve.pyu__init__�suDbfilenameShelf.__init__NF(u__name__u
__module__u__qualname__u__doc__uNoneuFalseu__init__(u
__locals__((u+/opt/alt/python33/lib64/python3.3/shelve.pyuDbfilenameShelf�succCst||||�S(uOpen a persistent dictionary for reading and writing.

    The filename parameter is the base filename for the underlying
    database.  As a side-effect, an extension may be added to the
    filename and more than one file may be created.  The optional flag
    parameter has the same interpretation as the flag parameter of
    dbm.open(). The optional protocol parameter specifies the
    version of the pickle protocol (0, 1, or 2).

    See the module's __doc__ string for an overview of the interface.
    (uDbfilenameShelf(ufilenameuflaguprotocolu	writeback((u+/opt/alt/python33/lib64/python3.3/shelve.pyuopen�s
F(u__doc__upickleuPickleru	UnpickleruiouBytesIOucollectionsu__all__uMutableMappingu_ClosedDictuShelfu
BsdDbShelfuDbfilenameShelfuNoneuFalseuopen(((u+/opt/alt/python33/lib64/python3.3/shelve.pyu<module>9sW+

Zerion Mini Shell 1.0