'Loads the file in a way that auto-detects source encoding and deals
with broken terminal encodings for stdin.
Stolen from flake8_import_order because it\'s good.'

def load_file(self):

    if (self.filename in ('stdin', '-', None)):
        self.filename = 'stdin'
        self.lines = pycodestyle.stdin_get_value().splitlines(True)
    else:
        self.lines = pycodestyle.readlines(self.filename)
    if (not self.tree):
        self.tree = ast.parse(''.join(self.lines))
