diff options
author | emkael <emkael@tlen.pl> | 2019-05-31 17:06:41 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-05-31 17:06:41 +0200 |
commit | ddc48b5f38de12d28917c71c46c61913e640c774 (patch) | |
tree | 59aad449a853c2bcccef3a5fa6cc6d6a40f9e271 | |
parent | c417577b9cf19e00f92d583f3c82ff95c9e54efe (diff) |
Changes that allow providing input from StringIO:
- format detection exposed for manual parser creation
- optional filename in constructor
-rw-r--r-- | dealconvert/__init__.py | 7 |
1 files 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( |