本文整理汇总了Python中werkzeug.test.EnvironBuilder.host方法的典型用法代码示例。如果您正苦于以下问题:Python EnvironBuilder.host方法的具体用法?Python EnvironBuilder.host怎么用?Python EnvironBuilder.host使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.test.EnvironBuilder
的用法示例。
在下文中一共展示了EnvironBuilder.host方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_environ_builder_paths
# 需要导入模块: from werkzeug.test import EnvironBuilder [as 别名]
# 或者: from werkzeug.test.EnvironBuilder import host [as 别名]
def test_environ_builder_paths(self):
b = EnvironBuilder(path='/foo', base_url='http://example.com/')
self.assert_strict_equal(b.base_url, 'http://example.com/')
self.assert_strict_equal(b.path, '/foo')
self.assert_strict_equal(b.script_root, '')
self.assert_strict_equal(b.host, 'example.com')
b = EnvironBuilder(path='/foo', base_url='http://example.com/bar')
self.assert_strict_equal(b.base_url, 'http://example.com/bar/')
self.assert_strict_equal(b.path, '/foo')
self.assert_strict_equal(b.script_root, '/bar')
self.assert_strict_equal(b.host, 'example.com')
b.host = 'localhost'
self.assert_strict_equal(b.base_url, 'http://localhost/bar/')
b.base_url = 'http://localhost:8080/'
self.assert_strict_equal(b.host, 'localhost:8080')
self.assert_strict_equal(b.server_name, 'localhost')
self.assert_strict_equal(b.server_port, 8080)
b.host = 'foo.invalid'
b.url_scheme = 'https'
b.script_root = '/test'
env = b.get_environ()
self.assert_strict_equal(env['SERVER_NAME'], 'foo.invalid')
self.assert_strict_equal(env['SERVER_PORT'], '443')
self.assert_strict_equal(env['SCRIPT_NAME'], '/test')
self.assert_strict_equal(env['PATH_INFO'], '/foo')
self.assert_strict_equal(env['HTTP_HOST'], 'foo.invalid')
self.assert_strict_equal(env['wsgi.url_scheme'], 'https')
self.assert_strict_equal(b.base_url, 'https://foo.invalid/test/')
示例2: test_environ_builder_paths
# 需要导入模块: from werkzeug.test import EnvironBuilder [as 别名]
# 或者: from werkzeug.test.EnvironBuilder import host [as 别名]
def test_environ_builder_paths():
b = EnvironBuilder(path="/foo", base_url="http://example.com/")
strict_eq(b.base_url, "http://example.com/")
strict_eq(b.path, "/foo")
strict_eq(b.script_root, "")
strict_eq(b.host, "example.com")
b = EnvironBuilder(path="/foo", base_url="http://example.com/bar")
strict_eq(b.base_url, "http://example.com/bar/")
strict_eq(b.path, "/foo")
strict_eq(b.script_root, "/bar")
strict_eq(b.host, "example.com")
b.host = "localhost"
strict_eq(b.base_url, "http://localhost/bar/")
b.base_url = "http://localhost:8080/"
strict_eq(b.host, "localhost:8080")
strict_eq(b.server_name, "localhost")
strict_eq(b.server_port, 8080)
b.host = "foo.invalid"
b.url_scheme = "https"
b.script_root = "/test"
env = b.get_environ()
strict_eq(env["SERVER_NAME"], "foo.invalid")
strict_eq(env["SERVER_PORT"], "443")
strict_eq(env["SCRIPT_NAME"], "/test")
strict_eq(env["PATH_INFO"], "/foo")
strict_eq(env["HTTP_HOST"], "foo.invalid")
strict_eq(env["wsgi.url_scheme"], "https")
strict_eq(b.base_url, "https://foo.invalid/test/")
示例3: test_environ_builder_paths
# 需要导入模块: from werkzeug.test import EnvironBuilder [as 别名]
# 或者: from werkzeug.test.EnvironBuilder import host [as 别名]
def test_environ_builder_paths(self):
b = EnvironBuilder(path='/foo', base_url='http://example.com/')
assert b.base_url == 'http://example.com/'
assert b.path == '/foo'
assert b.script_root == ''
assert b.host == 'example.com'
b = EnvironBuilder(path='/foo', base_url='http://example.com/bar')
assert b.base_url == 'http://example.com/bar/'
assert b.path == '/foo'
assert b.script_root == '/bar'
assert b.host == 'example.com'
b.host = 'localhost'
assert b.base_url == 'http://localhost/bar/'
b.base_url = 'http://localhost:8080/'
assert b.host == 'localhost:8080'
assert b.server_name == 'localhost'
assert b.server_port == 8080
b.host = 'foo.invalid'
b.url_scheme = 'https'
b.script_root = '/test'
env = b.get_environ()
assert env['SERVER_NAME'] == 'foo.invalid'
assert env['SERVER_PORT'] == '443'
assert env['SCRIPT_NAME'] == '/test'
assert env['PATH_INFO'] == '/foo'
assert env['HTTP_HOST'] == 'foo.invalid'
assert env['wsgi.url_scheme'] == 'https'
assert b.base_url == 'https://foo.invalid/test/'
示例4: open
# 需要导入模块: from werkzeug.test import EnvironBuilder [as 别名]
# 或者: from werkzeug.test.EnvironBuilder import host [as 别名]
def open(self, *args, **kwargs):
if self.context_preserved:
_request_ctx_stack.pop()
self.context_preserved = False
kwargs.setdefault('environ_overrides', {}) \
['flask._preserve_context'] = self.preserve_context
as_tuple = kwargs.pop('as_tuple', False)
buffered = kwargs.pop('buffered', False)
follow_redirects = kwargs.pop('follow_redirects', False)
builder = EnvironBuilder(*args, **kwargs)
if self.application.config.get('SERVER_NAME'):
server_name = self.application.config.get('SERVER_NAME')
if ':' not in server_name:
http_host, http_port = server_name, None
else:
http_host, http_port = server_name.split(':', 1)
if builder.base_url == 'http://localhost/':
# Default Generated Base URL
if http_port != None:
builder.host = http_host + ':' + http_port
else:
builder.host = http_host
old = _request_ctx_stack.top
try:
return Client.open(self, builder,
as_tuple=as_tuple,
buffered=buffered,
follow_redirects=follow_redirects)
finally:
self.context_preserved = _request_ctx_stack.top is not old