Skip to content

Commit

Permalink
try using codecs instead
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Mar 25, 2020
1 parent 25e3649 commit d2a757b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions yamllint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,31 @@
from __future__ import print_function

import argparse
import codecs
import io
import os
import platform
import sys

import yaml
from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION
from yamllint import linter
from yamllint.config import YamlLintConfig, YamlLintConfigError
from yamllint.linter import PROBLEM_LEVELS


def determine_encoding(file_path):
with open(file_path, 'rb')
if isinstance(self.raw_buffer, bytes):
if self.raw_buffer.startswith(codecs.BOM_UTF16_LE):
self.raw_decode = codecs.utf_16_le_decode
self.encoding = 'utf-16-le'
elif self.raw_buffer.startswith(codecs.BOM_UTF16_BE):
self.raw_decode = codecs.utf_16_be_decode
self.encoding = 'utf-16-be'
else:
self.raw_decode = codecs.utf_8_decode
self.encoding = 'utf-8'

def find_files_recursively(items, conf):
for item in items:
if os.path.isdir(item):
Expand Down Expand Up @@ -178,9 +191,8 @@ def run(argv=None):
for file in find_files_recursively(args.files, conf):
filepath = file[2:] if file.startswith('./') else file
try:
with io.open(file, mode='rb') as f:
buff = yaml.BaseLoader(f).buffer
problems = linter.run(buff, conf, filepath)
with codecs.open(file) as f:
problems = linter.run(f, conf, filepath)
except EnvironmentError as e:
print(e, file=sys.stderr)
sys.exit(-1)
Expand Down

0 comments on commit d2a757b

Please sign in to comment.