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


Python request.has_proxy方法代码示例

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


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

示例1: has_proxy

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import has_proxy [as 别名]
def has_proxy(self):
        return self.selector == self.full_url 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:4,代码来源:request.py

示例2: do_request_

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import has_proxy [as 别名]
def do_request_(self, request):
        host = request.host
        if not host:
            raise URLError('no host given')

        if request.data is not None:  # POST
            data = request.data
            if isinstance(data, str):
                msg = "POST data should be bytes or an iterable of bytes. " \
                      "It cannot be of type str."
                raise TypeError(msg)
            if not request.has_header('Content-type'):
                request.add_unredirected_header(
                    'Content-type',
                    'application/x-www-form-urlencoded')
            if not request.has_header('Content-length'):
                try:
                    mv = memoryview(data)
                except TypeError:
                    if isinstance(data, collections.Iterable):
                        raise ValueError("Content-Length should be specified "
                                "for iterable data of type %r %r" % (type(data),
                                data))
                else:
                    request.add_unredirected_header(
                            'Content-length', '%d' % (len(mv) * mv.itemsize))

        sel_host = host
        if request.has_proxy():
            scheme, sel = splittype(request.selector)
            sel_host, sel_path = splithost(sel)
        if not request.has_header('Host'):
            request.add_unredirected_header('Host', sel_host)
        for name, value in self.parent.addheaders:
            name = name.capitalize()
            if not request.has_header(name):
                request.add_unredirected_header(name, value)

        return request 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:41,代码来源:request.py

示例3: do_request_

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import has_proxy [as 别名]
def do_request_(self, request):
        host = request.host
        if not host:
            raise URLError('no host given')

        if request.data is not None:  # POST
            data = request.data
            if isinstance(data, str):
                msg = "POST data should be bytes, an iterable of bytes, " \
                      "or a file object. It cannot be of type str."
                raise TypeError(msg)
            if not request.has_header('Content-type'):
                request.add_unredirected_header(
                    'Content-type',
                    'application/x-www-form-urlencoded')
            if (not request.has_header('Content-length')
                    and not request.has_header('Transfer-encoding')):
                content_length = self._get_content_length(request)
                if content_length is not None:
                    request.add_unredirected_header(
                            'Content-length', str(content_length))
                else:
                    request.add_unredirected_header(
                            'Transfer-encoding', 'chunked')

        sel_host = host
        if request.has_proxy():
            scheme, sel = splittype(request.selector)
            sel_host, sel_path = splithost(sel)
        if not request.has_header('Host'):
            request.add_unredirected_header('Host', sel_host)
        for name, value in self.parent.addheaders:
            name = name.capitalize()
            if not request.has_header(name):
                request.add_unredirected_header(name, value)

        return request 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:39,代码来源:request.py

示例4: do_request_

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import has_proxy [as 别名]
def do_request_(self, request):
        host = request.host
        if not host:
            raise URLError('no host given')

        if request.data is not None:  # POST
            data = request.data
            if isinstance(data, str):
                msg = "POST data should be bytes or an iterable of bytes. " \
                      "It cannot be of type str."
                raise TypeError(msg)
            if not request.has_header('Content-type'):
                request.add_unredirected_header(
                    'Content-type',
                    'application/x-www-form-urlencoded')
            if not request.has_header('Content-length'):
                size = None
                try:
                    ### For Python-Future:
                    if PY2 and isinstance(data, array.array):
                        # memoryviews of arrays aren't supported
                        # in Py2.7. (e.g. memoryview(array.array('I',
                        # [1, 2, 3, 4])) raises a TypeError.)
                        # So we calculate the size manually instead:
                        size = len(data) * data.itemsize
                    ###
                    else:
                        mv = memoryview(data)
                        size = len(mv) * mv.itemsize
                except TypeError:
                    if isinstance(data, collections.Iterable):
                        raise ValueError("Content-Length should be specified "
                                "for iterable data of type %r %r" % (type(data),
                                data))
                else:
                    request.add_unredirected_header(
                            'Content-length', '%d' % size)

        sel_host = host
        if request.has_proxy():
            scheme, sel = splittype(request.selector)
            sel_host, sel_path = splithost(sel)
        if not request.has_header('Host'):
            request.add_unredirected_header('Host', sel_host)
        for name, value in self.parent.addheaders:
            name = name.capitalize()
            if not request.has_header(name):
                request.add_unredirected_header(name, value)

        return request 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:52,代码来源:request.py

示例5: do_request_

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import has_proxy [as 别名]
def do_request_(self, request):
        host = request.host
        if not host:
            raise URLError('no host given')

        if request.data is not None:  # POST
            data = request.data
            if isinstance(data, str):
                msg = "POST data should be bytes or an iterable of bytes. " \
                      "It cannot be of type str."
                raise TypeError(msg)
            if not request.has_header('Content-type'):
                request.add_unredirected_header(
                    'Content-type',
                    'application/x-www-form-urlencoded')
            if not request.has_header('Content-length'):
                size = None
                try:
                    ### For Python-Future:
                    if PY2 and isinstance(data, array.array):
                        # memoryviews of arrays aren't supported
                        # in Py2.7. (e.g. memoryview(array.array('I',
                        # [1, 2, 3, 4])) raises a TypeError.)
                        # So we calculate the size manually instead:
                        size = len(data) * data.itemsize
                    ###
                    else:
                        mv = memoryview(data)
                        size = len(mv) * mv.itemsize
                except TypeError:
                    if isinstance(data, Iterable):
                        raise ValueError("Content-Length should be specified "
                                "for iterable data of type %r %r" % (type(data),
                                data))
                else:
                    request.add_unredirected_header(
                            'Content-length', '%d' % size)

        sel_host = host
        if request.has_proxy():
            scheme, sel = splittype(request.selector)
            sel_host, sel_path = splithost(sel)
        if not request.has_header('Host'):
            request.add_unredirected_header('Host', sel_host)
        for name, value in self.parent.addheaders:
            name = name.capitalize()
            if not request.has_header(name):
                request.add_unredirected_header(name, value)

        return request 
开发者ID:alfa-addon,项目名称:addon,代码行数:52,代码来源:request.py


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