本文整理汇总了Python中httplib.ResponseNotReady方法的典型用法代码示例。如果您正苦于以下问题:Python httplib.ResponseNotReady方法的具体用法?Python httplib.ResponseNotReady怎么用?Python httplib.ResponseNotReady使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类httplib
的用法示例。
在下文中一共展示了httplib.ResponseNotReady方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HTTPResponse__getheaders
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ResponseNotReady [as 别名]
def HTTPResponse__getheaders(self):
"""Return list of (header, value) tuples."""
if self.msg is None:
raise httplib.ResponseNotReady()
return self.msg.items()
示例2: do_open
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ResponseNotReady [as 别名]
def do_open(self, http_class, req):
h = None
host = req.get_host()
if not host:
raise urllib2.URLError('no host given')
try:
need_new_connection = 1
key = self._get_connection_key(host)
h = self._connections.get(key)
if not h is None:
try:
self._start_connection(h, req)
except:
r = None
else:
try: r = h.getresponse()
except httplib.ResponseNotReady, e: r = None
except httplib.BadStatusLine, e: r = None
if r is None or r.version == 9:
# httplib falls back to assuming HTTP 0.9 if it gets a
# bad header back. This is most likely to happen if
# the socket has been closed by the server since we
# last used the connection.
if DEBUG: print "failed to re-use connection to %s" % host
h.close()
else:
if DEBUG: print "re-using connection to %s" % host
need_new_connection = 0
示例3: extractMSIInfo
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ResponseNotReady [as 别名]
def extractMSIInfo(self, path, wbs):
import robj
self.fileType = 'msi'
self.path = path
# This is here for backwards compatibility.
if not wbs.startswith('http'):
wbs = 'http://%s/api' % wbs
api = robj.connect(wbs)
api.msis.append(dict(
path=os.path.split(path)[1],
size=os.stat(path).st_size,
))
self.resource = api.msis[-1]
# put the actual file contents
self.resource.path = open(path)
self.resource.refresh()
self.productName = self.resource.name.encode('utf-8')
name = self.productName.split()
if len(name) > 1 and '.' in name[-1]:
name = '-'.join(name[:-1])
else:
name = '-'.join(name)
self.name = name
self.version = self.resource.version.encode('utf-8')
self.platform = self.resource.platform.encode('utf-8')
self.productCode = self.resource.productCode.encode('utf-8')
self.upgradeCode = self.resource.upgradeCode.encode('utf-8')
self.components = [ (x.uuid.encode('utf-8'), x.path.encode('utf-8'))
for x in self.resource.components ]
# clean up
try:
self.resource.delete()
except httplib.ResponseNotReady:
pass
示例4: _prefetch_in_background
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ResponseNotReady [as 别名]
def _prefetch_in_background(self, n, amount, offset):
headers = {
'Range': "bytes=" + str(max(offset, 0)) + "-" + str(
min((offset + amount) - 1, self.length) # noqa
),
}
self._wait_on_prefetch_connection(n)
while not self.pconn_terminated[n]:
try:
self.pconn[n].request(
"GET", self.parsed_url.path, headers=headers)
break
except CannotSendRequest:
sleep(1)
while not self.pconn_terminated[n]:
try:
res = self.pconn[n].getresponse()
break
except ResponseNotReady:
# Since we are sharing the connection wait for this to be
# ready
sleep(1)
if self.pconn_terminated[n]:
self._unwait_on_prefetch_connection(n)
return
else:
self._unwait_on_prefetch_connection(n)
if not(res.status >= 200 and res.status <= 299):
# Check for a valid status from the server
return
data = bytearray(res.length)
i = 0
for piece in iter(lambda: res.read(1024), bytes('')):
if not getattr(threading.currentThread(), "do_run", True):
break
data[i:i + len(piece)] = piece
i = i + len(piece)
else:
return bytes(data)
# Leaving the thread early, without
# reading all of the data this will
# make the connection unusable, refresh it
self._prepare_prefetch_connection(n)