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


Python urllib.addinfourl方法代码示例

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


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

示例1: probe_html5

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def probe_html5(self, result):

        class NoRedirectHandler(urllib2.HTTPRedirectHandler):

            def http_error_302(self, req, fp, code, msg, headers):
                infourl = urllib.addinfourl(fp, headers, req.get_full_url())
                infourl.status = code
                infourl.code = code
                return infourl
            http_error_300 = http_error_302
            http_error_301 = http_error_302
            http_error_303 = http_error_302
            http_error_307 = http_error_302

        opener = urllib2.build_opener(NoRedirectHandler())
        urllib2.install_opener(opener)

        r = urllib2.urlopen(urllib2.Request(result['url'], headers=result['headers']))
        if r.code == 200:
            result['url'] = r.read()
        return result 
开发者ID:kodi-czsk,项目名称:plugin.video.sosac.ph,代码行数:23,代码来源:sosac.py

示例2: _normalize_urllib_response

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def _normalize_urllib_response(response, request=None):
    if six.PY2:
        if not isinstance(response, urllib.addinfourl):
            raise TypeError("Cannot normalize this response object")
    else:
        if not isinstance(response, http.client.HTTPResponse):
            raise TypeError("Cannot normalize this response object")

    url = response.url
    status_code = response.getcode()
    content_type = response.headers.get('Content-Type')

    return Response(
        request=request,
        content=response.read(),
        url=url,
        status_code=status_code,
        content_type=content_type,
        response=response,
    ) 
开发者ID:pipermerriam,项目名称:flex,代码行数:22,代码来源:http.py

示例3: http_error_302

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:7,代码来源:openload.py

示例4: get_response

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def get_response(self):
        """Returns a copy of the current response."""
        return urllib.addinfourl(StringIO(self.data), self._response.info(), self._response.geturl()) 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:5,代码来源:browser.py

示例5: _make_response

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def _make_response(self, result, url):
        data = "\r\n".join(["%s: %s" % (k, v) for k, v in result.header_items])
        headers = httplib.HTTPMessage(StringIO(data))
        response = urllib.addinfourl(StringIO(result.data), headers, url)
        code, msg = result.status.split(None, 1)
        response.code, response.msg = int(code), msg
        return response 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:9,代码来源:browser.py

示例6: wsopen

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def wsopen(self, url, post, **params):
                noparam = params.pop('noparam',False)
                if noparam:
                        params = {}
                else:
                        if self.user is not None:
                                params['user'] = self.user
                        if self.password is not None:
                                params.pop('hmac', None)
                                HMAC=hmac.new(self.password)
                                for k,v in sorted(params.items()):
                                        HMAC.update("%s=%s" % (k,v))
                                params.update({'hmac':HMAC.hexdigest()})
                query = urllib.urlencode(params)
                if post:
                        body = query
                elif query:
                        url = "{}?{}".format(url, query)

                if self.debug:
                        if post:
                                print("POST:\n{}\n{!r}\n".format(url, body), file=sys.stderr)
                        else:
                                print("GET:\n{}\n".format(url), file=sys.stderr)

                class URLopener(urllib.FancyURLopener):
                        def http_error_default(self, url, fp, errcode, errmsg, headers):
                                return urllib.addinfourl(fp, headers, "http:" + url, errcode)
                try:
                        urllib._urlopener = URLopener()
                        if post:
                                resp = urllib.urlopen(url, body)
                        else:
                                resp = urllib.urlopen(url)
                except IOError as e:
                        raise WSError(url, msg=e)
                if self.debug:
                        print("RESPONSE:\n{}\n{}".format(resp.getcode(), resp.info()), file=sys.stderr)
                if resp.getcode() != 200:
                        raise WSError(url, resp.getcode(), resp.read())
                return resp 
开发者ID:alex-berard,项目名称:seq2seq,代码行数:43,代码来源:wsclient.py

示例7: get_response

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def get_response(self):
        """Returns a copy of the current response."""
        return addinfourl(BytesIO(self.data), self._response.info(), self._response.geturl()) 
开发者ID:Naayouu,项目名称:Hatkey,代码行数:5,代码来源:browser.py

示例8: _make_response

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def _make_response(self, result, url):

        data = "\r\n".join(["%s: %s" % (k, v) for k, v in result.header_items])

        if PY2:
            headers = HTTPMessage(BytesIO(data))
        else:
            import email
            headers = email.message_from_string(data)

        response = addinfourl(BytesIO(result.data), headers, url)
        code, msg = result.status.split(None, 1)
        response.code, response.msg = int(code), msg
        return response 
开发者ID:Naayouu,项目名称:Hatkey,代码行数:16,代码来源:browser.py

示例9: data_open

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def data_open(self, req):
            # data URLs as specified in RFC 2397.
            #
            # ignores POSTed data
            #
            # syntax:
            # dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
            # mediatype := [ type "/" subtype ] *( ";" parameter )
            # data      := *urlchar
            # parameter := attribute "=" value
            url = req.get_full_url()

            scheme, data = url.split(':', 1)
            mediatype, data = data.split(',', 1)

            # even base64 encoded data URLs might be quoted so unquote in any case:
            data = compat_urllib_parse_unquote_to_bytes(data)
            if mediatype.endswith(';base64'):
                data = binascii.a2b_base64(data)
                mediatype = mediatype[:-7]

            if not mediatype:
                mediatype = 'text/plain;charset=US-ASCII'

            headers = email.message_from_string(
                'Content-type: %s\nContent-length: %d\n' % (mediatype, len(data)))

            return compat_urllib_response.addinfourl(io.BytesIO(data), headers, url) 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:30,代码来源:compat.py

示例10: http_error_206

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def http_error_206(self, req, fp, code, msg, hdrs):
        # 206 Partial Content Response
        r = urllib.addinfourl(fp, hdrs, req.get_full_url())
        r.code = code
        r.msg = msg
        return r 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:8,代码来源:rangehandler.py

示例11: http_error_302

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def http_error_302(self, req, fp, code, msg, headers):
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
            infourl.status = code
            infourl.code = code
            return infourl 
开发者ID:tacy,项目名称:plugin.video.xunleicloud,代码行数:7,代码来源:addon.py

示例12: http_error_302

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, headers["Location"])
        infourl.status = code
        infourl.code = code
        return infourl 
开发者ID:alfa-addon,项目名称:addon,代码行数:7,代码来源:navigation.py

示例13: http_error_default

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def http_error_default(self, req, fp, code, msg, headers):
        if ((code / 100) == 3) and (code != 304):
            return self.http_error_302(req, fp, code, msg, headers)
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        return infourl 
开发者ID:MyRobotLab,项目名称:pyrobotlab,代码行数:8,代码来源:feedparser.py

示例14: http_error_302

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def http_error_302(self, req, fp, code, msg, headers):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code
        return infourl 
开发者ID:MyRobotLab,项目名称:pyrobotlab,代码行数:10,代码来源:feedparser.py

示例15: http_error_301

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import addinfourl [as 别名]
def http_error_301(self, req, fp, code, msg, headers):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers)
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code
        return infourl 
开发者ID:MyRobotLab,项目名称:pyrobotlab,代码行数:10,代码来源:feedparser.py


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