本文整理汇总了Python中suds.transport.http.HttpTransport类的典型用法代码示例。如果您正苦于以下问题:Python HttpTransport类的具体用法?Python HttpTransport怎么用?Python HttpTransport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpTransport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, **kwargs):
"""
@param kwargs: Keyword arguments.
- B{proxy} - An http proxy to be specified on requests.
The proxy is defined as {protocol:proxy,}
- type: I{dict}
- default: {}
- B{timeout} - Set the url open timeout (seconds).
- type: I{float}
- default: 90
- B{username} - The username used for http authentication.
- type: I{str}
- default: None
- B{password} - The password used for http authentication.
- type: I{str}
- default: None
- B{unverified_context} - Use an unverified context for the
connection, i.e. disabling HTTPS certificate validation.
- type: I{bool}
- default: False
"""
HttpTransport.__init__(self, **kwargs)
self.pm = urllib.request.HTTPPasswordMgrWithDefaultRealm()
if self.options.unverified_context:
import ssl
self.HTTPSHandler = urllib.request.HTTPSHandler(context=ssl._create_unverified_context())
else:
self.HTTPSHandler = urllib.request.HTTPSHandler()
示例2: auth
def auth(ver, type, username, password):
if ver == 2:
if type == 'up':
auth_client = Client(AUTH_URL_ver2, username = username, password = password) #version 2.0
SID = auth_client.service.authenticate()
return SID
elif type == 'ip':
auth_client = Client(AUTH_URL_ver2)
SID = auth_client.service.authenticate()
return SID
else:
print "Type either 'ip' or 'up'. 'ip' for ip access, 'up' for username/password access"
elif ver == 3:
if type == 'up':
username_password = ['username_password'][username]
#Your username/password from a purchased subscription should go here!
auth = HttpTransport()
auth_sender = urllib2.build_opener(HTTPAuthSender(username_password))
auth.urlopener = auth_sender
auth_client = Client(AUTH_URL_ver3, transport = auth)
SID = auth_client.service.authenticate()
return SID
elif type == 'ip':
auth_client = Client(AUTH_URL_ver3) #comment out if using username, password. #version 3.0
SID = auth_client.service.authenticate()
return SID
else:
print "Type either 'ip' or 'up'. 'ip' for ip access, 'up' for username/password access. username is an integer, password can be a null value for version 3."
else:
print "Authentication failed. Invalid version. Your request was not supported by this authentication module."
示例3: search_lite
def search_lite(fieldtag, searchterm, ver, count, SID):
#fieldtag must be 'PN = ' or 'CD ='
http = HttpTransport()
opener = urllib2.build_opener(HTTPSudsPreprocessor(SID))
http.urlopener = opener
client_obj = Client(SEARCH_LITE_URL[int(ver - 2)], transport = http, retxml = True)
query = fieldtag + '=' + searchterm
#construct query and retrieve field parameters
qparams = {
'databaseId' : 'DIIDW',
'userQuery' : query,
'queryLanguage' : 'en',
'editions' : [{
'collection' : 'DIIDW',
'edition' : 'CDerwent',
},{
'collection' : 'DIIDW',
'edition' : 'MDerwent',
},{
'collection' : 'DIIDW',
'edition' : 'EDerwent',
}]
}
rparams = {
'count' : count, # 1-500
'firstRecord' : 1,
'sortField' : [{
'name' : 'TC',
'sort' : 'D',
}]
}
result = client_obj.service.search(qparams, rparams)
return result
示例4: __init__
def __init__(self, slug=None, session=None, related_objects=None, timeout=None):
self.related_objects = related_objects or ()
self.slug = slug
self.timeout = timeout
# super won't work because not using new style class
HttpTransport.__init__(self)
self._session = session or security_requests.SecuritySession()
示例5: initSearchClient
def initSearchClient(self):
print 'initialize search....'
http = HttpTransport()
opener = urllib2.build_opener(HTTPSudsPreprocessor(self.SID))
http.urlopener = opener
self.client['search'] = Client(self.url['search'], transport = http)
print 'searching initializtion done'
示例6: _add_sid
def _add_sid(self):
"""Create URL opener with authentication token as header."""
opener = urllib2.build_opener()
opener.addheaders = [('Cookie', 'SID="'+self.sid_token+'"')]
http = HttpTransport()
http.urlopener = opener
self._establish_search_client(http)
示例7: __init__
def __init__(self, key, cert, *args, **kwargs):
"""
@param key: full path for the client's private key file
@param cert: full path for the client's PEM certificate file
"""
HttpTransport.__init__(self, *args, **kwargs)
self.key = key
self.cert = cert
示例8: __init__
def __init__(self, key, cert, *args, **kwargs):
"""
@param key: full path for the client's private key file
@param cert: full path for the client's PEM certificate file
"""
HttpTransport.__init__(self, *args, **kwargs)
self.key = key
self.cert = cert
self.urlopener = u2.build_opener(self._get_auth_handler())
示例9: open
def open(self, request):
url = request.url
if url.startswith('file:'):
return HttpTransport.open(self, request)
else:
resp = self._session.get(url)
resp.raise_for_status()
return BytesIO(resp.content)
示例10: u2handlers
def u2handlers(self):
try:
from ntlm import HTTPNtlmAuthHandler
except ImportError:
raise Exception("Cannot import python-ntlm module")
handlers = HttpTransport.u2handlers(self)
handlers.append(HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(self.pm))
return handlers
示例11: send
def send(self, request):
self.addcredentials(request)
r = XMLParser.parse(request.message.decode('ascii'))
data = dump_records(r)
request.message = data
request.headers['Content-Type'] = 'application/soap+msbin1'
# request.message = request.message()
return HttpTransport.send(self, request)
示例12: send
def send(self, request):
request.headers['Accept-encoding'] = 'gzip'
result = HttpTransport.send(self, request)
if ('content-encoding' in result.headers and
result.headers['content-encoding'] == 'gzip') :
buf = BytesIO(result.message)
f = gzip.GzipFile(fileobj=buf)
result.message = f.read()
return result
示例13: __init__
def __init__(self, **kwargs):
"""
@param kwargs: Keyword arguments.
- B{proxy} - An http proxy to be specified on requests.
The proxy is defined as {protocol:proxy,}
- type: I{dict}
- default: {}
- B{timeout} - Set the url open timeout (seconds).
- type: I{float}
- default: 90
- B{username} - The username used for http authentication.
- type: I{str}
- default: None
- B{password} - The password used for http authentication.
- type: I{str}
- default: None
"""
HttpTransport.__init__(self, **kwargs)
self.pm = u2.HTTPPasswordMgrWithDefaultRealm()
示例14: search
def search(fieldtag, searchterm, ver, count, SID):
'''
Makes a search query to the database.
:param fieldtag: fieldtag must be 'PN = ' or 'CD ='
:param searchterm: search term. in this case, the patent number.
:param ver: version 2 or 3. refer to the thomson reuters documentation.
:param count: requested retrieval count.
:param SID: Session ID.
:return: output xml.
'''
http = HttpTransport()
opener = urllib2.build_opener(HTTPSudsPreprocessor(SID))
http.urlopener = opener
client_obj = Client(SEARCH_URL[int(ver - 2)], transport = http, retxml = True)
query = fieldtag + '=' + searchterm
#construct query and retrieve field parameters
qparams = {
'databaseId' : 'DIIDW',
'userQuery' : query,
'queryLanguage' : 'en',
'editions' : [{
'collection' : 'DIIDW',
'edition' : 'CDerwent',
},{
'collection' : 'DIIDW',
'edition' : 'MDerwent',
},{
'collection' : 'DIIDW',
'edition' : 'EDerwent',
}]
}
rparams = {
'count' : count, # 1-500
'firstRecord' : 1,
'sortField' : [{
'name' : 'Relevance',
'sort' : 'D',
}]
}
result = client_obj.service.search(qparams, rparams)
return result
示例15: send
def send(self, request):
request.headers['Accept-encoding'] = 'gzip'
result = HttpTransport.send(self, request)
if result.headers['content-encoding'] == 'gzip':
try:
result.message = gzip.decompress(result.message)
except OSError:
pass
return result