Skip to content

Commit

Permalink
run black
Browse files Browse the repository at this point in the history
  • Loading branch information
Émilio😎Gonzalez committed Oct 31, 2023
1 parent 434c13f commit 1786ad9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
22 changes: 13 additions & 9 deletions sigma/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from math import inf
import re
from abc import ABC
from dataclasses import dataclass, field
from enum import Enum, auto
from ipaddress import IPv4Network, IPv6Network, ip_network
from math import inf
from typing import (
ClassVar,
Dict,
Expand All @@ -14,18 +18,14 @@
Callable,
Iterator,
)
from abc import ABC
from dataclasses import dataclass, field
from enum import Enum, auto
import re

from sigma.exceptions import (
SigmaPlaceholderError,
SigmaRuleLocation,
SigmaValueError,
SigmaRegularExpressionError,
SigmaTypeError,
)
from ipaddress import IPv4Network, IPv6Network, ip_network


class SpecialChars(Enum):
Expand Down Expand Up @@ -644,9 +644,13 @@ def escape(
if e is not None
]
)
pos = [ # determine positions of matches in regular expression
m.start() for m in re.finditer(r, self.regexp)
] if r is not '' else []
pos = (
[ # determine positions of matches in regular expression
m.start() for m in re.finditer(r, self.regexp)
]
if r is not ""
else []
)
ranges = zip([None, *pos], [*pos, None]) # string chunk ranges with escapes in between
ranges = list(ranges)

Expand Down
20 changes: 11 additions & 9 deletions tests/test_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
from ipaddress import IPv4Network, IPv6Network
import re
from ipaddress import IPv4Network, IPv6Network

import pytest

from sigma.exceptions import (
SigmaPlaceholderError,
SigmaTypeError,
SigmaValueError,
SigmaRegularExpressionError,
)
from sigma.types import (
SigmaBool,
SigmaCasedString,
Expand All @@ -17,12 +25,6 @@
sigma_type,
SigmaCIDRExpression,
)
from sigma.exceptions import (
SigmaPlaceholderError,
SigmaTypeError,
SigmaValueError,
SigmaRegularExpressionError,
)


@pytest.fixture
Expand Down Expand Up @@ -511,11 +513,11 @@ def test_re_escape_without_escape():

def test_re_escape_with_escape_escape_char_param():
# See issue #153 https://github.com/SigmaHQ/pySigma/issues/153
assert(
assert (
SigmaRegularExpression("bitsadmin\\.exe").escape(escape_escape_char=True)
== "bitsadmin\\\\.exe"
)
assert(
assert (
SigmaRegularExpression("bitsadmin\\.exe").escape(escape_escape_char=False)
== "bitsadmin\\.exe"
)
Expand Down

0 comments on commit 1786ad9

Please sign in to comment.