Open the subtitle file (detect encoding if necessary).
324291
def open(self):
        """"""
        with open(self.filename, 'rb') as file_open:
            binary = file_open.read()

        try:
            return binary.decode()
        except UnicodeDecodeError:
            encoding = get_encoding(binary)
            try:
                return binary.decode(encoding)
            except LookupError:
                return binary.decode(errors='ignore')
            except:  # pylint: disable=W0702
                open_error(self.filename)
        except:  # pylint: disable=W0702
            open_error(self.filename)
1301891
def read(filename):
    
    fname = os.path.join(here, filename)
    with codecs.open(fname, encoding='utf-8') as f:
        return f.read()
111720
def _read_text(self, filename):
        
        with io.open(filename, 'rt', encoding='utf-8') as f:
            return f.read()
1267990
def open_text(fn:PathOrStr, enc='utf-8'):
    ""
    with open(fn,'r', encoding = enc) as f: return ''.join(f.readlines())
892342
def open(filename):
	
	buffer = _builtin_open(filename, 'rb')
	try:
		encoding, lines = detect_encoding(buffer.readline)
		buffer.seek(0)
		text = TextIOWrapper(buffer, encoding, line_buffering=True)
		text.mode = 'r'
		return text
	except:
		buffer.close()
		raise
870524
def detect(filename, include_confidence=False):
    
    f = open(filename)
    detection = chardet.detect(f.read())
    f.close()
    encoding = detection.get('encoding')
    confidence = detection.get('confidence')
    if include_confidence:
        return (encoding, confidence)
    return encoding
181143
def from_file(filename):
        

        spec = Spec()
        with open(filename, "r", encoding="utf-8") as f:
            parse_context = {"current_subpackage": None}
            for line in f:
                spec, parse_context = _parse(spec, parse_context, line)
        return spec
1350916
def open(self):
        

        if not os.path.exists(self.path):
            raise IOError("No such path: {0}".format(self.path))


        with open(self.path, "rb") as f:
            msg = f.read()
        result = chardet.detect(msg)

        self.buffer = codecs.open(self.path, "rb", encoding=result['encoding'])

        self.at_eof = False
226040
def _detect_encoding(self, source_file):
        """"""

        encoding = self._guess(source_file)
        # If we didn't explicitly detect an encoding, assume default.
        if encoding is None:
            encoding = self.default_encoding

        return encoding
1318857
def read(self, encoding=None):
        """"""
        encoding = encoding or ENCODING
        try:
            with codecs.open(self.path, encoding=encoding) as fi:
                return fi.read()
        except:
            return None
503496
def _read_file(name, encoding='utf-8'):
    
    with codecs.open(name, encoding=encoding) as f:
        return f.read()
24383
def title_translations(self, key, value):
    """"""
    return {
        'language': langdetect.detect(value.get('a')),
        'source': value.get('9'),
        'subtitle': value.get('b'),
        'title': value.get('a'),
    }
312862
def OpenFile(self, filename):
    """"""
    (mime_type, encoding) = mimetypes.guess_type(filename)
    assert mime_type
    # A crude guess of when we should use binary mode. Without it non-unix
    # platforms may corrupt binary files.
    if mime_type.startswith('text/'):
      mode = 'r'
    else:
      mode = 'rb'
    return open(os.path.join(self.server.file_dir, filename), mode), mime_type
757229
def open_file(self, filename):
        """"""
        try:
            if filename.endswith('.gz'):
                self.blob_file = gzip.open(filename, 'rb')
            else:
                self.blob_file = open(filename, 'rb')
        except TypeError:
            log.error("Please specify a valid filename.")
            raise SystemExit
        except IOError as error_message:
            log.error(error_message)
            raise SystemExit
1289879
def smart_open(filename: str, mode: str = 'Ur', buffering: int = -1,
               encoding: str = None, errors: str = None, newline: str = None,
               closefd: bool = True) -> IO:
    
    # https://stackoverflow.com/questions/17602878/how-to-handle-both-with-open-and-sys-stdout-nicely  # noqa
    # https://stackoverflow.com/questions/1744989/read-from-file-or-stdin/29824059#29824059  # noqa
    if filename == '-':
        if mode is None or mode == '' or 'r' in mode:
            fh = sys.stdin
        else:
            fh = sys.stdout
    else:
        fh = open(filename, mode=mode,
                  buffering=buffering, encoding=encoding, errors=errors,
                  newline=newline, closefd=closefd)
    try:
        yield fh
    finally:
        if filename is not '-':
            fh.close()
631477
def open(self, encoding=None):
        """"""
        try:
            if IS_GZIPPED_FILE.search(self._filename):
                _file = gzip.open(self._filename, 'rb')
            else:
                if encoding:
                    _file = io.open(self._filename, 'r', encoding=encoding, errors='replace')
                elif self._encoding:
                    _file = io.open(self._filename, 'r', encoding=self._encoding, errors='replace')
                else:
                    _file = io.open(self._filename, 'r', errors='replace')
        except IOError, e:
            self._log_warning(str(e))
            _file = None
            self.close()

        return _file
1095505
def _open(self):
    
    # The gzip module supports directly setting encoding as of Python 3.3.
    # pylint: disable=unexpected-keyword-arg
    if py2to3.PY_3:
      return gzip.open(
          self.baseFilename, mode=self.mode, encoding=self.encoding)

    return gzip.open(self.baseFilename, self.mode)