fix: add missing json import
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is passing

This commit is contained in:
William Luke 2022-03-01 12:30:19 +03:00
parent b3ddf43285
commit 48ee8050c1
2 changed files with 18 additions and 19 deletions

View File

@ -134,7 +134,7 @@ class Network(Data):
for resource in self.resources.keys(): for resource in self.resources.keys():
for content_key in self.resources[resource]['contents'].keys(): for content_key in self.resources[resource]['contents'].keys():
content_value = self.resources[resource]['contents'][content_key] content_value = self.resources[resource]['contents'][content_key]
if content_value == None: if content_value is None:
content_value = '' content_value = ''
s += f'{resource}.{content_key} = {content_value}\n' s += f'{resource}.{content_key} = {content_value}\n'

View File

@ -4,10 +4,9 @@ import logging
import os import os
import sys import sys
import urllib.request import urllib.request
from typing import TYPE_CHECKING import json
from cic_types.ext.metadata import MetadataRequestsHandler
from cic_types.ext.metadata import MetadataRequestsHandler, MetadataPointer
logg = logging.getLogger(__name__) logg = logging.getLogger(__name__)
@ -22,7 +21,7 @@ class OutputWriter:
class StdoutWriter(OutputWriter): class StdoutWriter(OutputWriter):
def write(self, k, v): def write(self, k, v):
sys.stdout.write("{}\t{}\n".format(k, v)) sys.stdout.write(f"{k}\t{v}\n")
class KVWriter(OutputWriter): class KVWriter(OutputWriter):
@ -35,7 +34,7 @@ class KVWriter(OutputWriter):
def write(self, k, v): def write(self, k, v):
fp = os.path.join(self.path, str(k)) fp = os.path.join(self.path, str(k))
logg.debug("path write {} {}".format(fp, str(v))) logg.debug(f"path write {fp} {str(v)}")
f = open(fp, "wb") f = open(fp, "wb")
f.write(v) f.write(v)
f.close() f.close()
@ -48,12 +47,12 @@ class HTTPWriter(OutputWriter):
def write(self, k, v): def write(self, k, v):
path = self.path path = self.path
if k != None: if k is not None:
path = os.path.join(path, k) path = os.path.join(path, k)
logg.debug(f"http writer post {path} \n key: {k}, value: {v}") logg.debug(f"http writer post {path} \n key: {k}, value: {v}")
rq = urllib.request.Request(path, method="POST", data=v) rq = urllib.request.Request(path, method="POST", data=v)
r = urllib.request.urlopen(rq) r = urllib.request.urlopen(rq)
logg.info("http writer submitted at {}".format(r.read())) logg.info(f"http writer submitted at {r.read()}")
class KeyedWriter(OutputWriter): class KeyedWriter(OutputWriter):
@ -61,14 +60,14 @@ class KeyedWriter(OutputWriter):
self.writer_keyed = writer_keyed self.writer_keyed = writer_keyed
self.writer_immutable = writer_immutable self.writer_immutable = writer_immutable
def write(self, key, value): def write(self, k, v):
logg.debug(f"writing keywriter key: {key} value: {value}") logg.debug(f"writing keywriter key: {k} value: {v}")
if isinstance(value, str): if isinstance(value, str):
value = value.encode("utf-8") value = value.encode("utf-8")
if self.writer_keyed != None: if self.writer_keyed is not None:
self.writer_keyed.write(key, value) self.writer_keyed.write(k, v)
if self.writer_immutable != None: if self.writer_immutable is not None:
self.writer_immutable.write(None, value) self.writer_immutable.write(None, v)
class KeyedWriterFactory: class KeyedWriterFactory:
@ -78,16 +77,16 @@ class KeyedWriterFactory:
self.key_writer_constructor = key_writer_constructor self.key_writer_constructor = key_writer_constructor
self.immutable_writer_constructor = immutable_writer_constructor self.immutable_writer_constructor = immutable_writer_constructor
self.x = {} self.x = {}
for k in kwargs.keys(): for k, v in kwargs.items():
logg.debug("adding key {} t keyed writer factory".format(k)) logg.debug(f"adding key {k} t keyed writer factory")
self.x[k] = kwargs[k] self.x[k] = v
def new(self, path=None, *args, **kwargs): def new(self, path=None, *args, **kwargs):
writer_keyed = None writer_keyed = None
writer_immutable = None writer_immutable = None
if self.key_writer_constructor != None: if self.key_writer_constructor is not None:
writer_keyed = self.key_writer_constructor(path, **self.x) writer_keyed = self.key_writer_constructor(path, **self.x)
if self.immutable_writer_constructor != None: if self.immutable_writer_constructor is not None:
writer_immutable = self.immutable_writer_constructor(path, **self.x) writer_immutable = self.immutable_writer_constructor(path, **self.x)
return KeyedWriter(writer_keyed, writer_immutable) return KeyedWriter(writer_keyed, writer_immutable)