本文整理匯總了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)