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


Python Request.__init__方法代码示例

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


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

示例1: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
    def __init__(self, *args, **kwargs):
        Request.__init__(self, *args, **kwargs)

        logger.info("HTTP request: %s" % args[0])
        self.add_header("Cookie", "guid=B11E0A0A522C8371X1378648945")
        self.add_header(
            "User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X" "10.8; rv:23.0) Gecko/20100101 Firefox/23.0"
        )
        self.add_header("Accept", "text/html,application/xhtml+xml," "application/xml;q=0.9,*/*;q=0.8")
        self.add_header("Accept-Language", "en-us,en;q=0.5")
        self.add_header("Accept-Encoding", "gzip,deflate")
        self.add_header("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
开发者ID:TalLinzen,项目名称:russian-preps,代码行数:14,代码来源:httptools.py

示例2: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
    def __init__(self, url, method="GET", headers=None, data=None,
                 downloadTo=None, closeConnection=False, proxy=None,
                 redirectedFrom=None, unredirectedHeaders=None, **kw):
        """
        """
        headers = headers or dict()
        urllib2_Request.__init__(
                self, str(url), data=data, headers=headers,
                origin_req_host=kw.get("origin_req_host", redirectedFrom),
                unverifiable=kw.get("unverifiable", False),
            )
        Message.__init__(self, url, method, self.headers)
        self.host = self._url.host
        self.port = self._url.port
        self.setProxy(proxy)

        assert isinstance(self.headers, util.InsensitiveDict)
        unredirectedHeaders = unredirectedHeaders or dict()
        self.unredirectedHeaders = util.InsensitiveDict(unredirectedHeaders)

        self.closeConnection = closeConnection is True

        self.downloadTo = downloadTo
        self.redirectedTo = None
        self.redirectedFrom = tuple()
        self.response = defer.Deferred()
开发者ID:alexstaytuned,项目名称:tx-pendrell,代码行数:28,代码来源:messages.py

示例3: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
    def __init__(self, url, data=None, headers=None, origin_req_host=None, unverifiable=False):
        '''
        Constructor. It delegates construction to the base class
        Request and initializes the member variables

        It performs an additional call of Request.get_type and Request.get_host
        to ensure that the Request object is properly initialized. Because this
        is done by the urllib2 library, but we are just using the request

        @param url: url to be requested in the HTTP request
        @type url: str
        @param data: data for the HTTP request body (which enforces a POST)
        @type data: str
        @param headers: dictionary of header name/header value
        @type headers: dict
        @param origin_req_host: request host of the origin transaction as per
                                RFC 2965 - Host name or IP address of the host
        @type origin_req_host: str
        @param unverifiable: if the request was not verified/requested by the end
                             user and it is rather automatic (redirection, download
                             of a picture inside a web page) - RFC 2965
        @type unverifiable: bool
        '''
        if headers is None:
            headers = dict()
        Request.__init__(self, url, data, headers, origin_req_host, unverifiable)
        self.parsed = urlsplit(url)
        # Done to force split of the url fields inside the request
        self.get_type()
        self.get_host()
开发者ID:mementum,项目名称:bfrelay,代码行数:32,代码来源:httxrequest.py

示例4: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
    def __init__(self, *args, **kwargs):
        Request.__init__(self, *args, **kwargs)

        logger.info("HTTP request: %s" % args[0])
        self.add_header('User-Agent', 'Mozilla/5.0 (Macintosh; U; '
                        'Intel Mac OS X 10.5; en-US; rv:1.9.0.1) '
                        'Gecko/2008070206 Firefox/3.0.1')
        self.add_header('Accept', 'text/html,application/xhtml+xml,'
                        'application/xml;q=0.9,*/*;q=0.8')
        self.add_header('Accept-Language', 'en-us,en;q=0.5')
        self.add_header('Accept-Encoding', 'gzip,deflate')
        self.add_header('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7')
开发者ID:TalLinzen,项目名称:hebrew-blog-corpus,代码行数:14,代码来源:httptools.py

示例5: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
 def __init__(self , url , apiKey , data=None , headers={} , 
         origin_req_host=None , unverifiable=False):
     if apiKey is not None:
         headers['X-Gallery-Request-Key'] = apiKey
     if data is not None:
         if isinstance(data , dict):
             data = 'entity=%s' % quote(json.dumps(data , 
                 separators=(',' , ':')))
         elif type(data) not in types.StringTypes:
             raise TypeError('Invalid type for data.  It should be '
                 'a "dict" or "str", not %s' % type(data))
         headers['Content-Length'] = str(len(data))
     Request.__init__(self , url , data , headers , origin_req_host ,
         unverifiable)
开发者ID:Armani22,项目名称:gallery3-contrib,代码行数:16,代码来源:Requests.py

示例6: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
 def __init__(self, url, data = None, headers = {}, version = 'HTTP/1.1'):
     self._setupflags()
     self._debuglevel = 0
     self._response = None
     self._cookies = []
     self._request_line = None
     self._header_producer = None
     self._body_producer = None
     self._outgoing_producer = None
     self._state_listeners = []
     _Request.__init__(self, url, None, headers)
     self.headers = HeaderDictionary.from_name_value_dict(self.headers)
     self._set_version(version)
     self.set_data(data)
开发者ID:mcruse,项目名称:monotone,代码行数:16,代码来源:request.py

示例7: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
    def __init__(self, url, parameters={}, data=None, headers={}, method=None):

        if parameters:
            parameters = urlencode(parameters)
            if method == "POST":
                headers["Content-Type"] = "application/x-www-form-urlencoded"
                data = parameters.encode('ascii')
            else:
                url += "?" + parameters
        Request.__init__(self, url, data, headers)
        self.method = method

        self.add_header("Cache-Control", "no-cache")
        self.add_header("Pragma", "no-cache")
        self.add_header("Accept", 
                        "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2")
        self.add_header("Connection", "keep-alive") 
开发者ID:icatproject,项目名称:python-icat,代码行数:19,代码来源:ids.py

示例8: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
 def __init__(self, *args, **kwargs):
     self._http_request_method = kwargs.pop("method", "GET")
     uRequest.__init__(self, *args, **kwargs)
     self.add_header("content-type", "application/json")
开发者ID:maximesteisel,项目名称:webtriathlon,代码行数:6,代码来源:sclient.py

示例9: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
 def __init__(self, url, data='', headers={}):
     Request.__init__(self, url, data, headers)
     Request.add_header(self, 'User-Agent',
                  'NilanjanBot(nilanjan-basu.appspot.com/bot/testbot.html)')
开发者ID:nilanjanbasu,项目名称:Webcrawler,代码行数:6,代码来源:utils.py

示例10: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
 def __init__(self, *args, **kwargs):
     """ Constructor """
     self._method = kwargs.pop('method', 'GET')
     assert self._method in ['GET', 'POST', 'PUT', 'DELETE']
     Request.__init__(self, *args, **kwargs)
开发者ID:alienwang2012,项目名称:nuxeo-distribution,代码行数:7,代码来源:net.py

示例11: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
 def __init__(self, *args, **kwargs):
   self._method = kwargs.pop('method', None)
   _Request.__init__(self, *args, **kwargs)
开发者ID:bdacode,项目名称:gcsms,代码行数:5,代码来源:__init__.py

示例12: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
 def __init__(self, *args, **kwargs):
   self._method = kwargs.get('method')
   if self._method:
       del kwargs['method']
   Request.__init__(self, *args, **kwargs)
开发者ID:FieldDB,项目名称:clam,代码行数:7,代码来源:util.py

示例13: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
 def __init__(self, method, *args, **kwargs):
     URLLibRequest.__init__(self, *args, **kwargs) # ARRGH old-style classes!
     self._method = method
开发者ID:vmalloc,项目名称:json_rest,代码行数:5,代码来源:sender.py

示例14: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
 def __init__(self, method, *args, **kwargs):
     self._method = method
     Request.__init__(self, *args, **kwargs)
开发者ID:ytang,项目名称:winazurestorage,代码行数:5,代码来源:common.py

示例15: __init__

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
 def __init__(self, method=None, *args, **kwargs):
     Request.__init__(self, *args, **kwargs)
     self.method = method
开发者ID:olivier-m,项目名称:pmill,代码行数:5,代码来源:api.py


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