Skip to content

Commit

Permalink
πŸ“… Commit Tue, 10 Aug 2021 21:57:04
Browse files Browse the repository at this point in the history
πŸ“ docs added/updated
🎨 renamed split_by to split_by_regex
✨ join, which is the same as join_list
✨ split method
  • Loading branch information
securisec committed Aug 11, 2021
1 parent ea3aad3 commit ecf6a7e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</p>

![](https://github.com/securisec/chepy/workflows/tests/badge.svg)
![](https://img.shields.io/travis/com/securisec/chepy?logo=travis)
<!-- ![](https://img.shields.io/travis/com/securisec/chepy?logo=travis) -->
<!-- [![](https://img.shields.io/docker/cloud/build/securisec/chepy?logo=docker)](https://hub.docker.com/r/securisec/chepy) -->

[![](https://img.shields.io/readthedocs/chepy.svg?logo=read-the-docs&label=Docs)](http://chepy.readthedocs.io/en/latest/)
Expand All @@ -16,7 +16,7 @@
![](https://img.shields.io/github/license/securisec/chepy?label=License)

[![](https://pepy.tech/badge/chepy)](https://pepy.tech/project/chepy)
![](https://img.shields.io/docker/pulls/securisec/chepy?label=Docker%20pull&logo=docker)
<!-- ![](https://img.shields.io/docker/pulls/securisec/chepy?label=Docker%20pull&logo=docker) -->


# Chepy
Expand Down
16 changes: 16 additions & 0 deletions chepy/modules/dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ def str_list_to_list(self) -> DataFormatT:
self.state = ujson.loads(re.sub(r"'", '"', self._convert_to_str()))
return self

@ChepyDecorators.call_stack
def join(self, by: Union[str, bytes] = "") -> DataFormatT:
"""Join a list with specified character
Args:
by (Union[str, bytes], optional): What to join with. Defaults to ""
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy(["a", "b", "c"]).join_list(":").o
"a:b:c"
"""
self.state = by.join(self.state)
return self

@ChepyDecorators.call_stack
def join_list(self, by: Union[str, bytes] = "") -> DataFormatT:
"""Join a list with specified character
Expand Down
1 change: 1 addition & 0 deletions chepy/modules/dataformat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DataFormat(ChepyCore):
def bytes_to_ascii(self: DataFormatT) -> DataFormatT: ...
def list_to_str(self: DataFormatT, join_by: Union[str, bytes]=...) -> DataFormatT: ...
def str_list_to_list(self: DataFormatT) -> DataFormatT: ...
def join(self: DataFormatT, by: Union[str, bytes]=...) -> DataFormatT: ...
def join_list(self: DataFormatT, by: Union[str, bytes]=...) -> DataFormatT: ...
def json_to_dict(self: DataFormatT) -> DataFormatT: ...
def dict_to_json(self: DataFormatT) -> DataFormatT: ...
Expand Down
17 changes: 15 additions & 2 deletions chepy/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,21 @@ def regex_search(
return self

@ChepyDecorators.call_stack
def split_by(self, pattern: str = "\n", trim=True) -> UtilsT:
"""Split a string by the given pattern
def split(self, delimiter: str = " ") -> UtilsT:
"""Split a string by a delimiter
Args:
delimiter (str, optional): Delimiter to split by. Defaults to " ".
Returns:
UtilsT: The Chepy object.
"""
self.state = self._convert_to_str().split(delimiter)
return self

@ChepyDecorators.call_stack
def split_by_regex(self, pattern: str = "\n", trim=True) -> UtilsT:
"""Split a string by the given regex pattern
Args:
pattern (str, optional): Pattern to split by. Defaults to '\\n'.
Expand Down
3 changes: 2 additions & 1 deletion chepy/modules/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Utils(ChepyCore):
def remove_whitespace(self: UtilsT, spaces: bool=..., carriage_return: bool=..., line_feeds: bool=..., tabs: bool=..., form_feeds: bool=...) -> Any: ...
def remove_nullbytes(self: UtilsT) -> UtilsT: ...
def regex_search(self: UtilsT, pattern: str, ignore_case: bool=..., multiline: bool=..., dotall: bool=..., unicode: bool=..., extended: bool=...) -> Any: ...
def split_by(self: UtilsT, pattern: str=..., trim: Any=...) -> UtilsT: ...
def split(self: UtilsT, delimiter: str=...) -> UtilsT: ...
def split_by_regex(self: UtilsT, pattern: str=..., trim: Any=...) -> UtilsT: ...
def split_by_n(self: UtilsT, n: int) -> UtilsT: ...
def select_every_n(self: UtilsT, n: int, start: int=...) -> UtilsT: ...
def unique(self: UtilsT) -> UtilsT: ...
Expand Down
4 changes: 4 additions & 0 deletions tests/test_dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ def test_join_list():
assert Chepy(["a", "b", "c"]).join_list(":").o == "a:b:c"


def test_join():
assert Chepy(["a", "b", "c"]).join(":").o == "a:b:c"


def test_to_int():
assert Chepy("1").to_int().o == 1

Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def test_remove_nullbytes():


def test_split_by():
assert len(Chepy("some lol random lolol data").split_by("lo").o) == 4
assert len(Chepy("some lol random lolol data").split_by("lo", trim=False).o) == 4
assert len(Chepy("some lol random lolol data").split_by_regex("lo").o) == 4
assert len(Chepy("some lol random lolol data").split_by_regex("lo", trim=False).o) == 4


def test_split_by_n():
Expand Down

0 comments on commit ecf6a7e

Please sign in to comment.