Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with python3.8 #1

Open
villivateur opened this issue Nov 7, 2022 · 6 comments
Open

Not working with python3.8 #1

villivateur opened this issue Nov 7, 2022 · 6 comments
Assignees

Comments

@villivateur
Copy link

I use Ubuntu20.04 and python3.8 is the default python interpreter.

However, tufw uses many features that only supported by python3.9 or higher. I tried to install python3.10 but the dependencies messed up. For example, ModuleNotFoundError: No module named 'distutils.util'.

I tried to edit the source code to make it compatible with python3.8, and delete code like -> tuple[str, str] as much as I can, but end up with AttributeError: 'str' object has no attribute 'removeprefix' in "/usr/local/lib/python3.8/dist-packages/tufw/firewall.py", line 60.

Do you have any idea that make it work in Ubuntu 20.04? Or at least, post the minimum python version in README.

Thank you.

@a13ssandr0
Copy link
Owner

Hi @villivateur, sorry for replying late.
removeprefix was added in python 3.9, but python 3.8 should run it using regex match.
Try editing the file firewall.py adding search to the imports from re:
from re import sub, compile, search
Then replace these lines:

ufw_default_policy = int(self._run_cmd(['sysctl', 'net.ipv4.ip_forward']).replace(" ", "").removeprefix('net.ipv4.ip_forward=').strip())
    if not ufw_default_policy: return 'disabled'

with these:

if search(r'= (\d+)', self._run_cmd(['sysctl', 'net.ipv4.ip_forward'])).group(1) == '0':
    return 'disabled'

Tell me if the problem is solved this way.

@a13ssandr0 a13ssandr0 self-assigned this Nov 28, 2022
@villivateur
Copy link
Author

Hi @villivateur, sorry for replying late. removeprefix was added in python 3.9, but python 3.8 should run it using regex match. Try editing the file firewall.py adding search to the imports from re: from re import sub, compile, search Then replace these lines:

ufw_default_policy = int(self._run_cmd(['sysctl', 'net.ipv4.ip_forward']).replace(" ", "").removeprefix('net.ipv4.ip_forward=').strip())
    if not ufw_default_policy: return 'disabled'

with these:

if search(r'= (\d+)', self._run_cmd(['sysctl', 'net.ipv4.ip_forward'])).group(1) == '0':
    return 'disabled'

Tell me if the problem is solved this way.

It works, thank you.

@a13ssandr0
Copy link
Owner

Fine, I'll push the changes in the next few days.

@a13ssandr0
Copy link
Owner

@villivateur
Changes applied.
New version is now available.

@villivateur
Copy link
Author

@villivateur Changes applied. New version is now available.

However, it seems that there are still some typing hints like -> tuple... , which is not supported by python version under 3.9.

In README, it says Tufw requires python3.0 or newer.

@a13ssandr0
Copy link
Owner

a13ssandr0 commented Dec 16, 2022

However, it seems that there are still some typing hints like -> tuple... , which is not supported by python version under 3.9.

Thanks, testing with python 3.5.4 (the minimum python3 version conda could install) I discovered integrated annotations were incompatible (but vermin check didn't report that) and needed to import List and Tuple annotations from typing module.
I will eventually remove annotations and check if it is compatible with python 3.0.

@a13ssandr0 a13ssandr0 reopened this Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants