/usr/lib64/python3.9
NameSizeModeActions
asyncio/-0755rm
collections/-0755rm
concurrent/-0755rm
config-3.9-x86_64-linux-gnu/-0755rm
ctypes/-0755rm
curses/-0755rm
dbm/-0755rm
distutils/-0755rm
email/-0755rm
encodings/-0755rm
ensurepip/-0755rm
html/-0755rm
http/-0755rm
importlib/-0755rm
json/-0755rm
lib-dynload/-0755rm
lib2to3/-0755rm
logging/-0755rm
multiprocessing/-0755rm
pydoc_data/-0755rm
site-packages/-0755rm
sqlite3/-0755rm
unittest/-0755rm
urllib/-0755rm
venv/-0755rm
wsgiref/-0755rm
xml/-0755rm
xmlrpc/-0755rm
zoneinfo/-0755rm
__pycache__/-0755rm
abc.py49200644editdlrm
aifc.py326050644editdlrm
antigravity.py5000644editdlrm
argparse.py981190644editdlrm
ast.py562560644editdlrm
asynchat.py113210644editdlrm
asyncore.py201020644editdlrm
base64.py198590755editdlrm
bdb.py313890644editdlrm
binhex.py147840644editdlrm
bisect.py23500644editdlrm
bz2.py124470644editdlrm
calendar.py248320644editdlrm
cgi.py339320755editdlrm
cgitb.py120960644editdlrm
chunk.py54350644editdlrm
cmd.py148600644editdlrm
code.py106220644editdlrm
codecs.py366730644editdlrm
codeop.py63260644editdlrm
colorsys.py40640644editdlrm
compileall.py201050644editdlrm
configparser.py545840644editdlrm
contextlib.py246240644editdlrm
contextvars.py1290644editdlrm
copy.py86500644editdlrm
copyreg.py72740644editdlrm
cProfile.py63450755editdlrm
crypt.py38190644editdlrm
csv.py161440644editdlrm
dataclasses.py495860644editdlrm
datetime.py891770644editdlrm
decimal.py3200644editdlrm
difflib.py833070644editdlrm
dis.py205700644editdlrm
doctest.py1045680644editdlrm
enum.py394400644editdlrm
filecmp.py100240644editdlrm
fileinput.py147910644editdlrm
fnmatch.py60040644editdlrm
formatter.py151430644editdlrm
fractions.py243230644editdlrm
ftplib.py354960644editdlrm
functools.py388810644editdlrm
genericpath.py52460644editdlrm
getopt.py74890644editdlrm
getpass.py59900644editdlrm
gettext.py272660644editdlrm
glob.py58230644editdlrm
graphlib.py95730644editdlrm
gzip.py217720644editdlrm
hashlib.py80690644editdlrm
heapq.py228770644editdlrm
hmac.py80430644editdlrm
imaplib.py552560644editdlrm
imghdr.py38080644editdlrm
imp.py105360644editdlrm
inspect.py1182350644editdlrm
io.py35410644editdlrm
ipaddress.py809240644editdlrm
keyword.py10470644editdlrm
LICENSE.txt139370644editdlrm
linecache.py54610644editdlrm
locale.py782710644editdlrm
lzma.py132310644editdlrm
mailbox.py787940644editdlrm
mailcap.py91160644editdlrm
mimetypes.py215640644editdlrm
modulefinder.py244010644editdlrm
netrc.py55660644editdlrm
nntplib.py410230644editdlrm
ntpath.py264600644editdlrm
nturl2path.py28870644editdlrm
numbers.py103380644editdlrm
opcode.py56600644editdlrm
operator.py107510644editdlrm
optparse.py603690644editdlrm
os.py390650644editdlrm
pathlib.py511340644editdlrm
pdb.py632370755editdlrm
pickle.py649200644editdlrm
pickletools.py934860644editdlrm
pipes.py89160644editdlrm
pkgutil.py242760644editdlrm
platform.py406010755editdlrm
plistlib.py282480644editdlrm
poplib.py151980644editdlrm
posixpath.py161460644editdlrm
pprint.py225270644editdlrm
profile.py228810755editdlrm
pstats.py293260644editdlrm
pty.py48070644editdlrm
pyclbr.py152550644editdlrm
pydoc.py1095990755editdlrm
py_compile.py82030644editdlrm
queue.py114960644editdlrm
quopri.py72660755editdlrm
random.py314840644editdlrm
re.py158610644editdlrm
reprlib.py52670644editdlrm
rlcompleter.py76480644editdlrm
runpy.py130840644editdlrm
sched.py64420644editdlrm
secrets.py20360644editdlrm
selectors.py195360644editdlrm
shelve.py85270644editdlrm
shlex.py135010644editdlrm
shutil.py530300644editdlrm
signal.py24380644editdlrm
site.py220850644editdlrm
smtpd.py348210755editdlrm
smtplib.py454050755editdlrm
sndhdr.py70990644editdlrm
socket.py369150644editdlrm
socketserver.py272960644editdlrm
sre_compile.py279730644editdlrm
sre_constants.py71770644editdlrm
sre_parse.py407790644editdlrm
ssl.py526220644editdlrm
stat.py54850644editdlrm
statistics.py380670644editdlrm
string.py105660644editdlrm
stringprep.py129170644editdlrm
struct.py2570644editdlrm
subprocess.py835640644editdlrm
sunau.py181580644editdlrm
symbol.py22810644editdlrm
symtable.py79050644editdlrm
sysconfig.py255570644editdlrm
tabnanny.py114060755editdlrm
tarfile.py1129390755editdlrm
telnetlib.py232540644editdlrm
tempfile.py279630644editdlrm
textwrap.py194070644editdlrm
this.py10030644editdlrm
threading.py541760644editdlrm
timeit.py134800755editdlrm
token.py23680644editdlrm
tokenize.py258830644editdlrm
trace.py292070755editdlrm
traceback.py246600644editdlrm
tracemalloc.py180470644editdlrm
tty.py8790644editdlrm
types.py97850644editdlrm
typing.py770440644editdlrm
uu.py72770644editdlrm
uuid.py273240644editdlrm
warnings.py196880644editdlrm
wave.py180040644editdlrm
weakref.py215600644editdlrm
webbrowser.py240830755editdlrm
xdrlib.py59130644editdlrm
zipapp.py75350644editdlrm
zipfile.py888990644editdlrm
zipimport.py307650644editdlrm
_aix_support.py33890644editdlrm
_bootlocale.py18010644editdlrm
_bootsubprocess.py26750644editdlrm
_collections_abc.py293740644editdlrm
_compat_pickle.py87490644editdlrm
_compression.py53400644editdlrm
_markupbase.py146230644editdlrm
_osx_support.py217730644editdlrm
_pydecimal.py2286660644editdlrm
_pyio.py933160644editdlrm
_py_abc.py61890644editdlrm
_sitebuiltins.py31150644editdlrm
_strptime.py252770644editdlrm
_sysconfigdata__linux_x86_64-linux-gnu.py412360644editdlrm
_threading_local.py72200644editdlrm
_weakrefset.py59230644editdlrm
__future__.py51470644editdlrm
__phello__.foo.py640644editdlrm
Edit: /usr/lib64/python3.9/shelve.py (8527B)
"""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). """ from pickle import Pickler, Unpickler from io import BytesIO import collections.abc __all__ = ["Shelf", "BsdDbShelf", "DbfilenameShelf", "open"] class _ClosedDict(collections.abc.MutableMapping): 'Marker for a closed dict. Access attempts raise a ValueError.' def closed(self, *args): raise ValueError('invalid operation on closed shelf') __iter__ = __len__ = __getitem__ = __setitem__ = __delitem__ = keys = closed def __repr__(self): return '' class Shelf(collections.abc.MutableMapping): """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. """ def __init__(self, dict, protocol=None, writeback=False, keyencoding="utf-8"): self.dict = dict if protocol is None: protocol = 3 self._protocol = protocol self.writeback = writeback self.cache = {} self.keyencoding = keyencoding def __iter__(self): for k in self.dict.keys(): yield k.decode(self.keyencoding) def __len__(self): return len(self.dict) def __contains__(self, key): return key.encode(self.keyencoding) in self.dict def get(self, key, default=None): if key.encode(self.keyencoding) in self.dict: return self[key] return default def __getitem__(self, key): try: value = self.cache[key] except KeyError: f = BytesIO(self.dict[key.encode(self.keyencoding)]) value = Unpickler(f).load() if self.writeback: self.cache[key] = value return value def __setitem__(self, key, value): if self.writeback: self.cache[key] = value f = BytesIO() p = Pickler(f, self._protocol) p.dump(value) self.dict[key.encode(self.keyencoding)] = f.getvalue() def __delitem__(self, key): del self.dict[key.encode(self.keyencoding)] try: del self.cache[key] except KeyError: pass def __enter__(self): return self def __exit__(self, type, value, traceback): self.close() def close(self): if self.dict is None: return try: self.sync() try: self.dict.close() except AttributeError: pass finally: # Catch errors that may happen when close is called from __del__ # because CPython is in interpreter shutdown. try: self.dict = _ClosedDict() except: self.dict = None def __del__(self): if not hasattr(self, 'writeback'): # __init__ didn't succeed, so don't bother closing # see http://bugs.python.org/issue1339007 for details return self.close() def sync(self): if self.writeback and self.cache: self.writeback = False for key, entry in self.cache.items(): self[key] = entry self.writeback = True self.cache = {} if hasattr(self.dict, 'sync'): self.dict.sync() class BsdDbShelf(Shelf): """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. """ def __init__(self, dict, protocol=None, writeback=False, keyencoding="utf-8"): Shelf.__init__(self, dict, protocol, writeback, keyencoding) def set_location(self, key): (key, value) = self.dict.set_location(key) f = BytesIO(value) return (key.decode(self.keyencoding), Unpickler(f).load()) def next(self): (key, value) = next(self.dict) f = BytesIO(value) return (key.decode(self.keyencoding), Unpickler(f).load()) def previous(self): (key, value) = self.dict.previous() f = BytesIO(value) return (key.decode(self.keyencoding), Unpickler(f).load()) def first(self): (key, value) = self.dict.first() f = BytesIO(value) return (key.decode(self.keyencoding), Unpickler(f).load()) def last(self): (key, value) = self.dict.last() f = BytesIO(value) return (key.decode(self.keyencoding), Unpickler(f).load()) class DbfilenameShelf(Shelf): """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. """ def __init__(self, filename, flag='c', protocol=None, writeback=False): import dbm Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback) def open(filename, flag='c', protocol=None, writeback=False): """Open 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. See the module's __doc__ string for an overview of the interface. """ return DbfilenameShelf(filename, flag, protocol, writeback)