Skip to content

Commit

Permalink
Merge pull request #12 from michael-lazar/py312
Browse files Browse the repository at this point in the history
Add support for python 3.12
  • Loading branch information
michael-lazar authored Sep 10, 2024
2 parents 8a3bbf5 + a61d309 commit edb0787
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest]
steps:
- name: Check out repository
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- Added support for python 3.12.

## v3.0.1 (2024-02-25)

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PYTHONPATH=. bin/pygopherd conf/local.conf
For installing,

```
python3 setup.py install
python3 -m pip install .
```

Make sure that the ``/etc/pygopherd/pygopherd.conf`` names valid users
Expand Down
18 changes: 13 additions & 5 deletions pygopherd/handlers/pyg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import imp
import importlib.util
from importlib.machinery import SourceFileLoader
import re
import stat

Expand All @@ -10,6 +11,7 @@ class PYGHandler(Virtual):
def canhandlerequest(self) -> bool:
if not isinstance(self.vfs, VFS_Real):
return False

if not (
self.statresult
# Is it a regular file?
Expand All @@ -19,10 +21,16 @@ def canhandlerequest(self) -> bool:
and re.search(r"\.pyg$", self.getselector())
):
return False
with self.vfs.open(self.getselector(), "r") as modf:
self.module = imp.load_module(
"PYGHandler", modf, self.getfspath(), ("", "", imp.PY_SOURCE)
)

fspath = self.getfspath()
loader = SourceFileLoader("PYGHandler", fspath)
spec = importlib.util.spec_from_file_location("PYGHandler", fspath, loader=loader)
if spec is None:
return False

self.module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(self.module)

self.pygclass = self.module.PYGMain
self.pygobject = self.pygclass(
self.selector,
Expand Down
6 changes: 4 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def test_send_data(self):

def test_send_data_tls(self):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
with ssl.wrap_socket(sock) as ssock:
ctx = ssl.SSLContext()
with ctx.wrap_socket(sock) as ssock:
ssock.connect(self.server.server_address)
ssock.sendall(b"Hello World\n")
self.assertEqual(ssock.recv(4096), b"Hello World\n")
Expand All @@ -77,7 +78,8 @@ def test_send_data(self):

def test_send_data_tls(self):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
with ssl.wrap_socket(sock) as ssock:
ctx = ssl.SSLContext()
with ctx.wrap_socket(sock) as ssock:
ssock.connect(self.server.server_address)
ssock.sendall(b"Hello World\n")
self.assertEqual(ssock.recv(4096), b"Hello World\n")

0 comments on commit edb0787

Please sign in to comment.