mirror of https://github.com/yandex/gixy
commit
2ea357ea7b
|
@ -150,10 +150,10 @@ def main():
|
||||||
|
|
||||||
with Gixy(config=config) as yoda:
|
with Gixy(config=config) as yoda:
|
||||||
if path == '-':
|
if path == '-':
|
||||||
with os.fdopen(sys.stdin.fileno(), 'r') as fdata:
|
with os.fdopen(sys.stdin.fileno(), 'rb') as fdata:
|
||||||
yoda.audit('<stdin>', fdata, is_stdin=True)
|
yoda.audit('<stdin>', fdata, is_stdin=True)
|
||||||
else:
|
else:
|
||||||
with open(path, mode='r') as fdata:
|
with open(path, mode='rb') as fdata:
|
||||||
yoda.audit(path, fdata, is_stdin=False)
|
yoda.audit(path, fdata, is_stdin=False)
|
||||||
|
|
||||||
formatted = formatters()[config.output_format]().format(yoda)
|
formatted = formatters()[config.output_format]().format(yoda)
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
|
import codecs
|
||||||
|
import six
|
||||||
from cached_property import cached_property
|
from cached_property import cached_property
|
||||||
|
|
||||||
from pyparsing import (
|
from pyparsing import (
|
||||||
|
@ -27,11 +29,19 @@ class RawParser(object):
|
||||||
"""
|
"""
|
||||||
Returns the parsed tree.
|
Returns the parsed tree.
|
||||||
"""
|
"""
|
||||||
|
if isinstance(data, six.binary_type):
|
||||||
|
if data[:3] == codecs.BOM_UTF8:
|
||||||
|
encoding = 'utf-8-sig'
|
||||||
|
else:
|
||||||
|
encoding = 'latin1'
|
||||||
|
content = data.decode(encoding).strip()
|
||||||
|
else:
|
||||||
content = data.strip()
|
content = data.strip()
|
||||||
|
|
||||||
if not content:
|
if not content:
|
||||||
return ParseResults()
|
return ParseResults()
|
||||||
|
|
||||||
return self.script.parseString(data, parseAll=True)
|
return self.script.parseString(content, parseAll=True)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def script(self):
|
def script(self):
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
from nose.tools import assert_equals
|
from nose.tools import assert_equals
|
||||||
import mock
|
|
||||||
from six import StringIO
|
|
||||||
from six.moves import builtins
|
|
||||||
from gixy.parser.raw_parser import *
|
from gixy.parser.raw_parser import *
|
||||||
|
|
||||||
|
|
||||||
|
@ -527,6 +524,28 @@ def test_empty_config():
|
||||||
assert_config(config, expected)
|
assert_config(config, expected)
|
||||||
|
|
||||||
|
|
||||||
|
def test_utfbom_decoding():
|
||||||
|
config = b'''\xef\xbb\xbf
|
||||||
|
add_header X-Test "Windows-1251";
|
||||||
|
'''
|
||||||
|
|
||||||
|
expected = [
|
||||||
|
['add_header', 'X-Test', 'Windows-1251']
|
||||||
|
]
|
||||||
|
|
||||||
|
assert_config(config, expected)
|
||||||
|
|
||||||
|
|
||||||
|
def test_national_comment_decoding():
|
||||||
|
config = b'''
|
||||||
|
# \xeb\xff-\xeb\xff-\xeb\xff = Lya-lya-lya
|
||||||
|
add_header X-Test "Windows-1251";
|
||||||
|
'''
|
||||||
|
|
||||||
|
actual = RawParser().parse(config)
|
||||||
|
assert_equals(len(actual.asList()), 2)
|
||||||
|
|
||||||
|
|
||||||
def assert_config(config, expected):
|
def assert_config(config, expected):
|
||||||
actual = RawParser().parse(config)
|
actual = RawParser().parse(config)
|
||||||
assert_equals(actual.asList(), expected)
|
assert_equals(actual.asList(), expected)
|
||||||
|
|
Loading…
Reference in New Issue