Changeset 6580
- Timestamp:
- 16/02/10 17:10:49 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/soap/client.py
r6578 r6580 143 143 return self.__fileobject 144 144 145 146 class CapitalizedKeysDict(dict): 147 """Extend dict type to make keys capitalized. Keys must be string type""" 148 def __init__(self, *arg, **kw): 149 if len(arg) > 0: 150 if isinstance(arg[0], dict): 151 arg[0] = [(k.capitalize(), v) for k, v in arg[0].items()] 152 else: 153 arg[0] = [(k.capitalize(), v) for k, v in arg[0]] 154 155 kw = dict([(k.capitalize(), v) for k, v in kw.items()]) 156 157 super(CapitalizedKeysDict, self).__init__(*arg, **kw) 158 159 def __setitem__(self, k, v): 160 if not isinstance(k, basestring): 161 raise TypeError('Key must be string type; got %r' % type(k)) 162 163 super(CapitalizedKeysDict, self).__setitem__(k.capitalize(), v) 164 145 165 146 166 class UrlLib2SOAPClient(SOAPClientBase): 147 167 """urllib2 based SOAP Client""" 148 DEFAULT_HTTP_HEADER = {'Content-type': 'text/xml'}168 DEFAULT_HTTP_HEADER = CapitalizedKeysDict({'Content-type': 'text/xml'}) 149 169 150 170 def __init__(self): … … 156 176 self.__httpHeader = UrlLib2SOAPClient.DEFAULT_HTTP_HEADER.copy() 157 177 158 def _getHttpHeader(self): 178 @property 179 def httpHeader(self): 180 "Set HTTP header fields in this dict object" 159 181 return self.__httpHeader 160 182 161 def _setHttpHeader(self, value): 162 if not isinstance(value, dict): 163 raise TypeError('Expecting dict type for "httpHeader" attribute; ' 164 'got %r instead' % type(value)) 165 self.__httpHeader = value 166 167 httpHeader = property(_getHttpHeader, _setHttpHeader, 168 doc="Set HTTP header fields in this dict object") 169 183 def _getSOAPAction(self): 184 return self.__httpHeader.get('Soapaction') 185 186 def _setSOAPAction(self, value): 187 if not isinstance(value, basestring): 188 raise TypeError("Setting request soapAction: got %r, expecting " 189 "string type" % type(value)) 190 self.__httpHeader['Soapaction'] = value 191 192 soapAction = property(fget=_getSOAPAction, 193 fset=_setSOAPAction, 194 doc="SOAPAction HTTP header field setting") 195 170 196 def _getTimeout(self): 171 197 return self.__timeout … … 174 200 if not isinstance(value, (int, float)): 175 201 raise TypeError("Setting request timeout: got %r, expecting int " 176 " float type" % type(value))202 "or float type" % type(value)) 177 203 self.__timeout = value 178 204
Note: See TracChangeset
for help on using the changeset viewer.