Python urllib.request 模块,get_method() 实例源码

我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用urllib.request.get_method()

项目:maas    作者:maas    | 项目源码 | 文件源码
def put(self, location, params=None):
        """Dispatch a PUT request to a SeaMicro chassis.

        The seamicro box has order-dependent HTTP parameters, so we build
        our own get URL, and use a list vs. a dict for data, as the order is
        implicit.
        """
        opener = urllib.request.build_opener(urllib.request.HTTPHandler)
        url = self.build_url(location, params)
        request = urllib.request.Request(url)
        request.get_method = lambda: 'PUT'
        request.add_header('content-type', 'text/json')
        response = opener.open(request)
        json_data = self.parse_response(url, response)

        return json_data['result']
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_default_values(self):
        Request = urllib.request.Request
        request = Request("http://www.python.org")
        self.assertEqual(request.get_method(), 'GET')
        request = Request("http://www.python.org", {})
        self.assertEqual(request.get_method(), 'POST')
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_with_method_arg(self):
        Request = urllib.request.Request
        request = Request("http://www.python.org", method='HEAD')
        self.assertEqual(request.method, 'HEAD')
        self.assertEqual(request.get_method(), 'HEAD')
        request = Request("http://www.python.org", {}, method='HEAD')
        self.assertEqual(request.method, 'HEAD')
        self.assertEqual(request.get_method(), 'HEAD')
        request = Request("http://www.python.org", method='GET')
        self.assertEqual(request.get_method(), 'GET')
        request.method = 'HEAD'
        self.assertEqual(request.get_method(), 'HEAD')
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_default_values(self):
        Request = urllib.request.Request
        request = Request("http://www.python.org")
        self.assertEqual(request.get_method(), 'GET')
        request = Request("http://www.python.org", {})
        self.assertEqual(request.get_method(), 'POST')
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_with_method_arg(self):
        Request = urllib.request.Request
        request = Request("http://www.python.org", method='HEAD')
        self.assertEqual(request.method, 'HEAD')
        self.assertEqual(request.get_method(), 'HEAD')
        request = Request("http://www.python.org", {}, method='HEAD')
        self.assertEqual(request.method, 'HEAD')
        self.assertEqual(request.get_method(), 'HEAD')
        request = Request("http://www.python.org", method='GET')
        self.assertEqual(request.get_method(), 'GET')
        request.method = 'HEAD'
        self.assertEqual(request.get_method(), 'HEAD')
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_default_values(self):
        Request = urllib.request.Request
        request = Request("http://www.python.org")
        self.assertEqual(request.get_method(), 'GET')
        request = Request("http://www.python.org", {})
        self.assertEqual(request.get_method(), 'POST')
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_with_method_arg(self):
        Request = urllib.request.Request
        request = Request("http://www.python.org", method='HEAD')
        self.assertEqual(request.method, 'HEAD')
        self.assertEqual(request.get_method(), 'HEAD')
        request = Request("http://www.python.org", {}, method='HEAD')
        self.assertEqual(request.method, 'HEAD')
        self.assertEqual(request.get_method(), 'HEAD')
        request = Request("http://www.python.org", method='GET')
        self.assertEqual(request.get_method(), 'GET')
        request.method = 'HEAD'
        self.assertEqual(request.get_method(), 'HEAD')
项目:nexpose-client-python    作者:rapid7    | 项目源码 | 文件源码
def OpenWebRequest(uri, post_data, headers, timeout, get_method=None):
    request = urllib.request.Request(uri, post_data, headers)
    if get_method:
        request.get_method = get_method
    if timeout == 0:
        response = urllib.request.urlopen(request)
    else:
        response = urllib.request.urlopen(request, timeout=timeout)
    return response
项目:nexpose-client-python    作者:rapid7    | 项目源码 | 文件源码
def ExecuteWebRequest(uri, post_data, headers, timeout, get_method=None):
    response = OpenWebRequest(uri, post_data, headers, timeout, get_method)
    return response.read().decode('utf-8')
项目:nexpose-client-python    作者:rapid7    | 项目源码 | 文件源码
def ExecuteWithPostData_JSON(session_id, uri, sub_url, timeout, post_data, get_method):
    headers = CreateHeadersWithSessionCookieAndCustomHeader(session_id)
    headers["Content-Type"] = "application/json; charset=UTF-8"
    if isinstance(post_data, dict) or isinstance(post_data, list):
        post_data = json.dumps(post_data, separators=(',', ':'))
    post_data = post_data.encode('utf-8')
    return ExecuteWebRequest(uri + sub_url, post_data, headers, timeout, get_method)
项目:PassiveScanner    作者:jjf012    | 项目源码 | 文件源码
def put_request(self, api_path):
        request = urllib.request.Request(self.arachni_url + api_path)
        request.get_method = lambda: 'PUT'
        return urllib.request.urlopen(request).read().decode('utf8')
项目:PassiveScanner    作者:jjf012    | 项目源码 | 文件源码
def delete_request(self, api_path):
        request = urllib.request.Request(self.arachni_url + api_path)
        request.get_method = lambda: 'DELETE'
        return urllib.request.urlopen(request).read().decode('utf8')