Package suds :: Package transport
[hide private]
[frames] | no frames]

Source Code for Package suds.transport

  1  # This program is free software; you can redistribute it and/or modify 
  2  # it under the terms of the (LGPL) GNU Lesser General Public License as 
  3  # published by the Free Software Foundation; either version 3 of the  
  4  # License, or (at your option) any later version. 
  5  # 
  6  # This program is distributed in the hope that it will be useful, 
  7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  9  # GNU Library Lesser General Public License for more details at 
 10  # ( http://www.gnu.org/licenses/lgpl.html ). 
 11  # 
 12  # You should have received a copy of the GNU Lesser General Public License 
 13  # along with this program; if not, write to the Free Software 
 14  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 15  # written by: Jeff Ortel ( jortel@redhat.com ) 
 16   
 17  """ 
 18  Contains transport interface (classes). 
 19  """ 
 20   
 21   
22 -class TransportError(Exception):
23 - def __init__(self, reason, httpcode, fp=None):
24 Exception.__init__(self, reason) 25 self.httpcode = httpcode 26 self.fp = fp
27
28 -class Request:
29 """ 30 A transport request 31 @ivar url: The url for the request. 32 @type url: str 33 @ivar message: The message to be sent in a POST request. 34 @type message: str 35 @ivar headers: The http headers to be used for the request. 36 @type headers: dict 37 """ 38
39 - def __init__(self, url, message=None):
40 """ 41 @param url: The url for the request. 42 @type url: str 43 @param message: The (optional) message to be send in the request. 44 @type message: str 45 """ 46 self.url = url 47 self.headers = {} 48 self.message = message
49
50 - def __str__(self):
51 s = [] 52 s.append('URL:%s' % self.url) 53 s.append('HEADERS: %s' % self.headers) 54 s.append('MESSAGE:') 55 s.append(self.message) 56 return '\n'.join(s)
57 58
59 -class Reply:
60 """ 61 A transport reply 62 @ivar code: The http code returned. 63 @type code: int 64 @ivar message: The message to be sent in a POST request. 65 @type message: str 66 @ivar headers: The http headers to be used for the request. 67 @type headers: dict 68 """ 69
70 - def __init__(self, code, headers, message):
71 """ 72 @param code: The http code returned. 73 @type code: int 74 @param headers: The http returned headers. 75 @type headers: dict 76 @param message: The (optional) reply message received. 77 @type message: str 78 """ 79 self.code = code 80 self.headers = headers 81 self.message = message
82
83 - def __str__(self):
84 s = [] 85 s.append('CODE: %s' % self.code) 86 s.append('HEADERS: %s' % self.headers) 87 s.append('MESSAGE:') 88 s.append(self.message) 89 return '\n'.join(s)
90 91
92 -class Transport:
93 """ 94 The transport I{interface}. 95 """ 96
97 - def __init__(self):
98 """ 99 Constructor. 100 """ 101 from suds.transport.options import Options 102 self.options = Options() 103 del Options
104
105 - def open(self, request):
106 """ 107 Open the url in the specified request. 108 @param request: A transport request. 109 @type request: L{Request} 110 @return: An input stream. 111 @rtype: stream 112 @raise TransportError: On all transport errors. 113 """ 114 raise Exception('not-implemented')
115
116 - def send(self, request):
117 """ 118 Send soap message. Implementations are expected to handle: 119 - proxies 120 - I{http} headers 121 - cookies 122 - sending message 123 - brokering exceptions into L{TransportError} 124 @param request: A transport request. 125 @type request: L{Request} 126 @return: The reply 127 @rtype: L{Reply} 128 @raise TransportError: On all transport errors. 129 """ 130 raise Exception('not-implemented')
131