• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python network.HTTP类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中Naked.toolshed.network.HTTP的典型用法代码示例。如果您正苦于以下问题:Python HTTP类的具体用法?Python HTTP怎么用?Python HTTP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_http_get_response_check_200

 def test_http_get_response_check_200(self):
     """Confirm that the response object contains 200 status code"""
     http = HTTP('http://httpbin.org/status/200')
     http.get()
     self.assertEqual(http.res.status_code, 200) # test the response object attribute
     response = http.response()
     self.assertEqual(response.status_code, 200) # test the returned object from the response() method
开发者ID:chrisidefix,项目名称:naked,代码行数:7,代码来源:test_NETWORK.py


示例2: test_http_get_text_exists

 def test_http_get_text_exists(self):
     """Test HTTP GET request with text file write does not overwrite existing file by default"""
     filepath = os.path.join('testfiles', 'keep', 'file1.txt')
     if not file_exists(filepath):
         raise RuntimeError("Missing test file for the unit test.")
     http = HTTP("https://raw.github.com/chrissimpkins/six-four/master/LICENSE")
     self.assertFalse(http.get_txt_write_file(filepath)) # should not overwrite by default
开发者ID:chrisidefix,项目名称:naked,代码行数:7,代码来源:test_NETWORK.py


示例3: test_http_get_binary_file_exists

 def test_http_get_binary_file_exists(self):
     """Test HTTP GET request and write to binary file when it does exist - should not overwrite by default"""
     filepath = os.path.join('testfiles', 'keep', 'test.tar.gz')
     if not file_exists(filepath):
         raise RuntimeError("Missing test file for the unit test")
     http = HTTP("https://github.com/chrissimpkins/six-four/tarball/master")
     self.assertFalse(http.get_bin_write_file(filepath)) # should not overwrite file by default
开发者ID:chrisidefix,项目名称:naked,代码行数:7,代码来源:test_NETWORK.py


示例4: test_http_get_response_check_301

 def test_http_get_response_check_301(self):
     """Confirm that the reponse object contains 301 status code when do not follow redirects"""
     http = HTTP('http://httpbin.org/status/301')
     http.get(False) # do not follow redirects
     self.assertEqual(http.res.status_code, 301)
     response = http.response()
     self.assertEqual(response.status_code, 301)
开发者ID:chrisidefix,项目名称:naked,代码行数:7,代码来源:test_NETWORK.py


示例5: test_http_get_response_check_404

 def test_http_get_response_check_404(self):
     """Confirm that the response object contains a 404 status code when authentication required"""
     http = HTTP('http://httpbin.org/status/404')
     http.get()
     self.assertEqual(http.res.status_code, 404)
     response = http.response()
     self.assertEqual(response.status_code, 404)
开发者ID:chrisidefix,项目名称:naked,代码行数:7,代码来源:test_NETWORK.py


示例6: test_http_get_response_obj_present

 def test_http_get_response_obj_present(self):
     """Confirm that response object is set after GET request with site that exists"""
     http = HTTP('http://google.com')
     http.get()
     self.assertTrue(http.res)             # the response object
     self.assertTrue(http.res.content)     # the content of the response
     self.assertTrue(http.res.status_code) # the status code
开发者ID:chrisidefix,项目名称:naked,代码行数:7,代码来源:test_NETWORK.py


示例7: post_response

    def post_response(self):
        try:
            the_url = prepare_url(self.url)
            http = HTTP(the_url)
            http.post()
            resp = http.response()

            # confirm that a response was returned, abort if not
            if resp == None and the_url.startswith('https://'):
                stderr("Unable to connect to the requested URL. This can happen if the secure HTTP protocol is not supported at the requested URL.")
                sys.exit(1)
            elif resp == None:
                stderr("Unable to connect to the requested URL. Please confirm your URL and try again.")
                sys.exit(1)

            if len(resp.history) > 0:
                count = len(resp.history)
                for i in range(count):
                    print(str(resp.history[i].status_code) + " : " + str(resp.history[i].url))
            print(str(http.res.status_code) + " : " + the_url)
            exit_success()
        except ConnectionError as ce:
            error_string = "Unable to connect to the URL, " + self.url
            stderr(error_string, 1)
        except Exception as e:
            raise e
开发者ID:chrissimpkins,项目名称:status,代码行数:26,代码来源:http_request.py


示例8: test_http_get_binary_file_absent

 def test_http_get_binary_file_absent(self):
     """Test HTTP GET request and write to binary file when it does not exist"""
     filepath = os.path.join('testfiles', 'testdir', 'test.tar.gz')
     if file_exists(filepath):
         os.remove(filepath)
     http = HTTP("https://github.com/chrissimpkins/six-four/tarball/master")
     http.get_bin_write_file(filepath)
     self.assertTrue(file_exists(filepath))
开发者ID:chrisidefix,项目名称:naked,代码行数:8,代码来源:test_NETWORK.py


示例9: test_http_get_text_exists_request_overwrite

 def test_http_get_text_exists_request_overwrite(self):
     """Test HTTP GET request with text file write does overwrite existing file when requested to do so"""
     filepath = os.path.join('testfiles', 'testdir', 'test.txt')
     http = HTTP('https://raw.github.com/chrissimpkins/six-four/master/LICENSE')
     fw = FileWriter(filepath)
     fw.write("test")
     http.get_txt_write_file(filepath, overwrite_existing=True)
     self.assertEqual(FileReader(filepath).read().strip(), self.http_string.strip())
开发者ID:chrisidefix,项目名称:naked,代码行数:8,代码来源:test_NETWORK.py


示例10: test_http_post_binary_file_present

 def test_http_post_binary_file_present(self):
     """Test HTTP POST request binary file write when file does exist - should not write by default"""
     filepath = os.path.join('testfiles', 'keep', 'test.tar.gz')
     if not file_exists(filepath):
         raise RuntimeError("Missing test file for unit test")
     http = HTTP('http://httpbin.org/gzip')
     response = http.post_bin_write_file(filepath)
     self.assertEqual(False, response)
开发者ID:chrisidefix,项目名称:naked,代码行数:8,代码来源:test_NETWORK.py


示例11: test_http_get_ssl

    def test_http_get_ssl(self):
        """Test HTTP GET request content data with secure HTTP"""
        http = HTTP("https://raw.github.com/chrissimpkins/six-four/master/LICENSE")
        http_text = http.get()

        if state.py2:
            self.http_string = unicode(self.http_string)
        self.assertEqual(http_text.strip(), self.http_string.strip())
开发者ID:chrisidefix,项目名称:naked,代码行数:8,代码来源:test_NETWORK.py


示例12: test_http_post_text_file_present

 def test_http_post_text_file_present(self):
     """Test HTTP POST request text file write does not occur when file already exists"""
     filepath = os.path.join('testfiles', 'keep', 'file1.txt')
     if not file_exists(filepath):
         raise RuntimeError("Missing test file for unit test")
     http = HTTP('http://httpbin.org/gzip')
     response = http.post_bin_write_file(filepath)
     self.assertEqual(False, response)
开发者ID:chrisidefix,项目名称:naked,代码行数:8,代码来源:test_NETWORK.py


示例13: test_http_post_text_file_present_request_overwrite

 def test_http_post_text_file_present_request_overwrite(self):
     """Test HTTP request text file write does occur when file present and request overwrite"""
     filepath = os.path.join('testfiles', 'testdir', 'post.txt')
     if not file_exists(filepath):
         fw = FileWriter(filepath)
         fw.write('test')
     http = HTTP('http://httpbin.org/gzip')
     response = http.post_bin_write_file(filepath, overwrite_existing=True)
     self.assertEqual(True, response)
开发者ID:chrisidefix,项目名称:naked,代码行数:9,代码来源:test_NETWORK.py


示例14: test_http_get_type

    def test_http_get_type(self):
        """Test the HTTP GET request return value type"""
        http = HTTP("https://raw.github.com/chrissimpkins/six-four/master/LICENSE")
        http_text = http.get()

        if state.py2:
            self.assertEqual(type(u"test string"), type(http_text))
        else:
            self.assertEqual(type(str("test string")), type(http_text))
开发者ID:chrisidefix,项目名称:naked,代码行数:9,代码来源:test_NETWORK.py


示例15: test_http_post_binary_file_absent

 def test_http_post_binary_file_absent(self):
     """Test HTTP POST request binary file write when the file does not exist"""
     filepath = os.path.join('testfiles', 'testdir', 'post.gz')
     if file_exists(filepath):
         os.remove(filepath)
     http = HTTP("http://httpbin.org/gzip")
     http_data_write = http.post_bin_write_file(filepath)
     self.assertEqual(True, http_data_write) #test boolean for confirmation of data write
     self.assertEqual(True, file_exists(filepath))
开发者ID:chrisidefix,项目名称:naked,代码行数:9,代码来源:test_NETWORK.py


示例16: test_http_get_response_obj_nonexistentsite

 def test_http_get_response_obj_nonexistentsite(self):
     """Test the response object after GET request for a non-existent site"""
     http = HTTP('http://bigtimebogussite.io')
     self.assertEqual(False, http.get())
     self.assertEqual(None, http.res)
     with self.assertRaises(AttributeError):
         http.res.content
     with self.assertRaises(AttributeError):
         http.res.status_code
开发者ID:chrisidefix,项目名称:naked,代码行数:9,代码来源:test_NETWORK.py


示例17: test_http_get_binary_file_exists_request_overwrite

 def test_http_get_binary_file_exists_request_overwrite(self):
     """Test HTTP GET request and write binary file executes the write when the file exists and overwrite requested"""
     filepath = os.path.join('testfiles', 'testdir', 'test.tar.gz')
     fw = FileWriter(filepath)
     fw.write("test")
     if not file_exists(filepath):
         raise RuntimeError("Missing test file for the unit test")
     http = HTTP("https://github.com/chrissimpkins/six-four/tarball/master")
     http.get_bin_write_file(filepath, overwrite_existing=True)
     self.assertTrue(file_exists(filepath))
开发者ID:chrisidefix,项目名称:naked,代码行数:10,代码来源:test_NETWORK.py


示例18: test_http_post_binary_file_present_request_overwrite

 def test_http_post_binary_file_present_request_overwrite(self):
     """Test HTTP POST request binary file write when file does exist and request for overwrite"""
     filepath = os.path.join('testfiles', 'testdir', 'post.gz')
     if not file_exists(filepath):
         fw = FileWriter(filepath)
         fw.write('test')
     http = HTTP('http://httpbin.org/gzip')
     response = http.post_bin_write_file(filepath, overwrite_existing=True)
     self.assertEqual(True, response)
     self.assertEqual(True, file_exists(filepath))
开发者ID:chrisidefix,项目名称:naked,代码行数:10,代码来源:test_NETWORK.py


示例19: test_http_get_text_absent

 def test_http_get_text_absent(self):
     """Test HTTP get request for text data and write of text file"""
     filepath = os.path.join('testfiles', 'testdir', 'test.txt')
     if file_exists(filepath):
         os.remove(filepath)
     http = HTTP("https://raw.github.com/chrissimpkins/six-four/master/LICENSE")
     response = http.get_txt_write_file(filepath)
     fr = FileReader(filepath)
     the_dl_text = fr.read()
     self.assertEqual(the_dl_text.strip(), self.http_string.strip()) #test that the file write is appropriate
     self.assertEqual(response, True) # test that the response from the method is correct (True on completed file write)
开发者ID:chrisidefix,项目名称:naked,代码行数:11,代码来源:test_NETWORK.py


示例20: test_http_post_text_file_absent

 def test_http_post_text_file_absent(self):
     """Test HTTP POST request text file write when the file does not exist"""
     filepath = os.path.join('testfiles', 'testdir', 'post.txt')
     if file_exists(filepath):
         os.remove(filepath)
     http = HTTP("http://httpbin.org/post")
     http_text = http.post_txt_write_file(filepath)
     fr = FileReader(filepath)
     the_text = fr.read_utf8() #read file in
     textobj = json.loads(the_text) #convert JSON to Py object
     self.assertEqual(True, http_text) # test boolean for confirmation of data write
     self.assertEqual(textobj['url'], 'http://httpbin.org/post') #confirm the write of subset of the text
开发者ID:chrisidefix,项目名称:naked,代码行数:12,代码来源:test_NETWORK.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python system.file_exists函数代码示例发布时间:2022-05-24
下一篇:
Python Generic.GenericServer类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap