Skip to content

Commit 87272cf

Browse files
committed
- ✨ fo/from_fullwidth
- ✨ remove_newlines - 🧪 tests added/updated - 🐙 version 7.6.0
1 parent a2da458 commit 87272cf

File tree

8 files changed

+74
-3
lines changed

8 files changed

+74
-3
lines changed

chepy/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "7.5.0" # pragma: no cover
1+
__version__ = "7.6.0" # pragma: no cover
22
__author__ = "@securisec" # pragma: no cover

chepy/modules/dataformat.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,3 +2481,41 @@ def from_italics(self) -> DataFormatT:
24812481
translation_table = str.maketrans(italic, normal)
24822482
self.state = text.translate(translation_table)
24832483
return self
2484+
2485+
@ChepyDecorators.call_stack
2486+
def to_fullwidth(self):
2487+
"""Convert string to full width string
2488+
2489+
Returns:
2490+
Chepy: The Chepy object.
2491+
"""
2492+
text = self._convert_to_str()
2493+
result = ""
2494+
for char in text:
2495+
if ord(char) in range(33, 127):
2496+
result += chr(ord(char) - 33 + 0xFF01)
2497+
elif char == " ":
2498+
result += "\u3000"
2499+
else:
2500+
result += char
2501+
self.state = result
2502+
return self
2503+
2504+
@ChepyDecorators.call_stack
2505+
def from_fullwidth(self):
2506+
"""Convert full width string to regular string
2507+
2508+
Returns:
2509+
Chepy: The Chepy object.
2510+
"""
2511+
text = self._convert_to_str()
2512+
result = ""
2513+
for char in text:
2514+
if ord(char) in range(0xFF01, 0xFF5F): # Fullwidth ASCII range
2515+
result += chr(ord(char) - 0xFF01 + 33)
2516+
elif char == "\u3000": # Ideographic space
2517+
result += " "
2518+
else:
2519+
result += char # pragma: no cover
2520+
self.state = result
2521+
return self

chepy/modules/dataformat.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,5 @@ class DataFormat(ChepyCore):
129129
def parse_sqlite(self: DataFormatT, query: str) -> DataFormatT: ...
130130
def to_italics(self: DataFormatT) -> DataFormatT: ...
131131
def from_italics(self: DataFormatT) -> DataFormatT: ...
132+
def to_fullwidth(self: DataFormatT) -> DataFormatT: ...
133+
def from_fullwidth(self: DataFormatT) -> DataFormatT: ...

chepy/modules/encryptionencoding.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,12 +2012,12 @@ def gpp_decrypt(self):
20122012

20132013
@ChepyDecorators.call_stack
20142014
def pgp_decrypt(
2015-
self, passphrase: Union[str | bytes], armoured: bool = False
2015+
self, passphrase: Union[str, bytes], armoured: bool = False
20162016
) -> EncryptionEncodingT:
20172017
"""Decrypt PGP encrypted file with passphrase
20182018
20192019
Args:
2020-
passphrase (Union[str | bytes]): passphrase
2020+
passphrase (Union[str, bytes]): passphrase
20212021
armoured (bool): PGP armoured format
20222022
20232023
Returns:

chepy/modules/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ def count_occurances(self, regex: str, case_sensitive: bool = False) -> UtilsT:
7070
self.state = len(r.findall(self._convert_to_str()))
7171
return self
7272

73+
@ChepyDecorators.call_stack
74+
def remove_newlines(self):
75+
"""Remove new lines
76+
77+
Returns:
78+
Chepy: The Chepy object.
79+
"""
80+
self.data = self._convert_to_bytes()
81+
self.state = self.data.translate(None, b"\r\n")
82+
return self
83+
7384
@ChepyDecorators.call_stack
7485
def remove_whitespace(
7586
self,

chepy/modules/utils.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Utils(ChepyCore):
88
state: Any = ...
99
def reverse(self: UtilsT, count: int=...) -> UtilsT: ...
1010
def count_occurances(self: UtilsT, regex: str, case_sensitive: bool=...) -> UtilsT: ...
11+
def remove_newlines(self: UtilsT) -> UtilsT: ...
1112
def remove_whitespace(self: UtilsT, spaces: bool=..., carriage_return: bool=..., line_feeds: bool=..., tabs: bool=..., form_feeds: bool=...) -> UtilsT: ...
1213
def remove_nullbytes(self: UtilsT) -> UtilsT: ...
1314
def regex_search(self: UtilsT, pattern: str, is_bytes: bool=False, ignore_case: bool=False, multiline: bool=False, dotall: bool=False, unicode: bool=False, extended: bool=False) -> UtilsT: ...

tests/test_dataformat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,3 +865,9 @@ def test_italics():
865865
Chepy("𝘩𝘦𝘭𝘭𝘰 123 !@$@# 𝘸𝘰𝘳𝘭𝘥").from_italics().out_as_any
866866
== "hello 123 !@$@# world"
867867
)
868+
869+
870+
def test_fullwidth():
871+
data = "union select;"
872+
assert Chepy(data).to_fullwidth().o.decode() == "union select;"
873+
assert Chepy("union select;").from_fullwidth().o == b"union select;"

tests/test_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ def test_search():
5353
)
5454

5555

56+
def test_remove_newlines():
57+
assert (
58+
Chepy("""foo
59+
bar
60+
baz\r\n
61+
bang
62+
""")
63+
.remove_newlines()
64+
.o
65+
== b"foo barbazbang"
66+
)
67+
68+
5669
def test_remove_nullbytes():
5770
assert (
5871
Chepy("./tests/files/hello")

0 commit comments

Comments
 (0)