from os.path import exists, join from os import listdir, remove, makedirs from stuf.base import backport quote_plus = backport('urllib.quote_plus', 'urllib.parse.quote_plus') unquote_plus = backport('urllib.unquote_plus', 'urllib.parse.unquote_plus') class FileDict(): '''Base for file based storage.''' def __init__(self, dir, **kw): self._dir = dir # Create directory if not exists(self._dir): self._createdir() def __getitem__(self, key): # (per Larry Meyn) try: with open(self._key_to_file(key), 'rb') as item: return item.read() except (IOError, OSError): raise KeyError(key) def __setitem__(self, key, value): # (per Larry Meyn) # try: with open(self._key_to_file(key), 'wb') as item: item.write(value) # except (IOError, OSError): # raise KeyError(key)
# -*- coding: utf-8 -*- '''shove compatibility shim for different python versions.''' from stuf.six import PY3 from stuf.base import backport anydbm = backport('anydbm', 'dbm') url2pathname = backport('urllib.url2pathname', 'urllib.request.url2pathname') urlsplit = backport('urlparse.urlsplit', 'urllib.parse.urlsplit') quote_plus = backport('urllib.quote_plus', 'urllib.parse.quote_plus') unquote_plus = backport('urllib.unquote_plus', 'urllib.parse.unquote_plus') def synchronized(func): ''' Decorator to lock and unlock a method (Phillip J. Eby). :argument func: method to decorate ''' def wrapper(self, *__args, **__kw): self._lock.acquire() try: return func(self, *__args, **__kw) finally: self._lock.release() wrapper.__name__ = func.__name__ wrapper.__dict__ = func.__dict__ wrapper.__doc__ = func.__doc__ return wrapper
from os.path import exists, join from os import listdir, remove, makedirs from stuf.base import backport quote_plus = backport("urllib.quote_plus", "urllib.parse.quote_plus") unquote_plus = backport("urllib.unquote_plus", "urllib.parse.unquote_plus") class FileDict: """Base for file based storage.""" def __init__(self, dir, **kw): self._dir = dir # Create directory if not exists(self._dir): self._createdir() def __getitem__(self, key): # (per Larry Meyn) try: with open(self._key_to_file(key), "rb") as item: return item.read() except (IOError, OSError): raise KeyError(key) def __setitem__(self, key, value): # (per Larry Meyn) # try: with open(self._key_to_file(key), "wb") as item: item.write(value)
# -*- coding: utf-8 -*- '''shove compatibility shim for different python versions.''' from stuf.six import PY3 from stuf.base import backport import urllib.request as urlReq anydbm = backport('anydbm', 'dbm') # url2pathname = backport('urllib.url2pathname', 'urllib.request.url2pathname') url2pathname = urlReq.url2pathname urlsplit = backport('urlparse.urlsplit', 'urllib.parse.urlsplit') quote_plus = backport('urllib.quote_plus', 'urllib.parse.quote_plus') unquote_plus = backport('urllib.unquote_plus', 'urllib.parse.unquote_plus') def synchronized(func): ''' Decorator to lock and unlock a method (Phillip J. Eby). :argument func: method to decorate ''' def wrapper(self, *__args, **__kw): self._lock.acquire() try: return func(self, *__args, **__kw) finally: self._lock.release() wrapper.__name__ = func.__name__ wrapper.__dict__ = func.__dict__ wrapper.__doc__ = func.__doc__ return wrapper
# -*- coding: utf-8 -*- """shove compatibility shim for different python versions.""" from stuf.six import PY3 from stuf.base import backport anydbm = backport("anydbm", "dbm") url2pathname = backport("urllib.url2pathname", "urllib.request.url2pathname") urlsplit = backport("urlparse.urlsplit", "urllib.parse.urlsplit") quote_plus = backport("urllib.quote_plus", "urllib.parse.quote_plus") unquote_plus = backport("urllib.unquote_plus", "urllib.parse.unquote_plus") StringIO = backport("stuf.six.moves.StringIO") def synchronized(func): """ Decorator to lock and unlock a method (Phillip J. Eby). :argument func: method to decorate """ def wrapper(self, *__args, **__kw): self._lock.acquire() try: return func(self, *__args, **__kw) finally: self._lock.release() wrapper.__name__ = func.__name__ wrapper.__dict__ = func.__dict__ wrapper.__doc__ = func.__doc__
# -*- coding: utf-8 -*- '''Utilities for writing code that runs on Python 2 and 3.''' from stuf.base import first, docit, identity, getframe, backport, norm import sys import types from functools import partial from importlib import import_module from operator import attrgetter, methodcaller, lt, gt from .base import isfactory intern = backport('__builtin__.intern', 'sys.intern') OrderedDict = backport('collections.OrderedDict', 'ordereddict.OrderedDict') unittest = backport('unittest2', 'unittest') get_ident = backport( 'thread.get_ident', 'dummy_thread.get_ident', '_thread.get_ident', ) pickle = backport('cPickle', 'pickle') filter = backport('future_builtins.filter', 'builtins.filter') map = backport('future_builtins.map', 'builtins.map') zip = backport('future_builtins.zip', 'builtins.zip') # use next generation regular expression library if available rcompile = backport('regex.compile', 're.compile') rescape = backport('regex.escape', 're.escape') rsub = backport('regex.sub', 're.sub') subprocess = backport('subprocess32.Popen', 'subprocess.Popen') # True if we are running on Python 3. PY3 = first(sys.version_info) == 3
# -*- coding: utf-8 -*- """Utilities for writing code that runs on Python 2 and 3.""" from stuf.base import first, docit, identity, getframe, backport, norm import sys import types from functools import partial from importlib import import_module from operator import attrgetter, methodcaller, lt, gt from .base import isfactory intern = backport("__builtin__.intern", "sys.intern") OrderedDict = backport("collections.OrderedDict", "ordereddict.OrderedDict") unittest = backport("unittest2", "unittest") get_ident = backport("thread.get_ident", "dummy_thread.get_ident", "_thread.get_ident") pickle = backport("cPickle", "pickle") filter = backport("future_builtins.filter", "builtins.filter") map = backport("future_builtins.map", "builtins.map") zip = backport("future_builtins.zip", "builtins.zip") # use next generation regular expression library if available rcompile = backport("regex.compile", "re.compile") rescape = backport("regex.escape", "re.escape") rsub = backport("regex.sub", "re.sub") subprocess = backport("subprocess32.Popen", "subprocess.Popen") # True if we are running on Python 3. PY3 = first(sys.version_info) == 3 if PY3: