Skip to content

Commit

Permalink
python 3.12 support
Browse files Browse the repository at this point in the history
  • Loading branch information
cle-b committed Nov 4, 2023
1 parent 5b0e7d2 commit 2881b98
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
timeout-minutes: 15
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
Expand Down
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
[![Build Status](https://github.com/cle-b/hookdns/workflows/Build/badge.svg?branch=main)](https://github.com/cle-b/hookdns/actions?query=workflow%3ABuild) [![Coverage Status](https://coveralls.io/repos/github/cle-b/hookdns/badge.svg?branch=main)](https://coveralls.io/github/cle-b/hookdns?branch=main) [![PyPI version](https://badge.fury.io/py/hookdns.svg)](https://pypi.org/project/hookdns/) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)
[![Build Status](https://github.com/cle-b/hookdns/workflows/Build/badge.svg?branch=main)](https://github.com/cle-b/hookdns/actions?query=workflow%3ABuild) [![Coverage Status](https://coveralls.io/repos/github/cle-b/hookdns/badge.svg?branch=main)](https://coveralls.io/github/cle-b/hookdns?branch=main) [![PyPI version](https://badge.fury.io/py/hookdns.svg)](https://pypi.org/project/hookdns/)

# hookdns

HookDNS is a library which allow you to modify a name resolution in your Python script without any modification in your hosts file or by using a fake DNS resolver.

```python
import requests

from hookdns import hosts

with hosts({"example.org": "localhost"}):
...
r = requests.get("http://example.org") # the request is sent to your local server
...
```

## Installation

```
Expand All @@ -29,10 +40,10 @@ import requests

from hookdns import hosts

@hosts({"example.org": "localhost"})
@hosts({"example.org": "127.0.0.1"})
def myfunc():
...
r = requests.get("http://example.org") # the request is sent to your local server
r = requests.get("http://example.org") # the request is sent to your local server
...
```

Expand All @@ -45,7 +56,7 @@ from hookdns import hosts

with hosts({"example.org": "localhost"}):
...
r = requests.get("http://example.org") # the request is sent to your local server
r = requests.get("http://example.org") # the request is sent to your local server
...
```
### Options
Expand All @@ -61,19 +72,14 @@ from hookdns import hosts

with hosts({"example.org": "localhost"}, only=["gethostbyname"]):
...
addr = socket.gethostbyname("example.org") # returns "127.0.0.1"
addr = socket.gethostbyname("example.org") # returns "127.0.0.1"
print("gethostname returns: %s" % addr)

_, _, addr = socket.gethostbyname_ex("example.org") # returns the real ip address for example.org
_, _, addr = socket.gethostbyname_ex("example.org") # returns the real ip address for example.org
print("gethostname_ex returns: %s" % addr[0])
...
```
```
gethostname returns: 127.0.0.1
gethostname_ex returns: 93.184.216.34
```


## Limitation

It works only with Python 3.4 and greater.
2 changes: 1 addition & 1 deletion hookdns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from .hosts import hosts

name = "hookdns"
VERSION = "1.1.0"
VERSION = "1.1.1"

__all__ = ["hosts"]

0 comments on commit 2881b98

Please sign in to comment.