diff options
author | CoprDistGit <infra@openeuler.org> | 2023-05-31 07:04:25 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-05-31 07:04:25 +0000 |
commit | ea12a26391d47644aee5d1673a6fa6ba62f4dd79 (patch) | |
tree | a2d1fcefdaaa1efb57e0f8b30c2a39b8f7d55aa0 | |
parent | 5b31c904f9bc6b9a082bf02db129c22b041043fb (diff) |
automatic import of python-django-geoip2-extras
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-django-geoip2-extras.spec | 566 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 568 insertions, 0 deletions
@@ -0,0 +1 @@ +/django-geoip2-extras-4.0.tar.gz diff --git a/python-django-geoip2-extras.spec b/python-django-geoip2-extras.spec new file mode 100644 index 0000000..3e0da6a --- /dev/null +++ b/python-django-geoip2-extras.spec @@ -0,0 +1,566 @@ +%global _empty_manifest_terminate_build 0 +Name: python-django-geoip2-extras +Version: 4.0 +Release: 1 +Summary: Additional functionality using the GeoIP2 database. +License: MIT +URL: https://github.com/yunojuno/django-geoip2-extras +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/77/93/f9a5f6a07af073df798f30fd503ab7f50a49c86fc8f7e9d906b1fa81cef7/django-geoip2-extras-4.0.tar.gz +BuildArch: noarch + +Requires: python3-django +Requires: python3-geoip2 + +%description +# Django GeoIP2 Extras + +Useful extras based on the `django.contrib.gis.geoip2` module, using +the [MaxMind GeoIP2 Lite](http://dev.maxmind.com/geoip/geoip2/geolite2/) database. + +The first feature in this package is a Django middleware class that can +be used to add city, country level information to inbound requests. + +### Version support + +The current version of the this app support **Python 3.8+** and **Django 3.2+** + +## Requirements + +1) This package wraps the existing Django functionality, and as a result +relies on the same underlying requirements: + + In order to perform IP-based geolocation, the GeoIP2 object + requires the geoip2 Python library and the GeoIP Country and/or City + datasets in binary format (the CSV files will not work!). Grab the + GeoLite2-Country.mmdb.gz and GeoLite2-City.mmdb.gz files and unzip + them in a directory corresponding to the GEOIP_PATH setting. + +NB: The MaxMind database is not included with this package. It is your +responsiblity to download this and include it as part of your project. + +2) This package requires the usage of a Django cache configuration to +maintain adaquate performance. + + +## Installation + +This package can be installed from PyPI as `django-geoip2-extras`: + +``` +$ pip install django-geoip2-extras +``` + +If you want to add the country-level information to incoming requests, +add the middleware to your project settings. + +```python +# settings.py +MIDDLEWARE = ( + ..., + 'geoip2_extras.middleware.GeoIP2Middleware', +) +``` + +The middleware will not be active unless you add a setting for the +default `GEOIP_PATH` - this is the default Django GeoIP2 behaviour: + +```python +# settings.py +GEOIP_PATH = os.path.dirname(__file__) +``` + +You must also configure a cache to use via `GEOIP2_EXTRAS_CACHE_NAME`. +The value should match the name of the Django cache configuration you +wish to use for caching. + +```python +# settings.py + +# Django cache configuration setting +CACHES = { + "default": { ... }, + "some-other-cache": { ... }, # <-- it would use this one. + ... +} + +# Set this to specific configuration name from CACHES +GEOIP2_EXTRAS_CACHE_NAME = "some-other-cache" +``` + +Tip: see `/demo/settings.py` for a full working example. + +### Settings + +The following settings can be overridden via your Django settings: + +* `GEOIP2_EXTRAS_CACHE_NAME` + +The Django cache configuration to use for cacheing. + +* `GEOIP2_EXTRAS_CACHE_TIMEOUT` + +Time to cache IP <> address data in seconds - default to 1hr (3600s) + +* `GEOIP2_EXTRAS_ADD_RESPONSE_HEADERS` + +Set to True to write out the GeoIP data to the response headers. Defaults to use +the `DEBUG` value. This value can be overridden on a per-request basis by adding +the `X-GeoIP2-Debug` request header, or adding `geoip2=1` to the request +querystring. This is useful for debugging in a production environment where you +may not be adding the response headers by default. + +## Usage + +Once the middleware is added, you will be able to access City and / or +Country level information on the request object via the `geo_data` dict: + +```python +>>> request.geo_data +{ + "city": "" + "continent-code": "NA" + "continent-name": "North America" + "country-code": "US" + "country-name": "United States" + "dma-code": "" + "is-in-european-union": False + "latitude": 37.751 + "longitude": -97.822 + "postal-code": "" + "region": "" + "time-zone": "America/Chicago" + "remote-addr": "142.250.180.3" +} +``` + +The same information will be added to the HttpResponse headers if +`GEOIP2_EXTRAS_ADD_RESPONSE_HEADERS` is True. Values are set using the +`X-GeoIP2-` prefix. + +NB blank (`""`) values are **not** added to the response: + +```shell +# use the google.co.uk IP +$ curl -I -H "x-forwarded-for: 142.250.180.3" localhost:8000 +HTTP/1.1 200 OK +Date: Sun, 29 Aug 2021 15:47:22 GMT +Server: WSGIServer/0.2 CPython/3.9.4 +Content-Type: text/html +X-GeoIP2-Continent-Code: NA +X-GeoIP2-Continent-Name: North America +X-GeoIP2-Country-Code: US +X-GeoIP2-Country-Name: United States +X-GeoIP2-Is-In-European-Union: False +X-GeoIP2-Latitude: 37.751 +X-GeoIP2-Longitude: -97.822 +X-GeoIP2-Time-Zone: America/Chicago +X-GeoIP2-Remote-Addr: 142.250.180.3 +Content-Length: 10697 +``` + +If the IP address cannot be found (e.g. '127.0.0.1'), then a default +'unknown' country is used, with a code of 'XX'. + +```shell +$ curl -I -H "x-forwarded-for: 127.0.0.1" localhost:8000 +HTTP/1.1 200 OK +Date: Sun, 29 Aug 2021 15:47:22 GMT +Server: WSGIServer/0.2 CPython/3.9.4 +Content-Type: text/html +X-GeoIP2-Country-Code: XX +X-GeoIP2-Country-Name: unknown +X-GeoIP2-Remote-Addr: 127.0.0.1 +Content-Length: 10697 +``` + +## Tests + +The project tests are run through `pytest`. + + +%package -n python3-django-geoip2-extras +Summary: Additional functionality using the GeoIP2 database. +Provides: python-django-geoip2-extras +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-django-geoip2-extras +# Django GeoIP2 Extras + +Useful extras based on the `django.contrib.gis.geoip2` module, using +the [MaxMind GeoIP2 Lite](http://dev.maxmind.com/geoip/geoip2/geolite2/) database. + +The first feature in this package is a Django middleware class that can +be used to add city, country level information to inbound requests. + +### Version support + +The current version of the this app support **Python 3.8+** and **Django 3.2+** + +## Requirements + +1) This package wraps the existing Django functionality, and as a result +relies on the same underlying requirements: + + In order to perform IP-based geolocation, the GeoIP2 object + requires the geoip2 Python library and the GeoIP Country and/or City + datasets in binary format (the CSV files will not work!). Grab the + GeoLite2-Country.mmdb.gz and GeoLite2-City.mmdb.gz files and unzip + them in a directory corresponding to the GEOIP_PATH setting. + +NB: The MaxMind database is not included with this package. It is your +responsiblity to download this and include it as part of your project. + +2) This package requires the usage of a Django cache configuration to +maintain adaquate performance. + + +## Installation + +This package can be installed from PyPI as `django-geoip2-extras`: + +``` +$ pip install django-geoip2-extras +``` + +If you want to add the country-level information to incoming requests, +add the middleware to your project settings. + +```python +# settings.py +MIDDLEWARE = ( + ..., + 'geoip2_extras.middleware.GeoIP2Middleware', +) +``` + +The middleware will not be active unless you add a setting for the +default `GEOIP_PATH` - this is the default Django GeoIP2 behaviour: + +```python +# settings.py +GEOIP_PATH = os.path.dirname(__file__) +``` + +You must also configure a cache to use via `GEOIP2_EXTRAS_CACHE_NAME`. +The value should match the name of the Django cache configuration you +wish to use for caching. + +```python +# settings.py + +# Django cache configuration setting +CACHES = { + "default": { ... }, + "some-other-cache": { ... }, # <-- it would use this one. + ... +} + +# Set this to specific configuration name from CACHES +GEOIP2_EXTRAS_CACHE_NAME = "some-other-cache" +``` + +Tip: see `/demo/settings.py` for a full working example. + +### Settings + +The following settings can be overridden via your Django settings: + +* `GEOIP2_EXTRAS_CACHE_NAME` + +The Django cache configuration to use for cacheing. + +* `GEOIP2_EXTRAS_CACHE_TIMEOUT` + +Time to cache IP <> address data in seconds - default to 1hr (3600s) + +* `GEOIP2_EXTRAS_ADD_RESPONSE_HEADERS` + +Set to True to write out the GeoIP data to the response headers. Defaults to use +the `DEBUG` value. This value can be overridden on a per-request basis by adding +the `X-GeoIP2-Debug` request header, or adding `geoip2=1` to the request +querystring. This is useful for debugging in a production environment where you +may not be adding the response headers by default. + +## Usage + +Once the middleware is added, you will be able to access City and / or +Country level information on the request object via the `geo_data` dict: + +```python +>>> request.geo_data +{ + "city": "" + "continent-code": "NA" + "continent-name": "North America" + "country-code": "US" + "country-name": "United States" + "dma-code": "" + "is-in-european-union": False + "latitude": 37.751 + "longitude": -97.822 + "postal-code": "" + "region": "" + "time-zone": "America/Chicago" + "remote-addr": "142.250.180.3" +} +``` + +The same information will be added to the HttpResponse headers if +`GEOIP2_EXTRAS_ADD_RESPONSE_HEADERS` is True. Values are set using the +`X-GeoIP2-` prefix. + +NB blank (`""`) values are **not** added to the response: + +```shell +# use the google.co.uk IP +$ curl -I -H "x-forwarded-for: 142.250.180.3" localhost:8000 +HTTP/1.1 200 OK +Date: Sun, 29 Aug 2021 15:47:22 GMT +Server: WSGIServer/0.2 CPython/3.9.4 +Content-Type: text/html +X-GeoIP2-Continent-Code: NA +X-GeoIP2-Continent-Name: North America +X-GeoIP2-Country-Code: US +X-GeoIP2-Country-Name: United States +X-GeoIP2-Is-In-European-Union: False +X-GeoIP2-Latitude: 37.751 +X-GeoIP2-Longitude: -97.822 +X-GeoIP2-Time-Zone: America/Chicago +X-GeoIP2-Remote-Addr: 142.250.180.3 +Content-Length: 10697 +``` + +If the IP address cannot be found (e.g. '127.0.0.1'), then a default +'unknown' country is used, with a code of 'XX'. + +```shell +$ curl -I -H "x-forwarded-for: 127.0.0.1" localhost:8000 +HTTP/1.1 200 OK +Date: Sun, 29 Aug 2021 15:47:22 GMT +Server: WSGIServer/0.2 CPython/3.9.4 +Content-Type: text/html +X-GeoIP2-Country-Code: XX +X-GeoIP2-Country-Name: unknown +X-GeoIP2-Remote-Addr: 127.0.0.1 +Content-Length: 10697 +``` + +## Tests + +The project tests are run through `pytest`. + + +%package help +Summary: Development documents and examples for django-geoip2-extras +Provides: python3-django-geoip2-extras-doc +%description help +# Django GeoIP2 Extras + +Useful extras based on the `django.contrib.gis.geoip2` module, using +the [MaxMind GeoIP2 Lite](http://dev.maxmind.com/geoip/geoip2/geolite2/) database. + +The first feature in this package is a Django middleware class that can +be used to add city, country level information to inbound requests. + +### Version support + +The current version of the this app support **Python 3.8+** and **Django 3.2+** + +## Requirements + +1) This package wraps the existing Django functionality, and as a result +relies on the same underlying requirements: + + In order to perform IP-based geolocation, the GeoIP2 object + requires the geoip2 Python library and the GeoIP Country and/or City + datasets in binary format (the CSV files will not work!). Grab the + GeoLite2-Country.mmdb.gz and GeoLite2-City.mmdb.gz files and unzip + them in a directory corresponding to the GEOIP_PATH setting. + +NB: The MaxMind database is not included with this package. It is your +responsiblity to download this and include it as part of your project. + +2) This package requires the usage of a Django cache configuration to +maintain adaquate performance. + + +## Installation + +This package can be installed from PyPI as `django-geoip2-extras`: + +``` +$ pip install django-geoip2-extras +``` + +If you want to add the country-level information to incoming requests, +add the middleware to your project settings. + +```python +# settings.py +MIDDLEWARE = ( + ..., + 'geoip2_extras.middleware.GeoIP2Middleware', +) +``` + +The middleware will not be active unless you add a setting for the +default `GEOIP_PATH` - this is the default Django GeoIP2 behaviour: + +```python +# settings.py +GEOIP_PATH = os.path.dirname(__file__) +``` + +You must also configure a cache to use via `GEOIP2_EXTRAS_CACHE_NAME`. +The value should match the name of the Django cache configuration you +wish to use for caching. + +```python +# settings.py + +# Django cache configuration setting +CACHES = { + "default": { ... }, + "some-other-cache": { ... }, # <-- it would use this one. + ... +} + +# Set this to specific configuration name from CACHES +GEOIP2_EXTRAS_CACHE_NAME = "some-other-cache" +``` + +Tip: see `/demo/settings.py` for a full working example. + +### Settings + +The following settings can be overridden via your Django settings: + +* `GEOIP2_EXTRAS_CACHE_NAME` + +The Django cache configuration to use for cacheing. + +* `GEOIP2_EXTRAS_CACHE_TIMEOUT` + +Time to cache IP <> address data in seconds - default to 1hr (3600s) + +* `GEOIP2_EXTRAS_ADD_RESPONSE_HEADERS` + +Set to True to write out the GeoIP data to the response headers. Defaults to use +the `DEBUG` value. This value can be overridden on a per-request basis by adding +the `X-GeoIP2-Debug` request header, or adding `geoip2=1` to the request +querystring. This is useful for debugging in a production environment where you +may not be adding the response headers by default. + +## Usage + +Once the middleware is added, you will be able to access City and / or +Country level information on the request object via the `geo_data` dict: + +```python +>>> request.geo_data +{ + "city": "" + "continent-code": "NA" + "continent-name": "North America" + "country-code": "US" + "country-name": "United States" + "dma-code": "" + "is-in-european-union": False + "latitude": 37.751 + "longitude": -97.822 + "postal-code": "" + "region": "" + "time-zone": "America/Chicago" + "remote-addr": "142.250.180.3" +} +``` + +The same information will be added to the HttpResponse headers if +`GEOIP2_EXTRAS_ADD_RESPONSE_HEADERS` is True. Values are set using the +`X-GeoIP2-` prefix. + +NB blank (`""`) values are **not** added to the response: + +```shell +# use the google.co.uk IP +$ curl -I -H "x-forwarded-for: 142.250.180.3" localhost:8000 +HTTP/1.1 200 OK +Date: Sun, 29 Aug 2021 15:47:22 GMT +Server: WSGIServer/0.2 CPython/3.9.4 +Content-Type: text/html +X-GeoIP2-Continent-Code: NA +X-GeoIP2-Continent-Name: North America +X-GeoIP2-Country-Code: US +X-GeoIP2-Country-Name: United States +X-GeoIP2-Is-In-European-Union: False +X-GeoIP2-Latitude: 37.751 +X-GeoIP2-Longitude: -97.822 +X-GeoIP2-Time-Zone: America/Chicago +X-GeoIP2-Remote-Addr: 142.250.180.3 +Content-Length: 10697 +``` + +If the IP address cannot be found (e.g. '127.0.0.1'), then a default +'unknown' country is used, with a code of 'XX'. + +```shell +$ curl -I -H "x-forwarded-for: 127.0.0.1" localhost:8000 +HTTP/1.1 200 OK +Date: Sun, 29 Aug 2021 15:47:22 GMT +Server: WSGIServer/0.2 CPython/3.9.4 +Content-Type: text/html +X-GeoIP2-Country-Code: XX +X-GeoIP2-Country-Name: unknown +X-GeoIP2-Remote-Addr: 127.0.0.1 +Content-Length: 10697 +``` + +## Tests + +The project tests are run through `pytest`. + + +%prep +%autosetup -n django-geoip2-extras-4.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-django-geoip2-extras -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Wed May 31 2023 Python_Bot <Python_Bot@openeuler.org> - 4.0-1 +- Package Spec generated @@ -0,0 +1 @@ +121d1bfb13c4723cfbff6a31b15fb186 django-geoip2-extras-4.0.tar.gz |