diff sat/tools/stream.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 003b8b4b56a7
line wrap: on
line diff
--- a/sat/tools/stream.py	Wed Jun 27 07:51:29 2018 +0200
+++ b/sat/tools/stream.py	Wed Jun 27 20:14:46 2018 +0200
@@ -32,7 +32,6 @@
 
 
 class IStreamProducer(interface.Interface):
-
     def startStream(consumer):
         """start producing the stream
 
@@ -42,9 +41,20 @@
 
 class SatFile(object):
     """A file-like object to have high level files manipulation"""
+
     # TODO: manage "with" statement
 
-    def __init__(self, host, client, path, mode='rb', uid=None, size=None, data_cb=None, auto_end_signals=True):
+    def __init__(
+        self,
+        host,
+        client,
+        path,
+        mode="rb",
+        uid=None,
+        size=None,
+        data_cb=None,
+        auto_end_signals=True,
+    ):
         """
         @param host: %(doc_host)s
         @param path(str): path of the file to get
@@ -67,7 +77,9 @@
         self.data_cb = data_cb
         self.auto_end_signals = auto_end_signals
         metadata = self.getProgressMetadata()
-        self.host.registerProgressCb(self.uid, self.getProgress, metadata, profile=client.profile)
+        self.host.registerProgressCb(
+            self.uid, self.getProgress, metadata, profile=client.profile
+        )
         self.host.bridge.progressStarted(self.uid, metadata, client.profile)
 
     def checkSize(self):
@@ -91,14 +103,14 @@
             error can happen even if error is None, if current size differ from given size
         """
         if self._file.closed:
-            return # avoid double close (which is allowed) error
+            return  # avoid double close (which is allowed) error
         if error is None:
             try:
                 size_ok = self.checkSize()
             except exceptions.NotFound:
                 size_ok = True
             if not size_ok:
-                error = u'declared and actual size mismatch'
+                error = u"declared and actual size mismatch"
                 log.warning(error)
                 progress_metadata = None
 
@@ -149,35 +161,34 @@
 
         @return (dict): metadata (check bridge for documentation)
         """
-        metadata = {'type': C.META_TYPE_FILE}
+        metadata = {"type": C.META_TYPE_FILE}
 
         mode = self._file.mode
-        if '+' in mode:
-            pass # we have no direction in read/write modes
-        elif mode in ('r', 'rb'):
-            metadata['direction'] = 'out'
-        elif mode in ('w', 'wb'):
-            metadata['direction'] = 'in'
-        elif 'U' in mode:
-            metadata['direction'] = 'out'
+        if "+" in mode:
+            pass  # we have no direction in read/write modes
+        elif mode in ("r", "rb"):
+            metadata["direction"] = "out"
+        elif mode in ("w", "wb"):
+            metadata["direction"] = "in"
+        elif "U" in mode:
+            metadata["direction"] = "out"
         else:
             raise exceptions.InternalError
 
-        metadata['name'] = self._file.name
+        metadata["name"] = self._file.name
 
         return metadata
 
     def getProgress(self, progress_id, profile):
-        ret = {'position': self._file.tell()}
+        ret = {"position": self._file.tell()}
         if self.size:
-            ret['size'] = self.size
+            ret["size"] = self.size
         return ret
 
 
 @interface.implementer(IStreamProducer)
 @interface.implementer(interfaces.IConsumer)
 class FileStreamObject(basic.FileSender):
-
     def __init__(self, host, client, path, **kwargs):
         """