:param files: A list of file paths :: [str]
    :param encoding: Encoding, e.g. 'utf-8'
557070
def _load_file_itr(files, encoding):
    
    for filename in files:
        fileobj = jinja2.loaders.open_if_exists(filename)
        if fileobj is not None:
            try:
                yield (fileobj.read().decode(encoding),
                       os.path.getmtime(filename))
            finally:
                fileobj.close()
180199
def chunk_encoding(chunks, chunk):
    '''
    '''
    chunks.extend(("%X\r\n" % len(chunk)).encode('utf-8'))
    chunks.extend(chunk)
    chunks.extend(CRLF)
267022
def items2file(items, filename, encoding='utf-8', modifier='w'):
    
    with codecs.open(filename, modifier, encoding=encoding) as f:
        for item in items:
            f.write(u"{}\n".format(json.dumps(
                item, ensure_ascii=False, sort_keys=True)))
984561
def parse_source_file(filename):
    

    # can't use codecs.open(filename, 'r', 'utf-8') here b/c ast doesn't
    # work with unicode strings in Python2.7 "SyntaxError: encoding
    # declaration in Unicode string" In python 2.7 the string can't be
    # encoded and have information about its encoding. That is particularly
    # problematic since source files include in their header information
    # about the file encoding.
    # Minimal example to fail: ast.parse(u'# -*- coding: utf-8 -*-')

    with open(filename, 'rb') as fid:
        content = fid.read()
    # change from Windows format to UNIX for uniformity
    content = content.replace(b'\r\n', b'\n')

    try:
        node = ast.parse(content)
        return node, content.decode('utf-8')
    except SyntaxError:
        return None, content.decode('utf-8')
728094
def read_filepath(filepath, encoding='utf-8'):
    """"""
    with codecs.open(filepath, 'r', encoding=encoding) as fo:
        return fo.read()
622261
def read_unicode(path, encoding, encoding_errors):
    
    try:
      f = open(path, 'rb')
      return make_unicode(f.read(), encoding, encoding_errors)
    finally:
      f.close()
39156
function (/*String*/path, /*String?*/encoding) {
        if (encoding === 'utf-8') {
            encoding = 'utf8';
        }
        if (!encoding) {
            encoding = 'utf8';
        }

        return fs.readFileSync(path, encoding);
    }
775837
def filesys_decode(path):
    

    if isinstance(path, six.text_type):
        return path

    fs_enc = sys.getfilesystemencoding() or 'utf-8'
    candidates = fs_enc, 'utf-8'

    for enc in candidates:
        try:
            return path.decode(enc)
        except UnicodeDecodeError:
            continue
1068828
def format_file_params(files):
        '''
            
        '''
        files_payload = {}
        if files:
            for idx, filename in enumerate(files):
                files_payload["file[" + str(idx) + "]"] = open(filename, 'rb')
        return files_payload
1005191
def detectFileEncoding(self, fileName):
		'''
		
		'''
		try:
			import chardet
		except ImportError:
			return

		with open(fileName, 'rb') as inputFile:
			raw = inputFile.read(2048)

		result = chardet.detect(raw)
		if result['confidence'] > 0.9:
			if result['encoding'].lower() == 'ascii':
				# UTF-8 files can be falsely detected as ASCII files if they
				# don't contain non-ASCII characters in first 2048 bytes.
				# We map ASCII to UTF-8 to avoid such situations.
				return 'utf-8'
			return result['encoding']
1121473
def to_unicode(path, errors="replace"):
    """"""
    if isinstance(path, UNICODE):
        return path
    return path.decode(sys.getfilesystemencoding(), errors)
481180
def _read(path, encoding="utf-8", comment=";;;"):
    
    if path:
        if isinstance(path, basestring) and os.path.exists(path):
            # From file path.
            if PY2:
                f = codecs.open(path, 'r', encoding='utf-8')
            else:
                f = open(path, 'r', encoding='utf-8')
        elif isinstance(path, basestring):
            # From string.
            f = path.splitlines()
        else:
            # From file or buffer.
            f = path
        for i, line in enumerate(f):
            line = line.strip(codecs.BOM_UTF8) if i == 0 and isinstance(line, binary_type) else line
            line = line.strip()
            line = decode_utf8(line, encoding)
            if not line or (comment and line.startswith(comment)):
                continue
            yield line
    return
157444
def multipart_encoder(**kwargs):
    
    def get_filetype(file_path):
        file_type = filetype.guess(file_path)
        if file_type:
            return file_type.mime
        else:
            return "text/html"

    fields_dict = {}
    for key, value in kwargs.items():

        if os.path.isabs(value):
            _file_path = value
            is_file = True
        else:
            global PWD
            _file_path = os.path.join(PWD, value)
            is_file = os.path.isfile(_file_path)

        if is_file:
            filename = os.path.basename(_file_path)
            with open(_file_path, 'rb') as f:
                mime_type = get_filetype(_file_path)
                fields_dict[key] = (filename, f.read(), mime_type)
        else:
            fields_dict[key] = value

    return MultipartEncoder(fields=fields_dict)
433074
def read(filename, encoding='utf-8'):
    
    text, encoding = decode( open(filename, 'rb').read() )
    return text, encoding
527483
def _parse_singlefile(self, desired_type: Type[T], file_path: str, encoding: str, logger: Logger,
                          options: Dict[str, Dict[str, Any]]) -> T:
        
        raise Exception('Not implemented since this is a MultiFileParser')
11458
def encode_params_utf8(params):
    
    encoded = []
    for k, v in params:
        encoded.append((
            k.encode('utf-8') if isinstance(k, unicode_type) else k,
            v.encode('utf-8') if isinstance(v, unicode_type) else v))
    return encoded
1370413
def read(self, filename, encoding=None):
        
        with open(filename, encoding=encoding) as fp:
            self._read(fp, filename)
        self._filename = os.path.abspath(filename)