21718: Replace .decode method with str(bytes, "utf-8")
authorPeter Amstutz <peter.amstutz@curii.com>
Fri, 3 May 2024 14:38:19 +0000 (10:38 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Mon, 20 May 2024 18:40:20 +0000 (14:40 -0400)
This is because some bytes-like objects (such as memoryview) don't
have a "decode()" method. It appears that the preferred way to get a
decoded string is to simply call the constructor with the bytes-like
object and the desired encoding.

Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

sdk/cwl/arvados_cwl/arvdocker.py
sdk/cwl/arvados_cwl/arvworkflow.py
sdk/cwl/arvados_cwl/runner.py

index f5e67a6649409c60c6deddef9431340e7504e96c..ae5a434074ad58d9c5710f70f5140597f8f17d2d 100644 (file)
@@ -19,11 +19,10 @@ logger = logging.getLogger('arvados.cwl-runner')
 
 def determine_image_id(dockerImageId):
     for line in (
-        subprocess.check_output(  # nosec
-            ["docker", "images", "--no-trunc", "--all"]
-        )
-        .decode("utf-8")
-        .splitlines()
+            str(subprocess.check_output(  # nosec
+                ["docker", "images", "--no-trunc", "--all"]
+            ), "utf-8")
+            .splitlines()
     ):
         try:
             match = re.match(r"^([^ ]+)\s+([^ ]+)\s+([^ ]+)", line)
index dae68459bc3f6a00ea5c3bab3de03dbc64663a4e..4751e48c04be42cca81df4cf3048e9068f5ac1f4 100644 (file)
@@ -317,7 +317,7 @@ def upload_workflow(arvRunner, tool, job_order, project_uuid,
 
         text = tool.doc_loader.fetch_text(w)
         if isinstance(text, bytes):
-            textIO = StringIO(text.decode('utf-8'))
+            textIO = StringIO(str(text, 'utf-8'))
         else:
             textIO = StringIO(text)
 
index 259294a36e6ccbf87df87c6124eda124aef03d0b..0cd6295fbb9c0eb6df0bf4b7495d57bf8efb47b4 100644 (file)
@@ -929,7 +929,7 @@ class Runner(Process):
             if "cwl.output.json" in outc:
                 with outc.open("cwl.output.json", "rb") as f:
                     if f.size() > 0:
-                        outputs = json.loads(f.read().decode())
+                        outputs = json.loads(str(f.read(), 'utf-8'))
             def keepify(fileobj):
                 path = fileobj["location"]
                 if not path.startswith("keep:"):