diff --git a/Lib/site.py b/Lib/site.py --- a/Lib/site.py +++ b/Lib/site.py @@ -52,6 +52,52 @@ ImportError exception, it is silently ig """ +def open(file, mode="r", buffering=-1, encoding=None, errors=None, + newline=None, closefd=True): + if encoding is None and 'b' not in mode: + import warnings + warnings.warn('open encoding is not set', ResourceWarning, 2) + elif encoding == 'locale': + encoding = None + return open.builtin(file, mode, buffering, + encoding, errors, newline, closefd) +open.builtin = __builtins__['open'] +__builtins__['open'] = open +import io, _pyio +io.open = open +_pyio.open = open + +_cTextIOWrapper = io.TextIOWrapper + +class cTextIOWrapper(_cTextIOWrapper): + def __init__(self, buffer, encoding=None, errors=None, newline=None, + line_buffering=False): + if encoding is None: + import warnings + warnings.warn('TextIOWrapper encoding is not set', ResourceWarning, 2) + elif encoding == 'locale': + encoding = None + _cTextIOWrapper.__init__(self, buffer, encoding, errors, + newline, line_buffering) + +io.TextIOWrapper = cTextIOWrapper + +_pyTextIOWrapper = _pyio.TextIOWrapper + +class pyTextIOWrapper(_pyTextIOWrapper): + def __init__(self, buffer, encoding=None, errors=None, newline=None, + line_buffering=False): + if encoding is None: + import warnings + warnings.warn('TextIOWrapper encoding is not set', ResourceWarning, 2) + elif encoding == 'locale': + encoding = None + _pyTextIOWrapper.__init__(self, buffer, encoding, errors, + newline, line_buffering) + +_pyio.TextIOWrapper = pyTextIOWrapper + + import sys import os import builtins