From 2430b9c91ebb19ce962eb287788d743f1fdc4d93 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Sun, 4 Feb 2024 15:36:56 -0300 Subject: [PATCH] Add types for get_client_ip parameters (#110) --- ipware/ip.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ipware/ip.py b/ipware/ip.py index e8ae6d9..c64a3bd 100644 --- a/ipware/ip.py +++ b/ipware/ip.py @@ -1,14 +1,17 @@ +from typing import Iterable, Literal, Optional, Tuple + from django.conf import settings +from django.http import HttpRequest from python_ipware import IpWare def get_client_ip( - request, - proxy_order='left-most', - proxy_count=None, - proxy_trusted_ips=None, - request_header_order=None, -): + request: HttpRequest, + proxy_order: Literal['left-most', 'right-most'] = 'left-most', + proxy_count: Optional[int] = None, + proxy_trusted_ips: Optional[Iterable[str]] = None, + request_header_order: Optional[Iterable[str]] = None, +) -> Tuple[str, bool]: leftmost = proxy_order == 'left-most' proxy_count = proxy_count if proxy_count is not None else getattr(settings, 'IPWARE_META_PROXY_COUNT', 0) proxy_list = proxy_trusted_ips if proxy_trusted_ips is not None else []