Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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()
Ejemplo n.º 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())))
Ejemplo n.º 5
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))
Ejemplo n.º 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))
Ejemplo n.º 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()
Ejemplo n.º 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())))