aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/vk/tracking
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vk/tracking/db/backend/csv.py7
-rw-r--r--vk/tracking/db/backend/log.py4
-rw-r--r--vk/tracking/db/backend/null.py8
-rw-r--r--vk/tracking/db/meta.py25
4 files changed, 35 insertions, 9 deletions
diff --git a/vk/tracking/db/backend/csv.py b/vk/tracking/db/backend/csv.py
index 5b2cc7d..6176018 100644
--- a/vk/tracking/db/backend/csv.py
+++ b/vk/tracking/db/backend/csv.py
@@ -3,13 +3,12 @@
# For details, see https://github.com/egor-tensin/vk-scripts.
# Distributed under the MIT License.
-from collections.abc import Iterable
-
+from .. import meta
from ..io import InputReaderCSV, OutputWriterCSV
from ..record import Record
from ..timestamp import Timestamp
-class Writer:
+class Writer(meta.Writer):
def __init__(self, fd):
self._writer = OutputWriterCSV(fd)
@@ -31,7 +30,7 @@ class Writer:
def _record_to_row(record):
return [str(record.get_timestamp())] + [str(record[field]) for field in record]
-class Reader(Iterable):
+class Reader(meta.Reader):
def __init__(self, fd):
self._reader = InputReaderCSV(fd)
diff --git a/vk/tracking/db/backend/log.py b/vk/tracking/db/backend/log.py
index f248d65..4ee5ff2 100644
--- a/vk/tracking/db/backend/log.py
+++ b/vk/tracking/db/backend/log.py
@@ -5,7 +5,9 @@
import logging
-class Writer:
+from .. import meta
+
+class Writer(meta.Writer):
def __init__(self, fd):
self._logger = logging.getLogger(__file__)
self._logger.setLevel(logging.INFO)
diff --git a/vk/tracking/db/backend/null.py b/vk/tracking/db/backend/null.py
index 3cdb41e..663af10 100644
--- a/vk/tracking/db/backend/null.py
+++ b/vk/tracking/db/backend/null.py
@@ -3,9 +3,9 @@
# For details, see https://github.com/egor-tensin/vk-scripts.
# Distributed under the MIT License.
-from collections.abc import Iterable
+from .. import meta
-class Writer:
+class Writer(meta.Writer):
def __init__(self):
pass
@@ -18,9 +18,9 @@ class Writer:
def on_connection_error(self, e):
pass
-class Reader(Iterable):
+class Reader(meta.Reader):
def __init__(self):
pass
def __iter__(self):
- pass
+ return iter(())
diff --git a/vk/tracking/db/meta.py b/vk/tracking/db/meta.py
new file mode 100644
index 0000000..024d9d8
--- /dev/null
+++ b/vk/tracking/db/meta.py
@@ -0,0 +1,25 @@
+# Copyright (c) 2017 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "VK scripts" project.
+# For details, see https://github.com/egor-tensin/vk-scripts.
+# Distributed under the MIT License.
+
+import abc
+from collections.abc import Iterable
+
+class Writer(metaclass=abc.ABCMeta):
+ @abc.abstractmethod
+ def on_initial_status(self, user):
+ pass
+
+ @abc.abstractmethod
+ def on_status_update(self, user):
+ pass
+
+ @abc.abstractmethod
+ def on_connection_error(self, e):
+ pass
+
+class Reader(Iterable, metaclass=abc.ABCMeta):
+ @abc.abstractmethod
+ def __iter__(self):
+ pass