<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , division , print_function <EOL> from tls . io import BIOChain <EOL> from tls . c import api <EOL> from tls import err <EOL> class BIOFile ( BIOChain ) : <EOL> """<STR_LIT>""" <EOL> MODES = set ( [ '<STR_LIT:r>' , '<STR_LIT>' , '<STR_LIT:w>' , '<STR_LIT>' , '<STR_LIT:a>' , '<STR_LIT>' ] ) <EOL> def __init__ ( self , filename , mode = '<STR_LIT:r>' ) : <EOL> if mode not in self . MODES : <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT:U+0020>" . join ( "<STR_LIT>" . format ( m ) for m in sorted ( self . MODES ) ) <EOL> msg += "<STR_LIT>" . format ( mode ) <EOL> raise ValueError ( msg ) <EOL> self . _filename = filename . encode ( ) <EOL> self . _mode = mode . encode ( ) <EOL> mode = api . new ( '<STR_LIT>' , self . _mode ) <EOL> filename = api . new ( '<STR_LIT>' , self . _filename ) <EOL> bio = api . BIO_new_file ( filename , mode ) <EOL> if api . cast ( '<STR_LIT>' , bio ) == api . NULL : <EOL> messages = err . log_errors ( ) <EOL> raise IOError ( messages [ <NUM_LIT:0> ] ) <EOL> super ( BIOFile , self ) . __init__ ( bio ) <EOL> def readable ( self ) : <EOL> return self . _mode . startswith ( b'<STR_LIT:r>' ) or self . _mode . endswith ( b'<STR_LIT:+>' ) <EOL> def writable ( self ) : <EOL> return self . _mode . startswith ( b'<STR_LIT:w>' ) or self . _mode . endswith ( b'<STR_LIT:+>' ) <EOL> class BIOMemBuffer ( BIOChain ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , initial_value = None ) : <EOL> if initial_value is not None : <EOL> self . _buffer = api . new ( '<STR_LIT>' , initial_value ) <EOL> bio = api . BIO_new_mem_buf ( self . _buffer , len ( initial_value ) ) <EOL> else : <EOL> bio = api . BIO_new ( api . BIO_s_mem ( ) ) <EOL> super ( BIOMemBuffer , self ) . __init__ ( bio ) <EOL> def writable ( self ) : <EOL> return not hasattr ( self , '<STR_LIT>' ) <EOL> class BIONull ( BIOChain ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> bio = api . BIO_new ( api . BIO_s_null ( ) ) <EOL> super ( BIONull , self ) . __init__ ( bio ) </s>
