本文整理汇总了Python中httplib.HTTPResponse.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPResponse.__init__方法的具体用法?Python HTTPResponse.__init__怎么用?Python HTTPResponse.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类httplib.HTTPResponse
的用法示例。
在下文中一共展示了HTTPResponse.__init__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import __init__ [as 别名]
def __init__(self, response_str):
source = FakeSocket(response_str)
HTTPResponse.__init__(self, source)
self.begin()
# Request
# error_code
# command GET/POST
# path PATH
# request_version "HTTP/1.0"
# headers "Headers"
# headers.keys()
# headers['host']
# Response
# status CODE
# getheader('Content-Length')
# read(len(response_str))
示例2: __init__
# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import __init__ [as 别名]
def __init__(self, data):
"""Initialize a new object.
:param data: a stream of data which contain a discovery response in the HTTP format.
:type data: str or list[bytes] or list[int]
:rtype: DiscoveryResponse
"""
# create a fake socket which is needed by the base class to initialize.
# initialize the base class
HTTPResponse.__init__(self, DiscoveryResponse._FakeSocket(data), 1)
# turn off any debugging in the base class
self.debuglevel = 0
# let the base class parse the input
self.begin()
# set dedicated properties from the discovery response headers
self.__location = self.getheader("location")
self.__usn = self.getheader("usn")
self.__service = self.getheader("st")
# parse the location URL
urlParts = urlparse(self.location)
self.__locationProtocol = urlParts.scheme.lower()
self.__locationPath = urlParts.path
self.__locationHost = urlParts.hostname
# set the right port depending on if a port was given or the given protocol
if urlParts.port:
self.__locationPort = urlParts.port
else:
if self.__locationProtocol == "https":
self.__locationPort = 443
else:
self.__locationPort = 80