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


Python HttpRequest.META["REMOTE_ADDR"]方法代码示例

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


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

示例1: test_render_internal_ip

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META["REMOTE_ADDR"] [as 别名]
 def test_render_internal_ip(self):
     req = HttpRequest()
     req.META["REMOTE_ADDR"] = "1.1.1.1"
     context = Context({"request": req})
     r = ChartbeatBottomNode().render(context)
     self.assertTrue(r.startswith("<!-- Chartbeat disabled on internal IP address"), r)
     self.assertTrue(r.endswith("-->"), r)
开发者ID:zhas,项目名称:django-analytical,代码行数:9,代码来源:test_tag_chartbeat.py

示例2: mk_request

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META["REMOTE_ADDR"] [as 别名]
 def mk_request(self, user=None, ip="192.168.123.123", user_agent="FakeBrowser 1.0"):
     request = HttpRequest()
     request.user = user and user or AnonymousUser()
     request.method = "GET"
     request.META["REMOTE_ADDR"] = ip
     request.META["HTTP_USER_AGENT"] = user_agent
     return request
开发者ID:tantek,项目名称:kuma,代码行数:9,代码来源:tests.py

示例3: test_ip_address

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META["REMOTE_ADDR"] [as 别名]
    def test_ip_address(self):
        condition_set = "gargoyle.builtins.IPAddressConditionSet"

        switch = Switch.objects.create(key="test", status=SELECTIVE)
        switch = gargoyle["test"]

        request = HttpRequest()
        request.META["REMOTE_ADDR"] = "192.168.1.1"

        self.assertTrue(gargoyle.is_active("test", request))

        switch.add_condition(condition_set=condition_set, field_name="ip_address", condition="192.168.1.1")

        self.assertTrue(gargoyle.is_active("test", request))

        switch.clear_conditions(condition_set=condition_set)
        switch.add_condition(condition_set=condition_set, field_name="ip_address", condition="127.0.0.1")

        self.assertFalse(gargoyle.is_active("test", request))

        switch.clear_conditions(condition_set=condition_set)

        self.assertTrue(gargoyle.is_active("test", request))

        switch.add_condition(condition_set=condition_set, field_name="percent", condition="50-100")

        self.assertTrue(gargoyle.is_active("test", request))

        switch.clear_conditions(condition_set=condition_set)
        switch.add_condition(condition_set=condition_set, field_name="percent", condition="0-50")
        self.assertFalse(gargoyle.is_active("test", request))
开发者ID:darkseed,项目名称:gargoyle,代码行数:33,代码来源:tests.py

示例4: getResult

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META["REMOTE_ADDR"] [as 别名]
def getResult(tap, rules = None):

	if tap.format != 'verification':
		emsg = 'Currently, only FORMATs VERIFICATION and XSAMS are supported.\n'
		return vamdctap.views.tapServerError(status=400, errmsg=emsg)
	tap.request["FORMAT"] = "XSAMS"

	request = HttpRequest()
	request.META["SERVER_NAME"] = 'localhost'
	request.META["SERVER_PORT"] = '80'
	request.META["REMOTE_ADDR"] = '127.0.0.1'
	request.META["QUERY_STRING"] = ''
	request.REQUEST = {}

	for key in tap.request:
		request.REQUEST[upper(key)] = tap.request[key]

	xsamsResponse = vamdctap.views.sync(request)
	if xsamsResponse.get('VAMDC-COUNT-STATES', 0) < 1:
		return xsamsResponse

	if 'RETURN' in tap.request:
		action = lower(tap.request['RETURN'])
	else:
		action = 'all'

	if action not in ('all', 'good', 'bad'):
		action = 'all'

	ver = check.Verification(xsamsResponse.content, rules)
	ver.run(bad=None if action == 'all' else True if action == 'bad' else False)

	response = HttpResponse(ver.getXML(), content_type='text/xml')
	response._headers = xsamsResponse._headers
	return response
开发者ID:aip,项目名称:NodeSoftware,代码行数:37,代码来源:http.py

示例5: test_get_identifier

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META["REMOTE_ADDR"] [as 别名]
    def test_get_identifier(self):
        auth = Authentication()
        request = HttpRequest()
        self.assertEqual(auth.get_identifier(request), "noaddr_nohost")

        request = HttpRequest()
        request.META["REMOTE_ADDR"] = "127.0.0.1"
        request.META["REMOTE_HOST"] = "nebula.local"
        self.assertEqual(auth.get_identifier(request), "127.0.0.1_nebula.local")
开发者ID:thepeopleseason,项目名称:django-tastypie,代码行数:11,代码来源:authentication.py

示例6: getBigFile

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META["REMOTE_ADDR"] [as 别名]
def getBigFile():
	settings.DEBUG = True
	query = 'LANG=VSS1&FORMAT=VERIFICATION&QUERY=SELECT All WHERE InChI =\'InChI=1S/H2O/h1H2/i/hD\''

	request = HttpRequest()
	request.META["SERVER_NAME"] = 'localhost'
	request.META["SERVER_PORT"] = '80'
	request.META["REMOTE_ADDR"] = '127.0.0.1'
	request.META["QUERY_STRING"] = query

	request.REQUEST = toDict(QueryDict(query))
	return views.sync(request).content
开发者ID:xnx,项目名称:VAMDC-VALD,代码行数:14,代码来源:tests.py

示例7: getBigFile

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META["REMOTE_ADDR"] [as 别名]
def getBigFile():
	settings.DEBUG = True
	#query = 'LANG=VSS1&FORMAT=VERIFICATION&QUERY=SELECT All WHERE InChI =\'InChI=1S/H2O/h1H2/i/hD\''
	#query = "LANG=VSS1&FORMAT=XSAMS&QUERY=select * where (RadTransWavenumber >= 1239.0 AND RadTransWavenumber <= 1240.0) AND ((InchiKey IN ('A', 'XLYOFNOQVPJJNP-DYCDLGHISA-N','XLYOFNOQVPJJNP-DQGQKLTASA-N')))"
	query = "LANG=VSS1&FORMAT=VERIFICATION&QUERY=select * where (RadTransWavenumber >= 1239.0 AND RadTransWavenumber <= 1240.0) AND ((InchiKey IN ('A', 'XLYOFNOQVPJJNP-DYCDLGHISA-N','XLYOFNOQVPJJNP-DQGQKLTASA-N')))"

	request = HttpRequest()
	request.META["SERVER_NAME"] = 'localhost'
	request.META["SERVER_PORT"] = '80'
	request.META["REMOTE_ADDR"] = '127.0.0.1'
	request.META["QUERY_STRING"] = query

	request.REQUEST = toDict(QueryDict(query))

	return views.sync(request).content
开发者ID:surleau,项目名称:NodeSoftware,代码行数:17,代码来源:tests.py

示例8: test_is_active_superuser

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META["REMOTE_ADDR"] [as 别名]
def test_is_active_superuser():
    request = HttpRequest()
    request.META["REMOTE_ADDR"] = "10.0.0.1"

    with override_settings(INTERNAL_IPS=()):
        assert is_active_superuser(request) is False
        request.user = User()
        assert is_active_superuser(request) is False
        request.user.is_superuser = True
        assert is_active_superuser(request) is True

    with override_settings(INTERNAL_IPS=("127.0.0.1",)):
        assert is_active_superuser(request) is False

    with override_settings(INTERNAL_IPS=("10.0.0.1",)):
        assert is_active_superuser(request) is True
开发者ID:ForkRepo,项目名称:sentry,代码行数:18,代码来源:test_utils.py

示例9: process_request

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META["REMOTE_ADDR"] [as 别名]
    def process_request(self, request: HttpRequest):
        request.window_key = get_random_string(32, VALID_KEY_CHARS)
        if request.is_ajax() and self.ajax_header in request.META:
            session_key = request.COOKIES.get(settings.SESSION_COOKIE_NAME)
            signer = signing.Signer(session_key)
            signed_token = request.META[self.ajax_header]
            request.window_key = signer.unsign(signed_token)
        request.has_websocket_topics = False
        request.remote_username = None

        if settings.USE_X_FORWARDED_FOR and "HTTP_X_FORWARDED_FOR" in request.META:
            request.META["REMOTE_ADDR"] = (
                request.META["HTTP_X_FORWARDED_FOR"].split(",")[0].strip()
            )

        if settings.USE_HTTP_BASIC_AUTH and "HTTP_AUTHORIZATION" in request.META:
            authentication = request.META["HTTP_AUTHORIZATION"]
            authmeth, sep, auth_data = authentication.partition(" ")
            if sep == " " and authmeth.lower() == "basic":
                auth_data = base64.b64decode(auth_data.strip()).decode("utf-8")
                username, password = auth_data.split(":", 1)
                user = auth.authenticate(username=username, password=password)
                if user:
                    request.user = user
                    auth.login(request, user)
        # noinspection PyTypeChecker
        username = getattr(settings, "DF_FAKE_AUTHENTICATION_USERNAME", None)
        if username and settings.DEBUG:
            remote_addr = request.META.get("REMOTE_ADDR")
            if remote_addr in settings.INTERNAL_IPS:
                request.META[self.header] = username
            elif remote_addr:
                logger.warning(
                    "Unable to use `settings.DF_FAKE_AUTHENTICATION_USERNAME`. "
                    "You should add %s to the list `settings.INTERNAL_IPS`."
                    % remote_addr
                )

        if self.header and self.header in request.META:
            remote_username = request.META.get(self.header)
            if (
                not remote_username or remote_username == "(null)"
            ):  # special case due to apache2+auth_mod_kerb :-(
                return
            remote_username = self.format_remote_username(remote_username)
            # noinspection PyTypeChecker
            self.remote_user_authentication(request, remote_username)
开发者ID:d9pouces,项目名称:django-floor,代码行数:49,代码来源:middleware.py

示例10: test_decorator_for_ip_address

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META["REMOTE_ADDR"] [as 别名]
    def test_decorator_for_ip_address(self):
        condition_set = "gargoyle.builtins.IPAddressConditionSet"

        switch = Switch.objects.create(key="test", status=DISABLED)
        switch = gargoyle["test"]

        @switch_is_active("test")
        def test(request):
            return True

        request = HttpRequest()
        request.META["REMOTE_ADDR"] = "192.168.1.1"

        self.assertRaises(Http404, test, request)

        switch.status = SELECTIVE
        switch.save()

        switch.add_condition(condition_set=condition_set, field_name="ip_address", condition="192.168.1.1")

        self.assertTrue(test(request))

        switch.remove_condition(condition_set=condition_set, field_name="ip_address", condition="192.168.1.1")

        self.assertRaises(Http404, test, request)

        switch.add_condition(condition_set=condition_set, field_name="ip_address", condition="192.168.1.1")

        self.assertTrue(test(request))

        switch.clear_conditions(condition_set=condition_set, field_name="ip_address")

        switch.add_condition(condition_set=condition_set, field_name="percent", condition="50-100")

        self.assertTrue(test(request))

        switch.clear_conditions(condition_set=condition_set)

        switch.add_condition(condition_set=condition_set, field_name="percent", condition="0-50")

        self.assertRaises(Http404, test, request)
开发者ID:darkseed,项目名称:gargoyle,代码行数:43,代码来源:tests.py

示例11: test_middleware

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META["REMOTE_ADDR"] [as 别名]
 def test_middleware(self):
     testing_middleware = StoreHTTPRequestMiddleware()
     request = HttpRequest()
     request.META["REMOTE_ADDR"] = "127.0.0.1"
     response = testing_middleware.process_request(request)
     self.assertEqual(response, None)
开发者ID:smal,项目名称:cc_testing,代码行数:8,代码来源:tests.py


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