当前位置: 首页>>代码示例>>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;未经允许,请勿转载。