diff options
author | Jhon Honce <jhonce@redhat.com> | 2018-05-24 13:44:04 -0700 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-05-25 09:31:21 +0000 |
commit | 0a4ade1c175d3188ad55d22d751a86c96e060a44 (patch) | |
tree | 9bfb3414119e931fd715c6d3002c0e357fce7e18 /contrib/python/podman/libs/__init__.py | |
parent | 684b544e9c45129a3d8112cfab22526440d8fd13 (diff) | |
download | podman-0a4ade1c175d3188ad55d22d751a86c96e060a44.tar.gz podman-0a4ade1c175d3188ad55d22d751a86c96e060a44.tar.bz2 podman-0a4ade1c175d3188ad55d22d751a86c96e060a44.zip |
Implement python podman create and start
- Added alias 'container()' to image model for CreateContainer()
- Fixed return in containers_create.go to wrap error in varlink
exception
- Added a wait time to container.kill(), number of seconds to wait
for the container to change state
- Refactored cached_property() to use system libraries
- Refactored tests to speed up performance
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Closes: #821
Approved by: rhatdan
Diffstat (limited to 'contrib/python/podman/libs/__init__.py')
-rw-r--r-- | contrib/python/podman/libs/__init__.py | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/contrib/python/podman/libs/__init__.py b/contrib/python/podman/libs/__init__.py index 7285921d7..9db5dacf5 100644 --- a/contrib/python/podman/libs/__init__.py +++ b/contrib/python/podman/libs/__init__.py @@ -1,8 +1,8 @@ """Support files for podman API implementation.""" import datetime -import threading -from dateutil.parser import parse as dateutil_parse +import functools +from dateutil.parser import parse as dateutil_parse __all__ = [ 'cached_property', @@ -11,37 +11,28 @@ __all__ = [ ] -class cached_property(object): - """cached_property() - computed once per instance, cached as attribute. +def cached_property(fn): + """Cache return to save future expense.""" + return property(functools.lru_cache(maxsize=8)(fn)) - Maybe this will make a future version of python. - """ - def __init__(self, func): - """Construct context manager.""" - self.func = func - self.__doc__ = func.__doc__ - self.lock = threading.RLock() - - def __get__(self, instance, cls=None): - """Retrieve previous value, or call func().""" - if instance is None: - return self - - attrname = self.func.__name__ - try: - cache = instance.__dict__ - except AttributeError: # objects with __slots__ have no __dict__ - msg = ("No '__dict__' attribute on {}" - " instance to cache {} property.").format( - repr(type(instance).__name__), repr(attrname)) - raise TypeError(msg) from None - - with self.lock: - # check if another thread filled cache while we awaited lock - if attrname not in cache: - cache[attrname] = self.func(instance) - return cache[attrname] +# Cannot subclass collections.UserDict, breaks varlink +class Config(dict): + """Silently ignore None values, only take key once.""" + + def __init__(self, **kwargs): + """Construct dictionary.""" + super(Config, self).__init__(kwargs) + + def __setitem__(self, key, value): + """Store unique, not None values.""" + if value is None: + return + + if super().__contains__(key): + return + + super().__setitem__(key, value) def datetime_parse(string): |