Example #1
0
def check_syntax(filename, raise_error=False):
    """Return True if syntax is okay."""
    with autoflake.open_with_encoding(filename, encoding=autoflake.detect_encoding(filename)) as input_file:
        try:
            compile(input_file.read(), "<string>", "exec", dont_inherit=True)
            return True
        except (SyntaxError, TypeError, UnicodeDecodeError):
            if raise_error:
                raise
            else:
                return False
Example #2
0
def check_syntax(filename, raise_error=False):
    """Return True if syntax is okay."""
    with autoflake.open_with_encoding(
            filename,
            encoding=autoflake.detect_encoding(filename)) as input_file:
        try:
            compile(input_file.read(), '<string>', 'exec', dont_inherit=True)
            return True
        except (SyntaxError, TypeError, UnicodeDecodeError, ValueError):
            if raise_error:
                raise
            else:
                return False
Example #3
0
def readlines(filename):
    """Return contents of file as a list of lines."""
    with autoflake.open_with_encoding(
            filename, encoding=autoflake.detect_encoding(filename)) as f:
        return f.readlines()
Example #4
0
def pyflakes_count(filename):
    """Return pyflakes error count."""
    with autoflake.open_with_encoding(
            filename, encoding=autoflake.detect_encoding(filename)) as f:
        return len(list(autoflake.check(f.read())))
 def test_detect_encoding_with_bad_encoding(self):
     with temporary_file('# -*- coding: blah -*-\n') as filename:
         self.assertEqual('latin-1', autoflake.detect_encoding(filename))
Example #6
0
 def test_detect_encoding_with_bad_encoding(self):
     with temporary_file('# -*- coding: blah -*-\n') as filename:
         self.assertEqual('latin-1',
                          autoflake.detect_encoding(filename))
Example #7
0
def readlines(filename):
    """Return contents of file as a list of lines."""
    with autoflake.open_with_encoding(
            filename,
            encoding=autoflake.detect_encoding(filename)) as f:
        return f.readlines()
Example #8
0
def pyflakes_count(filename):
    """Return pyflakes error count."""
    with autoflake.open_with_encoding(
            filename,
            encoding=autoflake.detect_encoding(filename)) as f:
        return len(list(autoflake.check(f.read())))