mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-20 18:26:43 +00:00
Compare commits
No commits in common. "f914759b7126a9d2dae9037234e22fa557f50ba8" and "b845d9629581d72c717006d602a96421d6e9919c" have entirely different histories.
f914759b71
...
b845d96295
@ -160,10 +160,6 @@ def _sqlite_type(value):
|
|||||||
def _serialize(value):
|
def _serialize(value):
|
||||||
if isinstance(value, bytes):
|
if isinstance(value, bytes):
|
||||||
return base64.b64encode(value)
|
return base64.b64encode(value)
|
||||||
if value is None:
|
|
||||||
return None
|
|
||||||
if isinstance(value, bool):
|
|
||||||
return value
|
|
||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,16 +11,13 @@ last_time_called = dict()
|
|||||||
|
|
||||||
def retry(attempts, callback=None):
|
def retry(attempts, callback=None):
|
||||||
def decorate(func):
|
def decorate(func):
|
||||||
def wrapper(*args, **kwargs):
|
retries = attempts
|
||||||
retries = attempts
|
while retries > 0:
|
||||||
while retries > 0:
|
try:
|
||||||
try:
|
func()
|
||||||
return func(*args, **kwargs)
|
except Exception as e:
|
||||||
except Exception as e:
|
if callback:
|
||||||
if callback:
|
callback(e)
|
||||||
callback(e)
|
|
||||||
retries -= 1
|
|
||||||
return wrapper
|
|
||||||
return decorate
|
return decorate
|
||||||
|
|
||||||
|
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="hexlib",
|
name="hexlib",
|
||||||
version="1.23",
|
version="1.20",
|
||||||
description="Misc utility methods",
|
description="Misc utility methods",
|
||||||
author="simon987",
|
author="simon987",
|
||||||
author_email="me@simon987.net",
|
author_email="me@simon987.net",
|
||||||
|
@ -47,31 +47,3 @@ class TestPersistentState(TestCase):
|
|||||||
val["id"] = 1
|
val["id"] = 1
|
||||||
|
|
||||||
self.assertDictEqual(val, s["a"][1])
|
self.assertDictEqual(val, s["a"][1])
|
||||||
|
|
||||||
def test_none(self):
|
|
||||||
s = PersistentState()
|
|
||||||
|
|
||||||
val = {"a": 1, "b": None}
|
|
||||||
s["a"][1] = val
|
|
||||||
s["a"][1] = {
|
|
||||||
"a": None
|
|
||||||
}
|
|
||||||
|
|
||||||
val["a"] = None
|
|
||||||
val["id"] = 1
|
|
||||||
|
|
||||||
self.assertDictEqual(val, s["a"][1])
|
|
||||||
|
|
||||||
def test_bool(self):
|
|
||||||
s = PersistentState()
|
|
||||||
|
|
||||||
val = {"a": True, "b": False}
|
|
||||||
s["a"][1] = val
|
|
||||||
s["a"][1] = {
|
|
||||||
"a": True
|
|
||||||
}
|
|
||||||
|
|
||||||
val["a"] = True
|
|
||||||
val["id"] = 1
|
|
||||||
|
|
||||||
self.assertDictEqual(val, s["a"][1])
|
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
from unittest import TestCase
|
|
||||||
from hexlib.db import VolatileState, VolatileBooleanState
|
|
||||||
from hexlib.misc import retry
|
|
||||||
|
|
||||||
|
|
||||||
class TestRetry(TestCase):
|
|
||||||
|
|
||||||
def test_simple(self):
|
|
||||||
@retry(attempts=3)
|
|
||||||
def a(i):
|
|
||||||
return i + 1
|
|
||||||
|
|
||||||
self.assertEqual(a(1), 2)
|
|
||||||
|
|
||||||
def test_error(self):
|
|
||||||
arr = []
|
|
||||||
|
|
||||||
def cb(e):
|
|
||||||
arr.append(e)
|
|
||||||
|
|
||||||
@retry(attempts=3, callback=cb)
|
|
||||||
def a(i):
|
|
||||||
raise Exception("err")
|
|
||||||
|
|
||||||
a(1)
|
|
||||||
|
|
||||||
self.assertEqual(3, len(arr))
|
|
Loading…
x
Reference in New Issue
Block a user