当前位置: 首页>>代码示例>>Python>>正文


Python HTTP.close方法代码示例

本文整理汇总了Python中httplib.HTTP.close方法的典型用法代码示例。如果您正苦于以下问题:Python HTTP.close方法的具体用法?Python HTTP.close怎么用?Python HTTP.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在httplib.HTTP的用法示例。


在下文中一共展示了HTTP.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import close [as 别名]
    def run(self):
        try:
            self.downloaded = os.path.getsize(self.filename)
        except OSError:
            self.downloaded = 0

        self.start_pointer = self.ranges[0] + self.downloaded
        if self.start_pointer >= self.ranges[1]:
            print '%s has been over.' % self.filename
            return

        types = urllib.splittype(self.url)
        host, res = urllib.splithost(types[1])
        h = HTTP()
        h.connect(host)
        h.putrequest('GET', res)
        h.putheader('Host', host)
        h.putheader('Range', "bytes=%d-%d" % (self.start_pointer, self.ranges[1]))
        h.endheaders()
        response = h._conn.getresponse()
        data = response.read(self.once_buffer)
        while data:
            file_opener = open(self.filename, 'ab+')
            file_opener.write(data)
            file_opener.close()
            self.downloaded += len(data)
            data = response.read(self.once_buffer)
        h.close()
开发者ID:games,项目名称:py-onecore,代码行数:30,代码来源:downloader.py

示例2: identify

# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import close [as 别名]
def identify(host):
    h = HTTP(host)
    h.putrequest('GET', 'http://%s/' % host)
    h.putheader('Accept', '*/*')
    h.endheaders()
    errcode, errmsg, response = h.getreply()
    h.close()
    patterns.attempts = response.headers
    try: str = response['server']
    except: str = None
    return (str, None)
开发者ID:bruceg,项目名称:siteinfo,代码行数:13,代码来源:http.py

示例3: gethttpfile

# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import close [as 别名]
def gethttpfile(url, size=1024*1024):
  from urllib import splithost
  from httplib import HTTP
  if not url.startswith('http:'):
    raise ValueError, "URL %s" % url
  host, selector = splithost(url[5:])
  h = HTTP(host)
  h.putrequest('GET', url)
  h.endheaders()
  h.getreply()
  res = h.getfile().read(size)
  h.close()
  return res
开发者ID:ddxofy,项目名称:hda-analyzer-mb52,代码行数:15,代码来源:hda_analyzer.py

示例4: splithost

# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import close [as 别名]
import sys
from urllib import splithost
from httplib import HTTP

if os.path.exists("/dev/shm"):
  TMPDIR="/dev/shm"
else:
  TMPDIR="/tmp"
TMPDIR += "/hda-analyzer"
print "Using temporary directory: %s" % TMPDIR
print "You may remove this directory when finished or if you like to"
print "download the most recent copy of hda-analyzer tool."
if not os.path.exists(TMPDIR):
  os.mkdir(TMPDIR)
for f in FILES:
  dest = TMPDIR + '/' + f
  if os.path.exists(dest):
    print "File cached " + dest
    continue
  print "Downloading file %s" % f
  host, selector = splithost(URL[5:])
  h = HTTP(host)
  h.putrequest('GET', URL + f)
  h.endheaders()
  h.getreply()
  contents = h.getfile().read(2*1024*1024)
  h.close()
  open(dest, "w+").write(contents)
print "Downloaded all files, executing %s" % FILES[0]
os.system("python %s" % TMPDIR + '/' + FILES[0] + ' ' + ' '.join(sys.argv[1:]))
开发者ID:fishilico,项目名称:enable-headphones,代码行数:32,代码来源:run.py


注:本文中的httplib.HTTP.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。