本文整理汇总了Python中Naked.toolshed.network.HTTP.get_status_ok方法的典型用法代码示例。如果您正苦于以下问题:Python HTTP.get_status_ok方法的具体用法?Python HTTP.get_status_ok怎么用?Python HTTP.get_status_ok使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Naked.toolshed.network.HTTP
的用法示例。
在下文中一共展示了HTTP.get_status_ok方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _pull_official_repository_json
# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get_status_ok [as 别名]
def _pull_official_repository_json():
package = OfficialPackage()
master_package_json_url = package.get_master_package_description_json_url()
http = HTTP(master_package_json_url)
try:
if http.get_status_ok():
master_list = http.res.text
return master_list.strip() # strip additional spaces, blank end lines off of the list
else:
stderr("[!] Unable to pull the remote repository package descriptions (HTTP status code: " + str(http.res.status_code) + ")", exit=1)
except Exception as e:
stderr("[!] doxx: Unable to pull the remote repository package descriptions. Error: " + str(e), exit=1)
示例2: _pull_official_repository_descriptions
# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get_status_ok [as 别名]
def _pull_official_repository_descriptions():
package = OfficialPackage()
master_package_descriptions = package.get_master_package_description_json_url()
http = HTTP(master_package_descriptions)
try:
if http.get_status_ok():
master_descriptions = http.res.text
return master_descriptions.strip()
else:
stderr("[!] doxx: Unable to pull remote repository descriptions (HTTP status code: " + str(http.res.status_code) + ")", exit=1)
except Exception as e:
stderr("[!] doxx: Unable to pull remote repository descriptions Error: " + str(e) + ")", exit=1)
示例3: pull_text_file
# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get_status_ok [as 别名]
def pull_text_file(url, text_file_name):
"""pulls a remote text file and writes to disk"""
# pull the binary file data
http = HTTP(url)
try:
if http.get_status_ok():
text_data = http.res.text
# write text data to disk
try:
fw = FileWriter(text_file_name)
fw.write(text_data)
except Exception as e:
stderr("[!] doxx: File write failed for '" + text_file_name + "'. Error: " + str(e), exit=1)
else:
fail_status_code = http.res.status_code
stderr("[!] doxx: Unable to pull '" + url + "' (HTTP status code " + str(fail_status_code) + ")", exit=1)
except Exception as e:
stderr("[!] doxx: Unable to pull '" + url + "'. Error: " + str(e), exit=1)
示例4: run_pullkey
# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get_status_ok [as 别名]
def run_pullkey(package_name):
normalized_package_name = package_name.lower().strip()
package = OfficialPackage()
key_file_url = package.get_package_key_url(normalized_package_name)
try:
stdout("[*] doxx: Pulling the remote key file...")
http = HTTP(key_file_url)
if http.get_status_ok():
key_file_text = http.res.text
fr = FileWriter('key.yaml')
try:
fr.write(key_file_text)
except Exception as e:
stderr("[!] doxx: Unable to write the 'key.yaml' file to disk. Error: " + str(e), exit=1)
stdout("[*] doxx: Key file pull complete")
elif http.res.status_code == 404:
stderr("[!] doxx: Unable to pull the key file because the requested package could not be found. (HTTP status code: 404)", exit=1)
else:
stderr("[!] doxx: Unable to pull the key file. (HTTP status code: " + str(http.res.status_code) + ")", exit=1)
except Exception as e:
stderr("[!] doxx: Unable to pull the key file. Error: " + str(e), exit=1)
示例5: test_http_get_status_check_false
# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get_status_ok [as 别名]
def test_http_get_status_check_false(self):
"""Confirm the truth check for status response code OK is False for non-existent site"""
http = HTTP('http://www.abogussitename.com')
self.assertEqual(http.get_status_ok(), False)
self.assertEqual(http.res, None) # confirm that the response object is None when site does not exist
示例6: test_http_get_status_check_true
# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get_status_ok [as 别名]
def test_http_get_status_check_true(self):
"""Confirm the truth check for status response code OK (=200) is True when should be true"""
http = HTTP('http://httpbin.org/status/200')
self.assertEqual(http.get_status_ok(), True)
self.assertEqual(http.res.status_code, 200) #confirm that the response object is set after the get_status_ok() call