当前位置: 首页>>代码示例>>Python>>正文


Python Request.get_origin_req_host方法代码示例

本文整理汇总了Python中urllib.request.Request.get_origin_req_host方法的典型用法代码示例。如果您正苦于以下问题:Python Request.get_origin_req_host方法的具体用法?Python Request.get_origin_req_host怎么用?Python Request.get_origin_req_host使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib.request.Request的用法示例。


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

示例1: _get_texts_remaining

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import get_origin_req_host [as 别名]
    def _get_texts_remaining(self):
        #url = "http://messaging.o2online.ie/o2om_smscenter_new.osp"
        #pat = r'id="spn_WebtextFree">(\d+)<\/span> free texts'
        #data = {'MsgContentID': '-1',
        #        'SID': self.sid, }
        # data = urlencode(data).encode('utf-8')
        #response = urlopen(url, data)
        #match = re.search(pat, response.read().decode('utf-8'))
        #self.texts_remaining = int(match.group(1) if match else -1)
        #return self.texts_remaining

        url = "http://messaging.o2online.ie/smscenter_evaluate.osp"
        data = {'SID': self.sid,
                'SMSText': 'text',
                'FID': '6406',}
        data = urlencode(data).encode('utf-8')
        request = Request(url, data)
        request.add_header('Referer', request.get_origin_req_host())
        response = urlopen(request)
        try:
            content = self.parse_json(response.read().decode('utf-8'))
        except ValueError:
            content = None
        self.texts_remaining = content['freeMessageCount'] if content else -1
        return self.texts_remaining
开发者ID:russelldavies,项目名称:cliresms,代码行数:27,代码来源:cliresms.py

示例2: RequestTests

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import get_origin_req_host [as 别名]
class RequestTests(unittest.TestCase):

    def setUp(self):
        self.get = Request("http://www.python.org/~jeremy/")
        self.post = Request("http://www.python.org/~jeremy/",
                            "data",
                            headers={"X-Test": "test"})

    def test_method(self):
        self.assertEqual("POST", self.post.get_method())
        self.assertEqual("GET", self.get.get_method())

    def test_add_data(self):
        self.assertFalse(self.get.has_data())
        self.assertEqual("GET", self.get.get_method())
        self.get.add_data("spam")
        self.assertTrue(self.get.has_data())
        self.assertEqual("POST", self.get.get_method())

    def test_get_full_url(self):
        self.assertEqual("http://www.python.org/~jeremy/",
                         self.get.get_full_url())

    def test_selector(self):
        self.assertEqual("/~jeremy/", self.get.get_selector())
        req = Request("http://www.python.org/")
        self.assertEqual("/", req.get_selector())

    def test_get_type(self):
        self.assertEqual("http", self.get.get_type())

    def test_get_host(self):
        self.assertEqual("www.python.org", self.get.get_host())

    def test_get_host_unquote(self):
        req = Request("http://www.%70ython.org/")
        self.assertEqual("www.python.org", req.get_host())

    def test_proxy(self):
        self.assertFalse(self.get.has_proxy())
        self.get.set_proxy("www.perl.org", "http")
        self.assertTrue(self.get.has_proxy())
        self.assertEqual("www.python.org", self.get.get_origin_req_host())
        self.assertEqual("www.perl.org", self.get.get_host())

    def test_wrapped_url(self):
        req = Request("<URL:http://www.python.org>")
        self.assertEqual("www.python.org", req.get_host())

    def test_urlwith_fragment(self):
        req = Request("http://www.python.org/?qs=query#fragment=true")
        self.assertEqual("/?qs=query", req.get_selector())
        req = Request("http://www.python.org/#fun=true")
        self.assertEqual("/", req.get_selector())
开发者ID:pogigroo,项目名称:py3k-__format__,代码行数:56,代码来源:test_urllib2.py

示例3: send_message

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import get_origin_req_host [as 别名]
 def send_message(self, recipients, message):
     url = "http://messaging.o2online.ie/smscenter_send.osp"
     data = {'SID': self.sid,
             'MsgContentID': '-1',
             'SMSTo': ', '.join(recipient),
             'SMSText': message, }
     data = urlencode(data).encode('utf-8')
     request = Request(url, data)
     request.add_header('Referer', request.get_origin_req_host())
     response = urlopen(request)
     content = self.parse_json(response.read().decode('utf-8'))
     return content['isSuccess']
开发者ID:russelldavies,项目名称:cliresms,代码行数:14,代码来源:cliresms.py

示例4: test_cookies

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import get_origin_req_host [as 别名]
    def test_cookies(self):
        cj = MockCookieJar()
        h = urllib.request.HTTPCookieProcessor(cj)
        o = h.parent = MockOpener()

        req = Request("http://example.com/")
        r = MockResponse(200, "OK", {}, "")
        newreq = h.http_request(req)
        self.assertTrue(cj.ach_req is req is newreq)
        self.assertEquals(req.get_origin_req_host(), "example.com")
        self.assertTrue(not req.is_unverifiable())
        newr = h.http_response(req, r)
        self.assertTrue(cj.ec_req is req)
        self.assertTrue(cj.ec_r is r is newr)
开发者ID:Kanma,项目名称:Athena-Dependencies-Python,代码行数:16,代码来源:test_urllib2.py


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