當前位置: 首頁>>代碼示例>>Python>>正文


Python HTTP.get_status_ok方法代碼示例

本文整理匯總了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)  
開發者ID:tstyle,項目名稱:doxx,代碼行數:14,代碼來源:repoupdate.py

示例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)
        
開發者ID:tstyle,項目名稱:doxx,代碼行數:14,代碼來源:whatis.py

示例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)
開發者ID:tstyle,項目名稱:doxx,代碼行數:20,代碼來源:pull.py

示例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)
        
開發者ID:tstyle,項目名稱:doxx,代碼行數:23,代碼來源:pullkey.py

示例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
開發者ID:chrisidefix,項目名稱:naked,代碼行數:7,代碼來源:test_NETWORK.py

示例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
開發者ID:chrisidefix,項目名稱:naked,代碼行數:7,代碼來源:test_NETWORK.py


注:本文中的Naked.toolshed.network.HTTP.get_status_ok方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。