From 6a8ce2d4a3466b0a9e51e2bcff7aaa787b2751f2 Mon Sep 17 00:00:00 2001 From: "Val Neekman (AvidCoder)" Date: Wed, 25 Oct 2023 09:43:19 -0400 Subject: [PATCH 1/8] rename ipware to python_ipware --- .github/workflows/ci.yml | 2 +- CHANGELOG.md | 7 +++++++ README.md | 6 +++--- ipware/__version__.py | 1 - pyproject.toml | 8 ++++---- {ipware => python_ipware}/__init__.py | 2 +- python_ipware/__version__.py | 1 + {ipware => python_ipware}/py.typed | 0 ipware/ipware.py => python_ipware/python_ipware.py | 0 tests/tests_ipv4.py | 2 +- tests/tests_ipv6.py | 2 +- 11 files changed, 19 insertions(+), 12 deletions(-) delete mode 100644 ipware/__version__.py rename {ipware => python_ipware}/__init__.py (51%) create mode 100644 python_ipware/__version__.py rename {ipware => python_ipware}/py.typed (100%) rename ipware/ipware.py => python_ipware/python_ipware.py (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04a29dd..ba7e23c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,7 +36,7 @@ jobs: - name: Run ruff run: ruff --format=github . - name: Run test - run: coverage run --source=ipware -m unittest discover + run: coverage run --source=python_ipware -m unittest discover - name: Coveralls run: coveralls --service=github env: diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e90f62..3cc2260 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 2.0.0 + +- Introduced breaking changes to avoid conflicts with the `django-ipware` package. +- Renamed the imported module from `ipware` to `python_ipware` in the `python-ipware` package. + - Old usage: `from ipware import IpWare` + - New usage: `from python_ipware import IpWare` + ## 1.0.5 - Enhance: Readme updates diff --git a/README.md b/README.md index 5d36669..048ef39 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ pip3 install python-ipware Here's a basic example of how to use `python-ipware` in a view or middleware where the `request` object is available. This can be applied in Django, Flask, or other similar frameworks. ```python -from ipware import IpWare +from python_ipware import IpWare # Instantiate IpWare with default values ipw = IpWare() @@ -186,7 +186,7 @@ You can customize the proxy count by providing your `proxy_count` during initial ```python # In the above scenario, the total number of proxies can be used as a way to filter out unwanted requests. -from ipware import IpWare +from python_ipware import IpWare # enforce proxy count ipw = IpWare(proxy_count=1) @@ -219,7 +219,7 @@ In the following `example`, your public load balancer (LB) can be seen as the `o ```python # We make best attempt to return the first public IP address based on header precedence # Then we fall back on private, followed by loopback -from ipware import IpWare +from python_ipware import IpWare # no proxy enforce in this example ipw = IpWare() diff --git a/ipware/__version__.py b/ipware/__version__.py deleted file mode 100644 index 68cdeee..0000000 --- a/ipware/__version__.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "1.0.5" diff --git a/pyproject.toml b/pyproject.toml index afa4fa3..a0e6c4c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,14 +43,14 @@ dev = [ ] [tool.setuptools] -packages = ["ipware"] +packages = ["python_ipware"] [tool.setuptools.dynamic] -version = {attr = "ipware.__version__"} +version = {attr = "python_ipware.__version__"} readme = {file = ["README.md"], content-type = "text/markdown"} [tool.setuptools.package-data] -"ipware" = ["py.typed"] +"python_ipware" = ["py.typed"] [tool.ruff] select = [ @@ -85,5 +85,5 @@ max-complexity = 16 [tool.coverage.run] omit = [ - "ipware/__version__.py" + "python_ipware/__version__.py" ] \ No newline at end of file diff --git a/ipware/__init__.py b/python_ipware/__init__.py similarity index 51% rename from ipware/__init__.py rename to python_ipware/__init__.py index e987461..5ec16c9 100644 --- a/ipware/__init__.py +++ b/python_ipware/__init__.py @@ -1,2 +1,2 @@ -from .ipware import IpWare # noqa +from .python_ipware import IpWare # noqa from .__version__ import __version__ # noqa diff --git a/python_ipware/__version__.py b/python_ipware/__version__.py new file mode 100644 index 0000000..8c0d5d5 --- /dev/null +++ b/python_ipware/__version__.py @@ -0,0 +1 @@ +__version__ = "2.0.0" diff --git a/ipware/py.typed b/python_ipware/py.typed similarity index 100% rename from ipware/py.typed rename to python_ipware/py.typed diff --git a/ipware/ipware.py b/python_ipware/python_ipware.py similarity index 100% rename from ipware/ipware.py rename to python_ipware/python_ipware.py diff --git a/tests/tests_ipv4.py b/tests/tests_ipv4.py index 7678b63..277c7c3 100644 --- a/tests/tests_ipv4.py +++ b/tests/tests_ipv4.py @@ -1,7 +1,7 @@ import unittest import logging from ipaddress import IPv4Address -from ipware import IpWare +from python_ipware import IpWare logging.disable(logging.CRITICAL) # Disable logging for the entire file diff --git a/tests/tests_ipv6.py b/tests/tests_ipv6.py index e34d670..8017750 100644 --- a/tests/tests_ipv6.py +++ b/tests/tests_ipv6.py @@ -2,7 +2,7 @@ import logging from ipaddress import IPv4Address, IPv6Address -from ipware import IpWare +from python_ipware import IpWare logging.disable(logging.CRITICAL) # Disable logging for the entire file From fc2a7292383d623a6b7d519ea8b1c26228e901d2 Mon Sep 17 00:00:00 2001 From: "Val Neekman (AvidCoder)" Date: Wed, 25 Oct 2023 09:51:03 -0400 Subject: [PATCH 2/8] github action --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba7e23c..f722a6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: python -m pip install --upgrade pip pip install -e .[dev] - name: Run ruff - run: ruff --format=github . + run: ruff . - name: Run test run: coverage run --source=python_ipware -m unittest discover - name: Coveralls From 2016b28bf465ec45e76903509419cf44b49d5212 Mon Sep 17 00:00:00 2001 From: "Val Neekman (AvidCoder)" Date: Wed, 13 Dec 2023 13:55:00 -0500 Subject: [PATCH 3/8] Remove HTTP_VIA --- README.md | 1 - python_ipware/python_ipware.py | 3 +-- tests/tests_ipv4.py | 7 ------- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/README.md b/README.md index 048ef39..74ebb29 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,6 @@ request_headers_precedence_order = ( "HTTP_X_CLUSTER_CLIENT_IP", # Rackspace LB and Riverbed Stingray "HTTP_FORWARDED_FOR", # RFC 7239 "HTTP_FORWARDED", # RFC 7239 - "HTTP_VIA", # Squid and others "X-CLIENT-IP", # Microsoft Azure "X-REAL-IP", # NGINX "X-CLUSTER-CLIENT-IP", # Rackspace Cloud Load Balancers diff --git a/python_ipware/python_ipware.py b/python_ipware/python_ipware.py index 6e4f6f1..f4d730d 100644 --- a/python_ipware/python_ipware.py +++ b/python_ipware/python_ipware.py @@ -26,7 +26,6 @@ def __init__( "HTTP_X_CLUSTER_CLIENT_IP", # Rackspace LB and Riverbed Stingray "HTTP_FORWARDED_FOR", # RFC 7239 "HTTP_FORWARDED", # RFC 7239 - "HTTP_VIA", # Squid and others "X-CLIENT-IP", # Microsoft Azure "X-REAL-IP", # NGINX "X-CLUSTER-CLIENT-IP", # Rackspace Cloud Load Balancers @@ -106,7 +105,7 @@ def get_ip_object( ip = ipaddress.IPv4Address(ipv4) except ipaddress.AddressValueError: # not a valid IP address, return None - logging.exception("Invalid ip address. {0}".format(ip_str)) + logging.info("Invalid ip address. {0}".format(ip_str)) ip = None return ip diff --git a/tests/tests_ipv4.py b/tests/tests_ipv4.py index 277c7c3..6a173a3 100644 --- a/tests/tests_ipv4.py +++ b/tests/tests_ipv4.py @@ -364,13 +364,6 @@ def test_ipv4_http_http_forwarded(self): r = self.ipware.get_client_ip(meta) self.assertEqual(r, (IPv4Address("177.139.233.139"), False)) - def test_ipv4_http_via(self): - meta = { - "HTTP_VIA": "177.139.233.139", - } - r = self.ipware.get_client_ip(meta) - self.assertEqual(r, (IPv4Address("177.139.233.139"), False)) - def test_ipv4_x_client_ip(self): meta = { "X-CLIENT-IP": "177.139.233.139", From d2217fa0c6bf8260641ad31e9f15485fc6ce7a51 Mon Sep 17 00:00:00 2001 From: "Val Neekman (AvidCoder)" Date: Wed, 13 Dec 2023 13:57:48 -0500 Subject: [PATCH 4/8] up version --- CHANGELOG.md | 4 ++++ python_ipware/__version__.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cc2260..0419d30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.1 +Issue: +- Remove `HTTP_VIA` header support (unreliable IP information) (@yourcelf) + ## 2.0.0 - Introduced breaking changes to avoid conflicts with the `django-ipware` package. diff --git a/python_ipware/__version__.py b/python_ipware/__version__.py index 8c0d5d5..159d48b 100644 --- a/python_ipware/__version__.py +++ b/python_ipware/__version__.py @@ -1 +1 @@ -__version__ = "2.0.0" +__version__ = "2.0.1" From 0a2c1ee7df800a154a85602695ca3f43cf984635 Mon Sep 17 00:00:00 2001 From: "Val Neekman (AvidCoder)" Date: Wed, 13 Dec 2023 14:01:32 -0500 Subject: [PATCH 5/8] add py 3.12 --- .github/workflows/ci.yml | 2 +- CHANGELOG.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f722a6e..26377b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9, "3.10", 3.11, pypy3.9] + python-version: [3.7, 3.8, 3.9, "3.10", 3.11, 3.12, pypy3.9] steps: - uses: actions/checkout@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0419d30..685fed6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Issue: - Remove `HTTP_VIA` header support (unreliable IP information) (@yourcelf) +Enhance: +- Include support for python 3.12 + ## 2.0.0 - Introduced breaking changes to avoid conflicts with the `django-ipware` package. From bee1c6ba9695d20a1a50ba34d7dfd65a2092f1c6 Mon Sep 17 00:00:00 2001 From: "Val Neekman (AvidCoder)" Date: Wed, 13 Dec 2023 14:02:24 -0500 Subject: [PATCH 6/8] add 3.12 --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index a0e6c4c..ad4c5e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ] [project.urls] From 32ee035ed6bdcca1a9834883e57a467fcfb296ee Mon Sep 17 00:00:00 2001 From: "Val Neekman (AvidCoder)" Date: Thu, 11 Apr 2024 18:47:14 -0400 Subject: [PATCH 7/8] add HTTP_CF_CONNECTING_IP to ip header list --- CHANGELOG.md | 5 +++++ python_ipware/__version__.py | 2 +- python_ipware/python_ipware.py | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f0c124..b56f3f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.3 + +Enhance: +- Added `HTTP_CF_CONNECTING_IP` to list of known ip headers (Adam M.) + ## 2.0.2 Enhance: diff --git a/python_ipware/__version__.py b/python_ipware/__version__.py index 0309ae2..5fa9130 100644 --- a/python_ipware/__version__.py +++ b/python_ipware/__version__.py @@ -1 +1 @@ -__version__ = "2.0.2" +__version__ = "2.0.3" diff --git a/python_ipware/python_ipware.py b/python_ipware/python_ipware.py index f897a56..8b6d177 100644 --- a/python_ipware/python_ipware.py +++ b/python_ipware/python_ipware.py @@ -28,6 +28,7 @@ def __init__( "HTTP_X_CLUSTER_CLIENT_IP", # Rackspace LB and Riverbed Stingray "HTTP_FORWARDED_FOR", # RFC 7239 "HTTP_FORWARDED", # RFC 7239 + "HTTP_CF_CONNECTING_IP", # CloudFlare "X-CLIENT-IP", # Microsoft Azure "X-REAL-IP", # NGINX "X-CLUSTER-CLIENT-IP", # Rackspace Cloud Load Balancers From 27f064d08a90a53ffd90761267c242460afbea40 Mon Sep 17 00:00:00 2001 From: "Val Neekman (AvidCoder)" Date: Thu, 11 Apr 2024 19:01:37 -0400 Subject: [PATCH 8/8] update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 74ebb29..5a691a1 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ request_headers_precedence_order = ( "HTTP_X_CLUSTER_CLIENT_IP", # Rackspace LB and Riverbed Stingray "HTTP_FORWARDED_FOR", # RFC 7239 "HTTP_FORWARDED", # RFC 7239 + "HTTP_CF_CONNECTING_IP", # CloudFlare "X-CLIENT-IP", # Microsoft Azure "X-REAL-IP", # NGINX "X-CLUSTER-CLIENT-IP", # Rackspace Cloud Load Balancers