mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-12 13:12:35 +01:00
Use a monotonic time for registry cache.
So an old cache does not take precedence over a newly set value.
I noticed this bug because of the time going backward in tests
because of the time.time mock introduced in
dcf55cf6de
, but this may happen
in production systems too.
Also adds another deprecation warning for python < 3.3.
This commit is contained in:
parent
702cfaaf97
commit
8b2cbbc583
5
setup.py
5
setup.py
@ -267,5 +267,10 @@ if sys.version_info < (3, 0):
|
|||||||
'bug at <https://github.com/ProgVal/Limnoria/issues> and we\'ll '
|
'bug at <https://github.com/ProgVal/Limnoria/issues> and we\'ll '
|
||||||
'see together what we can do about it.',
|
'see together what we can do about it.',
|
||||||
DeprecationWarning)
|
DeprecationWarning)
|
||||||
|
if sys.version_info < (3, 3):
|
||||||
|
warnings.warn('You are installing Limnoria for Python < 3.3, which is '
|
||||||
|
'only partially support. Limnoria requires Python 3.4 or later '
|
||||||
|
'to be fully stable.',
|
||||||
|
DeprecationWarning)
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
@ -70,6 +70,12 @@ ENCODING = 'string_escape' if minisix.PY2 else 'unicode_escape'
|
|||||||
decoder = codecs.getdecoder(ENCODING)
|
decoder = codecs.getdecoder(ENCODING)
|
||||||
encoder = codecs.getencoder(ENCODING)
|
encoder = codecs.getencoder(ENCODING)
|
||||||
|
|
||||||
|
if hasattr(time, 'monotonic'):
|
||||||
|
monotonic_time = time.monotonic
|
||||||
|
else:
|
||||||
|
# fallback for python < 3.3
|
||||||
|
monotonic_time = time.time
|
||||||
|
|
||||||
_cache = utils.InsensitivePreservingDict()
|
_cache = utils.InsensitivePreservingDict()
|
||||||
_lastModified = 0
|
_lastModified = 0
|
||||||
def open_registry(filename, clear=False):
|
def open_registry(filename, clear=False):
|
||||||
@ -105,7 +111,7 @@ def open_registry(filename, clear=False):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise InvalidRegistryFile('Error unpacking line %r' % acc)
|
raise InvalidRegistryFile('Error unpacking line %r' % acc)
|
||||||
_cache[key] = value
|
_cache[key] = value
|
||||||
_lastModified = time.time()
|
_lastModified = monotonic_time()
|
||||||
_fd.close()
|
_fd.close()
|
||||||
|
|
||||||
CONF_FILE_HEADER = """
|
CONF_FILE_HEADER = """
|
||||||
@ -435,7 +441,7 @@ class Value(Group):
|
|||||||
if self._name == 'unset':
|
if self._name == 'unset':
|
||||||
self._lastModified = 0
|
self._lastModified = 0
|
||||||
self.__parent.setName(*args)
|
self.__parent.setName(*args)
|
||||||
self._lastModified = time.time()
|
self._lastModified = monotonic_time()
|
||||||
|
|
||||||
def set(self, s):
|
def set(self, s):
|
||||||
"""Override this with a function to convert a string to whatever type
|
"""Override this with a function to convert a string to whatever type
|
||||||
@ -456,7 +462,7 @@ class Value(Group):
|
|||||||
inherited=True means the value is inherited from the parent, so if
|
inherited=True means the value is inherited from the parent, so if
|
||||||
the parent gets a new value, this group will get the new value as
|
the parent gets a new value, this group will get the new value as
|
||||||
well."""
|
well."""
|
||||||
self._lastModified = time.time()
|
self._lastModified = monotonic_time()
|
||||||
self.value = v
|
self.value = v
|
||||||
if self._supplyDefault:
|
if self._supplyDefault:
|
||||||
for (name, child) in list(self._children.items()):
|
for (name, child) in list(self._children.items()):
|
||||||
|
@ -87,7 +87,6 @@ def timeFastForward(extra_offset):
|
|||||||
mock_time_offset += extra_offset
|
mock_time_offset += extra_offset
|
||||||
|
|
||||||
def setupMockTime():
|
def setupMockTime():
|
||||||
mock_time_offset = 0
|
|
||||||
time.time = mockTime
|
time.time = mockTime
|
||||||
|
|
||||||
def teardownMockTime():
|
def teardownMockTime():
|
||||||
|
Loading…
Reference in New Issue
Block a user