Return preferred encoding for reading from ``stream``.

    ``stream`` defaults to sys.stdin.

def getinputencoding(stream=None):
    """Return preferred encoding for reading from ``stream``.

    ``stream`` defaults to sys.stdin.
    """
    if stream is None:
        stream = sys.stdin
    encoding = stream.encoding
    if not encoding:
        encoding = getpreferredencoding()
    return encoding