Skip to content

Drop Python 2 support#31

Open
JuanTecedor wants to merge 6 commits into
TheHive-Project:masterfrom
JuanTecedor:drop_python_2_support
Open

Drop Python 2 support#31
JuanTecedor wants to merge 6 commits into
TheHive-Project:masterfrom
JuanTecedor:drop_python_2_support

Conversation

@JuanTecedor

Copy link
Copy Markdown
Contributor

https://docs.python.org/3/whatsnew/3.0.html

@JuanTecedor JuanTecedor marked this pull request as ready for review June 8, 2026 17:03
Comment thread cortexutils/extractor.py
+ ")"
)
regex.append({"type": "ip", "regex": re.compile(r"{}".format(r))})
regex.append({"type": "ip", "regex": re.compile(r)})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure that leaving r"" won't cause any issues with the regex pattern rendering

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fairly sure r"{}".format(r) is no-OP equivalent.

Quick test with https://hypothesis.readthedocs.io/en/latest/:

import re
from hypothesis import given, strategies as st
from hypothesis.provisional import domains

regexp = (
    "("
    + "([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|"
    + "([0-9a-fA-F]{1,4}:){1,7}:|"
    + "([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|"
    + "([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|"
    + "([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|"
    + "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|"
    + "([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|"
    + "[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|"
    + ":((:[0-9a-fA-F]{1,4}){1,7}|:)|"
    + "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|"
    + "::(ffff(:0{1,4}){0,1}:){0,1}"
    + r"((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}"
    + "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|"
    + "([0-9a-fA-F]{1,4}:){1,4}:"
    + r"((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}"
    + "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"
    + ")"
)
original_regex = re.compile(r"{}".format(regexp))
new_regex = re.compile(regexp)


@given(
    st.text()
    | domains()
    | st.ip_addresses()
    | st.none()
    | st.integers()
    | st.floats()
    | st.binary()
)
def test_regex_refactor(data: str):
    old = original_regex.search(str(data))
    new = new_regex.search(str(data))

    if old is None or new is None:
        assert old == new
    else:
        assert old.group() == new.group()
        assert old.span() == new.span()
$ pytest tests/test_regex.py
test session starts ...
1 passed in 0.21s 

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also compared the original_regex == new_regex and they are the same 😄

Comment thread cortexutils/worker.py Outdated
with open(
"%s/output/output.json" % self.job_directory, mode="w"
) as f_output:
output_path = f"{self.job_directory}/output"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
output_path = f"{self.job_directory}/output"
output_dir = f"{self.job_directory}/output"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled also in 7a1d8cd

Comment thread tests/test_suite_analyzer.py Outdated
fixture_file = open(path + "/" + fixture_path)
input = fixture_file.read()
fixture_file.close()
with open(path + "/" + fixture_path) as fixture_file:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for these kind of syntaxes we can start using os.path.join to be future proof in case of different platforms with different path separators

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot :)

Please check 7a1d8cd

Comment thread tests/test_suite_extractor.py Outdated
@Kamforka Kamforka added the changelog:removed changelog label for now removed features label Jun 9, 2026
@Kamforka Kamforka linked an issue Jun 9, 2026 that may be closed by this pull request
Comment thread cortexutils/worker.py Outdated
JuanTecedor and others added 2 commits June 9, 2026 20:58
Co-authored-by: Kamforka <antalszabolcs01@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:removed changelog label for now removed features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drop Python2 support

2 participants