3 nf\@s&dZddlZddlmZdddZdS)z backports.makefile ~~~~~~~~~~~~~~~~~~ Backports the Python 3 ``socket.makefile`` method for use with anything that wants to create a "fake" socket object. N)SocketIOrc Cst|dddhks td|fd|k}d|kp4| }d|k}d} |rN| d7} |rZ| d7} t|| } |jd7_|dkr~d }|dkrtj}|dkr|std | S|r|rtj| | |} n|rtj| |} n tj| |} |r| Stj | |||} || _ | S) z: Backport of ``socket.makefile`` from Python 3.5. rwbz&invalid mode %r (only r, w, b allowed)Nrz!unbuffered streams must be binary) set ValueErrorrZ_makefile_refsioDEFAULT_BUFFER_SIZEBufferedRWPairBufferedReaderBufferedWriter TextIOWrappermode) selfr bufferingencodingerrorsnewlineZwritingZreadingZbinaryZrawmoderawbuffertextr/usr/lib/python3.6/makefile.pybackport_makefiles>   r)rNNNN)__doc__r Zsocketrrrrrrs