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


Python HTTPResponse.recv方法代码示例

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


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

示例1: _read_resp

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import recv [as 别名]
 def _read_resp(self):
     # Let httplib handle the response part.
     from httplib import HTTPResponse
     from urllib import addinfourl
     resp = HTTPResponse(self.sock, strict=True, method=self.method)
     resp.begin()
     if resp.will_close:
         self.sock.close()
     else:
         # TODO Should make something of this, I suppose.
         self._active_resp = resp
     # Courtesy of urllib2, weird stuff going on here.
     resp.recv = resp.read
     fp = socket._fileobject(resp, close=True)
     rv = addinfourl(fp, resp.msg, self.get_full_url())
     rv.code = resp.status
     rv.msg = resp.reason
     return rv
开发者ID:erh,项目名称:simples3,代码行数:20,代码来源:htstream.py

示例2: urlopen_custom

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import recv [as 别名]
def urlopen_custom(req, rawserver):
    global _urlopener

    if not _urlopener:
        opener = FancyURLopener()
        _urlopener = opener
        # remove User-Agent
        del _urlopener.addheaders[:]

    if not isinstance(req, str):
        # for header in r.headers:
        #    _urlopener.addheaders.append((header, r.headers[header]))
        # return _urlopener.open(r.get_full_url(), r.data)

        # All this has to be done manually, since httplib and urllib 1 and 2
        # add headers to the request that some routers do not accept.
        # A minimal, functional request includes the headers:
        # Content-Length
        # Soapaction
        # I have found the following to be specifically disallowed:
        # User-agent
        # Connection
        # Accept-encoding

        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(req.get_full_url())

        if not scheme.startswith("http"):
            raise ValueError("UPnP URL scheme is not http: " + req.get_full_url())

        if len(path) == 0:
            path = "/"

        if netloc.count(":") > 0:
            host, port = netloc.split(":", 1)
            try:
                port = int(port)
            except:
                raise ValueError("UPnP URL port is not int: " + req.get_full_url())
        else:
            host = netloc
            port = 80

        header_str = ""
        data = ""
        method = ""
        header_str = " " + path + " HTTP/1.0\r\n"
        if req.has_data():
            method = "POST"
            header_str = method + header_str
            header_str += "Content-Length: " + str(len(req.data)) + "\r\n"
            data = req.data + "\r\n"
        else:
            method = "GET"
            header_str = method + header_str

        header_str += "Host: " + host + ":" + str(port) + "\r\n"

        for header in req.headers:
            header_str += header + ": " + str(req.headers[header]) + "\r\n"

        header_str += "\r\n"
        data = header_str + data

        try:
            rawserver._add_pending_connection(host)
            s.connect((host, port))
        finally:
            rawserver._remove_pending_connection(host)

        s.send(data)
        r = HTTPResponse(s, method=method)
        r.begin()

        r.recv = r.read
        fp = socket._fileobject(r)

        resp = addinfourl(fp, r.msg, req.get_full_url())
        resp.code = r.status
        resp.msg = r.reason

        return resp
    return _urlopener.open(req)
开发者ID:galaxy001,项目名称:libtorrent,代码行数:86,代码来源:NatTraversal.py


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