summaryrefslogtreecommitdiff
path: root/dealconvert/formats/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'dealconvert/formats/__init__.py')
-rw-r--r--dealconvert/formats/__init__.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/dealconvert/formats/__init__.py b/dealconvert/formats/__init__.py
index 1d8b460..fc19280 100644
--- a/dealconvert/formats/__init__.py
+++ b/dealconvert/formats/__init__.py
@@ -8,20 +8,34 @@ class DealFormat(object):
self.interactive = interactive
self.options = kwargs
+ def file_to_read(self, input_path):
+ return open(input_path, 'r')
+
+ def file_to_write(self, output_path):
+ return open(output_path, 'w')
+
def parse(self, input_file):
- with open(input_file, 'rb') as content:
+ with self.file_to_read(input_file) as content:
return self.parse_content(content)
def output(self, output_file, deal, analyze=False):
self.analyze = analyze
if not len(deal):
raise RuntimeError('Dealset is empty')
- with open(output_file, 'wb') as out_file:
+ with self.file_to_write(output_file) as out_file:
return self.output_content(out_file, deal)
def match_file(self, filename):
return filename.lower().endswith(self.suffix)
+ def parse_byte(self, byte):
+ try:
+ converted_byte = ord(byte)
+ byte = converted_byte
+ except TypeError:
+ converted_byte = byte # in Python3, ord() is not needed
+ return converted_byte
+
@property
def suffix(self):
pass
@@ -33,6 +47,14 @@ class DealFormat(object):
pass
+class BinaryFormat(DealFormat):
+ def file_to_read(self, input_path):
+ return open(input_path, 'rb')
+
+ def file_to_write(self, output_path):
+ return open(output_path, 'wb')
+
+
modules = glob.glob(join(dirname(__file__), "*.py"))
__all__ = [
basename(f)[:-3] for f in modules