diff options
| author | Tina Müller (tinita) <cpan2@tinita.de> | 2019-12-08 01:37:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-08 01:37:38 +0100 |
| commit | bedeb6895b830c0fe88e2d6925eb1f6c18e28fe5 (patch) | |
| tree | 8f0eccc9261a475c0ae59fee202c839794bebc6c | |
| parent | a5f4329ac595d06da91d018195c33de9bc48e0f9 (diff) | |
| download | pyyaml-git-revert-236-patch-2.tar.gz | |
Revert "Python 3: file() --> open() in yaml-highlight example (#236)"revert-236-patch-2
This reverts commit a5f4329ac595d06da91d018195c33de9bc48e0f9.
| -rwxr-xr-x | examples/yaml-highlight/yaml_hl.py | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/examples/yaml-highlight/yaml_hl.py b/examples/yaml-highlight/yaml_hl.py index b6eb316..d6f7bf4 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 @@ yaml.add_path_resolver(u'tag:yaml.org,2002:pairs', 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): |
