API is cleaner this way, easier to understand the purpose of methods (#2).

This commit is contained in:
Romain Dorgueil
2016-12-28 11:40:03 +01:00
parent 67e25b92e1
commit cebb8df173
3 changed files with 17 additions and 19 deletions

View File

@ -10,7 +10,7 @@ class JsonHandler:
class JsonReader(JsonHandler, FileReader):
def handle(self, ctx):
def read(self, ctx):
for line in json.load(ctx.file):
yield line
@ -20,14 +20,14 @@ class JsonWriter(JsonHandler, FileWriter):
super().initialize(ctx)
ctx.file.write('[\n')
def handle(self, ctx, row):
def write(self, ctx, row):
"""
Write a json row on the next line of file pointed by ctx.file.
:param ctx:
:param row:
"""
return super().handle(ctx, json.dumps(row))
return super().write(ctx, json.dumps(row))
def finalize(self, ctx):
ctx.file.write('\n]')