1- #!/usr/bin/env python
1+ """
2+ Vendoring of pickleshare, reduced to used functionalities.
3+
4+ ---
25
3- """ PickleShare - a small 'shelve' like datastore with concurrency support
6+ PickleShare - a small 'shelve' like datastore with concurrency support
47
58Like shelve, a PickleShareDB object acts like a normal dictionary. Unlike
69shelve, many processes can access the database simultaneously. Changing a
3336
3437"""
3538
36- from __future__ import print_function
37-
38-
3939__version__ = "0.7.5"
4040
41- try :
42- from pathlib import Path
43- except ImportError :
44- # Python 2 backport
45- from pathlib2 import Path
41+ from pathlib import Path
42+
4643
4744import os , stat , time
4845
5754import errno
5855import sys
5956
60- if sys .version_info [0 ] >= 3 :
61- string_types = (str ,)
62- else :
63- string_types = (str , unicode )
64-
6557
6658def gethashfile (key ):
6759 return ("%02x" % abs (hash (key ) % 256 ))[- 2 :]
@@ -75,7 +67,7 @@ class PickleShareDB(collections_abc.MutableMapping):
7567
7668 def __init__ (self , root ):
7769 """Return a db object that will manage the specied directory"""
78- if not isinstance (root , string_types ):
70+ if not isinstance (root , str ):
7971 root = str (root )
8072 root = os .path .abspath (os .path .expanduser (root ))
8173 self .root = Path (root )
@@ -309,53 +301,3 @@ def __repr__(self):
309301 self .__dict__ ["keydir" ],
310302 ";" .join ([Path (k ).basename () for k in keys ]),
311303 )
312-
313-
314- def main ():
315- import textwrap
316-
317- usage = textwrap .dedent (
318- """\
319- pickleshare - manage PickleShare databases
320-
321- Usage:
322-
323- pickleshare dump /path/to/db > dump.txt
324- pickleshare load /path/to/db < dump.txt
325- pickleshare test /path/to/db
326- """
327- )
328- DB = PickleShareDB
329- import sys
330-
331- if len (sys .argv ) < 2 :
332- print (usage )
333- return
334-
335- cmd = sys .argv [1 ]
336- args = sys .argv [2 :]
337- if cmd == "dump" :
338- if not args :
339- args = ["." ]
340- db = DB (args [0 ])
341- import pprint
342-
343- pprint .pprint (db .items ())
344- elif cmd == "load" :
345- cont = sys .stdin .read ()
346- db = DB (args [0 ])
347- data = eval (cont )
348- db .clear ()
349- for k , v in db .items ():
350- db [k ] = v
351- elif cmd == "testwait" :
352- db = DB (args [0 ])
353- db .clear ()
354- print (db .waitget ("250" ))
355- elif cmd == "test" :
356- test ()
357- stress ()
358-
359-
360- if __name__ == "__main__" :
361- main ()
0 commit comments