From ddc48b5f38de12d28917c71c46c61913e640c774 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 31 May 2019 17:06:41 +0200 Subject: Changes that allow providing input from StringIO: - format detection exposed for manual parser creation - optional filename in constructor --- dealconvert/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dealconvert/__init__.py b/dealconvert/__init__.py index 1779976..2f9b5aa 100644 --- a/dealconvert/__init__.py +++ b/dealconvert/__init__.py @@ -1,17 +1,18 @@ from .formats import * class DealConverter(object): - def __init__(self, input_file): + def __init__(self, input_file=None): self.input = input_file self.formats = {} - self.parser = self._detect_format(self.input) + if input_file is not None: + self.parser = self._detect_format(self.input) def output(self, output_files): deal_set = sorted(self.parser.parse(self.input), key=lambda d:d.number) for output in output_files: self._detect_format(output).output(output, deal_set) - def _detect_format(self, filename): + def detect_format(self, filename): for deal_format in globals()['formats'].__all__: if deal_format not in self.formats: self.formats[deal_format] = getattr( -- cgit v1.2.3