From daf6041854d99dbc8d7a7c1e108c7f02b6d50abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tina=20M=C3=BCller?= Date: Sun, 8 Dec 2019 17:06:30 +0100 Subject: [PATCH] Revert "Python 3: file() --> open() in yaml-highlight example (#236)" This reverts commit a5f4329ac595d06da91d018195c33de9bc48e0f9. Still not working with python3: % PYTHONPATH=$PWD/lib3 python3 examples/yaml-highlight/yaml_hl.py <.appveyor.yml Traceback (most recent call last): File "examples/yaml-highlight/yaml_hl.py", line 126, in hl.highlight() File "examples/yaml-highlight/yaml_hl.py", line 66, in highlight if input.startswith(codecs.BOM_UTF16_LE): TypeError: startswith first arg must be str or a tuple of str, not bytes and getting this warning in python2: Exception AttributeError: "'NoneType' object has no attribute 'stdin'" in > ignored --- examples/yaml-highlight/yaml_hl.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/examples/yaml-highlight/yaml_hl.py b/examples/yaml-highlight/yaml_hl.py index b6eb3164..d6f7bf4e 100755 --- a/examples/yaml-highlight/yaml_hl.py +++ b/examples/yaml-highlight/yaml_hl.py @@ -2,12 +2,6 @@ import yaml, codecs, sys, os.path, optparse -try: - unicode -except NameError: - unicode = str - - class Style: def __init__(self, header=None, footer=None, @@ -43,24 +37,17 @@ def __setstate__(self, state): class YAMLHighlight: def __init__(self, options): - with open(options.config, 'rb') as yaml_file: - config = yaml.load(yaml_file.read()) + config = yaml.load(file(options.config, 'rb').read()) self.style = config[options.style] if options.input: - self.input = open(options.input, 'rb') + self.input = file(options.input, 'rb') else: self.input = sys.stdin if options.output: - self.output = open(options.output, 'wb') + self.output = file(options.output, 'wb') else: self.output = sys.stdout - def __del__(self): - if self.input not in (sys.stdin, None): - self.input.close() - if self.output not in (sys.stdout, None): - self.output.close() - def highlight(self): input = self.input.read() if input.startswith(codecs.BOM_UTF16_LE):