From 3fbdbcc0f44a51aef08ac2f2720c0e513c92650c Mon Sep 17 00:00:00 2001 From: Cqk Date: Sat, 10 Mar 2018 19:51:28 +0800 Subject: [PATCH] small fixes in README and sth else --- README.md | 2 +- README.rst | 2 +- cannondb/__init__.py | 2 +- cannondb/serializer.py | 8 +++----- cannondb/wrapper.py | 5 +++-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4ff73ed..80883a9 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ db = cannondb.connect(log='local') # use tcp/udp mode # host and port must be specified. -db = cannondb.connect(log='tcp', host=127.0.0.1, port=2048) +db = cannondb.connect(log='tcp', host='127.0.0.1', port=2048) ``` ###### Do not forget to close db when exit. diff --git a/README.rst b/README.rst index 1cbe9af..4c7490a 100644 --- a/README.rst +++ b/README.rst @@ -145,7 +145,7 @@ logging # use tcp/udp mode # host and port must be specified. - db = cannondb.connect(log='tcp', host=127.0.0.1, port=2048) + db = cannondb.connect(log='tcp', host='127.0.0.1', port=2048) Do not forget to close db when exit. diff --git a/cannondb/__init__.py b/cannondb/__init__.py index c183f71..9817907 100644 --- a/cannondb/__init__.py +++ b/cannondb/__init__.py @@ -3,7 +3,7 @@ from cannondb.storages import FileStorage, MemoryStorage from cannondb.wrapper import log_wrapper -__version__ = '1.1.0' +__version__ = '1.1.1' __all__ = ('CannonDB', 'FileStorage', 'MemoryStorage') diff --git a/cannondb/serializer.py b/cannondb/serializer.py index 6d0428c..0999827 100644 --- a/cannondb/serializer.py +++ b/cannondb/serializer.py @@ -87,13 +87,11 @@ def deserialize(data: bytes) -> dict: 0: int, 1: float, 2: str, - 3: dict, - int: 0, - float: 1, - str: 2, - dict: 3 + 3: dict } +type_num_map.update(dict(zip(type_num_map.values(), type_num_map.keys()))) + def serializer_switcher(t: Type[Union[int, float, str, dict]]) -> Serializer: """return corresponding serializer to arg type""" diff --git a/cannondb/wrapper.py b/cannondb/wrapper.py index 4733ff4..0da9a2f 100644 --- a/cannondb/wrapper.py +++ b/cannondb/wrapper.py @@ -68,11 +68,12 @@ def log_wrapper(cls, methods_to_log: tuple, log_mode='local', host=None, port=No orig_cls = cls.__class__ logger = logging.getLogger(orig_cls.__name__) if log_mode == 'tcp' or log_mode == 'udp': - handler = log_handlers.SocketHandler(host=host, port=port) if log_mode == 'tcp' else log_handlers.DatagramHandler( + handler = log_handlers.SocketHandler(host=host, + port=port) if log_mode == 'tcp' else log_handlers.DatagramHandler( host=host, port=port) else: if not os.path.exists(_log_file_name): - os.open(_log_file_name, os.O_RDWR | os.O_CREAT) + open(_log_file_name, 'a').close() handler = logging.FileHandler(_log_file_name, mode='r+') logger.addHandler(handler)