From cdf8f6be09d7d1bd9a629ee50cf2d42cf0a1b9fa Mon Sep 17 00:00:00 2001 From: Davis Goglin Date: Tue, 15 Mar 2016 15:05:25 -0700 Subject: [PATCH] Fix config loading --- escpos/config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/escpos/config.py b/escpos/config.py index fe1918e..bf6e4cb 100644 --- a/escpos/config.py +++ b/escpos/config.py @@ -43,12 +43,16 @@ class Config(object): ) try: - config = yaml.safe_load(f) + if isinstance(config_path, file): + config = yaml.safe_load(config_path) + else: + with open(config_path, 'rb') as f: + config = yaml.safe_load(f) except EnvironmentError as e: raise exceptions.ConfigNotFoundError('Couldn\'t read config at one or more of {config_path}'.format( config_path="\n".join(config_path), )) - except yaml.ParserError as e: + except yaml.YAMLError as e: raise exceptions.ConfigSyntaxError('Error parsing YAML') if 'printer' in config: