#NEWLINE# def _on_connect( self ) : #NEWLINE# #INDENT# ' The Stream connected, so send the request. ' #NEWLINE# if ( not self . _requests ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# request = self . _requests [ 0 ] #NEWLINE# self . _reset_timer ( ) #NEWLINE# if ( ( request . url . scheme == 'https' ) and request . session . verify_ssl ) : #NEWLINE# #INDENT# cert = self . _stream . _socket . getpeercert ( ) #NEWLINE# try : #NEWLINE# #INDENT# match_hostname ( cert , _hostname ( request . url ) ) #NEWLINE# #UNINDENT# except CertificateError as err : #NEWLINE# #INDENT# if ( not self . _safely_call ( request . session . on_ssl_error , request . response , cert , err ) ) : #NEWLINE# #INDENT# self . _do_error ( err ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if self . _stream . need_full_url : #NEWLINE# #INDENT# path = ( '%s://%s%s' % ( request . url . scheme , request . url . netloc , request . path ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# path = request . path #NEWLINE# #UNINDENT# self . _stream . write ( ( '%s %s HTTP/1.1%s' % ( key . method , path , CRLF ) ) ) #NEWLINE# for ( key , val ) in request . headers . iteritems ( ) : #NEWLINE# #INDENT# self . _stream . write ( ( '%s: %s%s' % ( key , val , CRLF ) ) ) #NEWLINE# #UNINDENT# cookies = _get_cookies ( request ) #NEWLINE# if cookies : #NEWLINE# #INDENT# for key in cookies : #NEWLINE# #INDENT# morsel = cookies [ key ] #NEWLINE# if ( ( not request . path . startswith ( morsel [ 'path' ] ) ) or ( not _hostname ( request . url ) . lower ( ) . endswith ( morsel [ 'domain' ] . lower ( ) ) ) or ( morsel [ 'secure' ] and ( request . url . scheme != 'https' ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# self . _stream . write ( ( morsel . output ( None , 'Cookie:' ) + CRLF ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . _stream . write ( CRLF ) #NEWLINE# if request . body : #NEWLINE# #INDENT# for item in request . body : #NEWLINE# #INDENT# if isinstance ( item , basestring ) : #NEWLINE# #INDENT# self . _stream . write ( item ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _stream . write_file ( item ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . _stream . on_read = self . _read_headers #NEWLINE# self . _stream . read_delimiter = DOUBLE_CRLF