|
53 | 53 | import warnings |
54 | 54 |
|
55 | 55 | from privex.helpers.common import * |
56 | | -from privex.helpers.collections import * |
57 | | -from privex.helpers.decorators import * |
58 | | -from privex.helpers.net import * |
| 56 | + |
| 57 | +log = logging.getLogger(__name__) |
| 58 | + |
| 59 | + |
| 60 | +class _Dummy: |
| 61 | + def __init__(self): |
| 62 | + self.dummydata = {} |
| 63 | + |
| 64 | + def __getattr__(self, item): |
| 65 | + try: |
| 66 | + return object.__getattribute__(self, item) |
| 67 | + except AttributeError: |
| 68 | + pass |
| 69 | + try: |
| 70 | + if item in object.__getattribute__(self, 'dummydata'): |
| 71 | + return object.__getattribute__(self, 'dummydata')[item] |
| 72 | + except AttributeError: |
| 73 | + pass |
| 74 | + |
| 75 | + return lambda *args, **kwargs: None |
| 76 | + |
| 77 | + def __setattr__(self, key, value): |
| 78 | + if key == 'dummydata': |
| 79 | + return object.__setattr__(self, key, value) |
| 80 | + m = object.__getattribute__(self, 'dummydata') |
| 81 | + m[key] = value |
| 82 | + |
| 83 | + def __getitem__(self, item): |
| 84 | + try: |
| 85 | + return self.__getattr__(item) |
| 86 | + except AttributeError as ex: |
| 87 | + raise KeyError(str(ex)) |
| 88 | + |
| 89 | + def __setitem__(self, key, value): |
| 90 | + try: |
| 91 | + self.__setattr__(key, value) |
| 92 | + except AttributeError as ex: |
| 93 | + raise KeyError(str(ex)) |
| 94 | + |
| 95 | +try: |
| 96 | + from privex.helpers.collections import * |
| 97 | +except ImportError as e: |
| 98 | + log.warning( |
| 99 | + 'privex.helpers __init__ failed to import "%s", not loading %s module. reason: %s %s', |
| 100 | + 'privex.helpers.collections', 'collections', type(e), str(e) |
| 101 | + ) |
| 102 | + |
| 103 | +try: |
| 104 | + from privex.helpers.decorators import * |
| 105 | +except ImportError as e: |
| 106 | + log.warning( |
| 107 | + 'privex.helpers __init__ failed to import "%s", not loading %s module. reason: %s %s', |
| 108 | + 'privex.helpers.decorators', 'decorators', type(e), str(e) |
| 109 | + ) |
| 110 | +try: |
| 111 | + from privex.helpers.net import * |
| 112 | +except ImportError as e: |
| 113 | + log.warning( |
| 114 | + 'privex.helpers __init__ failed to import "%s", not loading %s module. reason: %s %s', |
| 115 | + 'privex.helpers.net', 'net', type(e), str(e) |
| 116 | + ) |
| 117 | + |
59 | 118 | from privex.helpers.exceptions import * |
60 | | -from privex.helpers.plugin import * |
61 | | -from privex.helpers.cache import CacheNotFound, CacheAdapter, CacheWrapper, MemoryCache, cached |
62 | 119 |
|
63 | | -from privex.helpers import plugin |
| 120 | +try: |
| 121 | + from privex.helpers.cache import CacheNotFound, CacheAdapter, CacheWrapper, MemoryCache, cached |
| 122 | +except ImportError as e: |
| 123 | + log.warning( |
| 124 | + 'privex.helpers __init__ failed to import "%s", not loading %s module. reason: %s %s', |
| 125 | + 'privex.helpers.cache', 'cache', type(e), str(e) |
| 126 | + ) |
| 127 | + # noinspection PyTypeChecker |
| 128 | + CacheNotFound, CacheAdapter, CacheWrapper, MemoryCache, cached = _Dummy(), _Dummy(), _Dummy(), _Dummy(), _Dummy() |
64 | 129 |
|
65 | | -log = logging.getLogger(__name__) |
66 | 130 |
|
| 131 | +try: |
| 132 | + from privex.helpers import plugin |
| 133 | + from privex.helpers.plugin import * |
| 134 | +except ImportError as e: |
| 135 | + log.warning( |
| 136 | + 'privex.helpers __init__ failed to import "%s", not loading %s module. reason: %s %s', |
| 137 | + 'privex.helpers.plugin', 'plugin', type(e), str(e) |
| 138 | + ) |
| 139 | + # noinspection PyTypeChecker |
| 140 | + plugin = _Dummy() |
67 | 141 |
|
68 | 142 | try: |
69 | 143 | from privex.helpers.cache.RedisCache import RedisCache |
|
78 | 152 | except ImportError: |
79 | 153 | log.debug('privex.helpers __init__ failed to import "MemcachedCache", not loading MemcachedCache') |
80 | 154 |
|
| 155 | +try: |
| 156 | + from privex.helpers.cache.SqliteCache import SqliteCache |
| 157 | +except ImportError: |
| 158 | + log.debug('privex.helpers __init__ failed to import "SqliteCache", not loading SqliteCache') |
| 159 | + |
81 | 160 | try: |
82 | 161 | from privex.helpers.cache.asyncx import * |
83 | 162 | except ImportError: |
@@ -160,7 +239,10 @@ def _setup_logging(level=logging.WARNING): |
160 | 239 | log = _setup_logging() |
161 | 240 | name = 'helpers' |
162 | 241 |
|
163 | | -VERSION = '3.2.0' |
| 242 | +from privex.helpers import version as _version_mod |
| 243 | + |
| 244 | +VERSION = _version_mod.VERSION |
| 245 | + |
164 | 246 |
|
165 | 247 |
|
166 | 248 |
|
0 commit comments