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| }|sB|sBtd|k}d} |rZ| d7} |rf| d7} t|| } |jd7_|dkrd }|dkrtj}|dkr|std | S|r|rtj| | |} n&|rtj| |} n|sttj | |} |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 ValueErrorAssertionErrorrZ_makefile_refsioDEFAULT_BUFFER_SIZEBufferedRWPairBufferedReaderBufferedWriter TextIOWrappermode) selfr bufferingencodingerrorsnewlineZwritingZreadingZbinaryZrawmoderawbuffertextr/usr/lib/python3.6/makefile.pybackport_makefilesB    r)rNNNN)__doc__r Zsocketrrrrrrs