Skip to content

Commit

Permalink
move string functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnybod committed Sep 28, 2023
1 parent 78be144 commit 69e3bed
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion empire/server/api/v2/download/download_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import BaseModel

from empire.server.api.v2.tag.tag_dto import Tag, domain_to_dto_tag
from empire.server.utils.data_util import removeprefix
from empire.server.utils.string_util import removeprefix


def domain_to_dto_download(download):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Dict

from empire.server.core.module_models import EmpireModule
from empire.server.utils.data_util import removeprefix, removesuffix
from empire.server.utils.string_util import removeprefix, removesuffix


class Module:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Dict, Optional, Tuple

from empire.server.core.module_models import EmpireModule
from empire.server.utils.data_util import removeprefix, removesuffix
from empire.server.utils.string_util import removeprefix, removesuffix


class Module:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Dict, Optional, Tuple

from empire.server.core.module_models import EmpireModule
from empire.server.utils.data_util import removeprefix, removesuffix
from empire.server.utils.string_util import removeprefix, removesuffix


class Module:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Dict, Optional, Tuple

from empire.server.core.module_models import EmpireModule
from empire.server.utils.data_util import removeprefix, removesuffix
from empire.server.utils.string_util import removeprefix, removesuffix


class Module:
Expand Down
2 changes: 1 addition & 1 deletion empire/server/stagers/osx/application.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from empire.server.utils.data_util import removeprefix, removesuffix
from empire.server.utils.string_util import removeprefix, removesuffix

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion empire/server/stagers/osx/dylib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from empire.server.common import helpers
from empire.server.utils.data_util import removeprefix, removesuffix
from empire.server.utils.string_util import removeprefix, removesuffix


class Stager:
Expand Down
2 changes: 1 addition & 1 deletion empire/server/stagers/osx/pkg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from empire.server.common import helpers
from empire.server.utils.data_util import removeprefix, removesuffix
from empire.server.utils.string_util import removeprefix, removesuffix


class Stager:
Expand Down
Empty file added empire/server/utils/__init__.py
Empty file.
14 changes: 0 additions & 14 deletions empire/server/utils/data_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,3 @@ def ps_convert_to_oneliner(psscript):
def is_port_in_use(port: int) -> bool:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex(("localhost", port)) == 0


def removeprefix(s, prefix):
# Remove when we drop Python 3.8 support
if s.startswith(prefix):
return s[len(prefix) :]
return s


def removesuffix(s, suffix):
# Remove when we drop Python 3.8 support
if s.endswith(suffix):
return s[: -len(suffix)]
return s
12 changes: 12 additions & 0 deletions empire/server/utils/string_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def removeprefix(s, prefix):
# Remove when we drop Python 3.8 support
if s.startswith(prefix):
return s[len(prefix) :]
return s


def removesuffix(s, suffix):
# Remove when we drop Python 3.8 support
if s.endswith(suffix):
return s[: -len(suffix)]
return s
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from empire.server.utils.data_util import removeprefix, removesuffix
from empire.server.utils.string_util import removeprefix, removesuffix


def test_remove_prefix():
Expand Down

0 comments on commit 69e3bed

Please sign in to comment.