Skip to content

Commit 2498b58

Browse files
committed
πŸ—“ Apr 4, 2022 7:32:27 PM
4.0.0 πŸ”₯ move some extractors and codetidy to plugins πŸ”₯ move multimedia to plugins βž• deps removed from core πŸ§ͺ tests added/updated
1 parent cd9ab3e commit 2498b58

17 files changed

+61
-806
lines changed

β€Ž.coveragerc

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ omit =
77

88

99
[report]
10-
fail_under = 90
10+
fail_under = 100

β€Žchepy/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from .modules.hashing import Hashing
1111
from .modules.language import Language
1212
from .modules.links import Links
13-
from .modules.multimedia import Multimedia
1413
from .modules.networking import Networking
1514
from .modules.other import Other
1615
from .modules.publickey import Publickey
@@ -34,7 +33,6 @@ class Chepy(
3433
Hashing,
3534
Language,
3635
Links,
37-
Multimedia,
3836
Networking,
3937
Other,
4038
Publickey,

β€Žchepy/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "3.5.1" # pragma: no cover
1+
__version__ = "4.0.0" # pragma: no cover
22
__author__ = "Hapsida @securisec" # pragma: no cover

β€Žchepy/core.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def for_each(self, methods: List[Tuple[Union[str, object], dict]]):
256256
>>> c = Chepy(['41', '42'])
257257
>>> c.for_each([("from_hex",), ("to_hex",)])
258258
>>> # this is how to use fork methods with a string
259-
>>> c.for([(c.from_hex,), (c.to_hex,)])
259+
>>> c.for_each([(c.from_hex,), (c.to_hex,)])
260260
>>> # This is how to use fork using methods
261261
>>> print(c)
262262
['41', '42']
@@ -539,7 +539,7 @@ def _convert_to_str(self) -> str:
539539
return str(self.state)
540540
elif isinstance(self.state, bytearray):
541541
return bytearray(self.state).decode()
542-
elif isinstance(self.state, float):
542+
elif isinstance(self.state, float): # pragma: no cover
543543
return format(self.state, "f")
544544
else: # pragma: no cover
545545
# todo check more types here

β€Žchepy/modules/codetidy.py

+4-55
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
from typing import TypeVar
2-
import lazy_import
32

43
import json
54

6-
pydash = lazy_import.lazy_module("pydash")
7-
import phpserialize
5+
import pydash
86
import regex as re
9-
from lxml import etree
107
from ..core import ChepyCore, ChepyDecorators
118

129
CodeTidyT = TypeVar("CodeTidyT", bound="CodeTidy")
@@ -27,7 +24,9 @@ def minify_json(self) -> CodeTidyT:
2724
>>> c = Chepy("/path/to/file.json").load_file()
2825
>>> print(c.minify_json())
2926
"""
30-
self.state = json.dumps(json.loads(self._convert_to_str()), separators=(',', ':'))
27+
self.state = json.dumps(
28+
json.loads(self._convert_to_str()), separators=(",", ":")
29+
)
3130
return self
3231

3332
@ChepyDecorators.call_stack
@@ -47,56 +46,6 @@ def beautify_json(self, indent: int = 2) -> CodeTidyT:
4746
self.state = json.dumps(json.loads(self._convert_to_str()), indent=indent)
4847
return self
4948

50-
@ChepyDecorators.call_stack
51-
def minify_xml(self) -> CodeTidyT:
52-
"""Minify XML string
53-
54-
Returns:
55-
Chepy: The Chepy object.
56-
57-
Examples:
58-
>>> c = Chepy("/path/to/file.xml").load_file()
59-
>>> print(c.minify_xml())
60-
"""
61-
parser = etree.XMLParser(remove_blank_text=True)
62-
self.state = etree.tostring(
63-
etree.fromstring(self._convert_to_bytes(), parser=parser)
64-
)
65-
return self
66-
67-
@ChepyDecorators.call_stack
68-
def beautify_xml(self) -> CodeTidyT:
69-
"""Beautify compressed XML
70-
71-
Returns:
72-
Chepy: The Chepy object.
73-
74-
Examples:
75-
>>> c = Chepy("/path/to/file.xml").load_file()
76-
>>> print(c.beautify_json())
77-
"""
78-
self.state = etree.tostring(
79-
etree.fromstring(self._convert_to_bytes()), pretty_print=True
80-
)
81-
return self
82-
83-
@ChepyDecorators.call_stack
84-
def php_deserialize(self) -> CodeTidyT:
85-
"""Deserialize php to dict
86-
87-
Deserializes PHP serialized data, outputting keyed arrays as a python dict.
88-
89-
Returns:
90-
Chepy: The Chepy object.
91-
92-
Examples:
93-
>>> c = Chepy('a:3:{i:1;s:6:"elem 1";i:2;s:6:"elem 2";i:3;s:7:" elem 3";}')
94-
>>> c.php_deserialize()
95-
{1: b'elem 1', 2: b'elem 2', 3: b' elem 3'}
96-
"""
97-
self.state = phpserialize.loads(self._convert_to_bytes())
98-
return self
99-
10049
@ChepyDecorators.call_stack
10150
def to_upper_case(self, by: str = "all") -> CodeTidyT:
10251
"""Convert string to uppercase

β€Žchepy/modules/codetidy.pyi

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ class CodeTidy(ChepyCore):
99
state: Any = ...
1010
def minify_json(self: CodeTidyT) -> CodeTidyT: ...
1111
def beautify_json(self: CodeTidyT, indent: int=...) -> CodeTidyT: ...
12-
def minify_xml(self: CodeTidyT) -> CodeTidyT: ...
13-
def beautify_xml(self: CodeTidyT) -> CodeTidyT: ...
14-
def php_deserialize(self: CodeTidyT) -> CodeTidyT: ...
1512
def to_upper_case(self: CodeTidyT, by: Literal['all', 'word', 'sentence']=...) -> CodeTidyT: ...
1613
def to_lower_case(self: CodeTidyT) -> CodeTidyT: ...
1714
def to_snake_case(self: CodeTidyT) -> CodeTidyT: ...

β€Žchepy/modules/encryptionencoding.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
jwt = lazy_import.lazy_module("jwt")
1111
import pathlib
1212

13-
import pycipher
1413
import regex as re
1514
import json
1615

@@ -24,6 +23,7 @@
2423
PKCS1_OAEP = lazy_import.lazy_module("Crypto.Cipher.PKCS1_OAEP")
2524
Blowfish = lazy_import.lazy_module("Crypto.Cipher.Blowfish")
2625
Padding = lazy_import.lazy_module("Crypto.Util.Padding")
26+
pycipher = lazy_import.lazy_module("pycipher")
2727

2828
from ..core import ChepyCore, ChepyDecorators
2929
from ..extras.combinatons import hex_chars

β€Žchepy/modules/extractors.py

-81
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
from typing import TypeVar
22
from urllib.parse import urlparse as _pyurlparse
33

4-
import jsonpath_rw
5-
import lazy_import
64
import regex as re
7-
import json
85

9-
parsel = lazy_import.lazy_module("parsel")
106
from ..core import ChepyCore, ChepyDecorators
117

128
ExtractorsT = TypeVar("ExtractorsT", bound="Extractors")
@@ -16,10 +12,6 @@ class Extractors(ChepyCore):
1612
def __init__(self, *data):
1713
super().__init__(*data)
1814

19-
def _parsel_obj(self):
20-
"""Returns a parsel.Selector object"""
21-
return parsel.Selector(self._convert_to_str())
22-
2315
@ChepyDecorators.call_stack
2416
def extract_hashes(self) -> ExtractorsT:
2517
"""Extract md5, sha1, sha256 and sha512 hashes
@@ -207,79 +199,6 @@ def extract_domains(self, is_binary: bool = False) -> ExtractorsT:
207199
self.state = matched
208200
return self
209201

210-
@ChepyDecorators.call_stack
211-
def xpath_selector(self, query: str, namespaces: str = None) -> ExtractorsT:
212-
"""Extract data using valid xpath selectors
213-
214-
Args:
215-
query (str): Required. Xpath query
216-
namespaces (str, optional): Namespace. Applies for XML data. Defaults to None.
217-
218-
Returns:
219-
Chepy: The Chepy object.
220-
221-
Examples:
222-
>>> c = Chepy("http://example.com")
223-
>>> c.http_request()
224-
>>> c.xpath_selector("//title/text()")
225-
>>> c.get_by_index(0)
226-
>>> c.o
227-
"Example Domain"
228-
"""
229-
self.state = (
230-
parsel.Selector(self._convert_to_str(), namespaces=namespaces)
231-
.xpath(query)
232-
.getall()
233-
)
234-
return self
235-
236-
@ChepyDecorators.call_stack
237-
def css_selector(self, query: str) -> ExtractorsT:
238-
"""Extract data using valid CSS selectors
239-
240-
Args:
241-
query (str): Required. CSS query
242-
243-
Returns:
244-
Chepy: The Chepy object.
245-
246-
Examples:
247-
>>> c = Chepy("http://example.com")
248-
>>> c.http_request()
249-
>>> c.css_selector("title")
250-
>>> c.get_by_index(0)
251-
>>> c.o
252-
"<title>Example Domain</title>"
253-
"""
254-
self.state = self._parsel_obj().css(query).getall()
255-
return self
256-
257-
@ChepyDecorators.call_stack
258-
def jpath_selector(self, query: str) -> ExtractorsT:
259-
"""Query JSON with jpath query
260-
261-
`Reference <https://goessner.net/articles/JsonPath/index.html#e2>`__
262-
263-
Args:
264-
query (str): Required. Query. For reference, see the help
265-
266-
Returns:
267-
Chepy: The Chepy object.
268-
269-
Examples:
270-
>>> c = Chepy("tests/files/test.json")
271-
>>> c.load_file()
272-
>>> c.jpath_selector("[*].name.first")
273-
>>> c.get_by_index(2)
274-
>>> c.o
275-
"Long"
276-
"""
277-
self.state = list(
278-
j.value
279-
for j in jsonpath_rw.parse(query).find(json.loads(self._convert_to_str()))
280-
)
281-
return self
282-
283202
@ChepyDecorators.call_stack
284203
def html_comments(self) -> ExtractorsT:
285204
"""Extract html comments

β€Žchepy/modules/extractors.pyi

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from ..core import ChepyCore
22
from typing import Any, TypeVar
33

4-
parsel: Any
54
ExtractorsT = TypeVar('ExtractorsT', bound='Extractors')
65

76
class Extractors(ChepyCore):
@@ -14,9 +13,6 @@ class Extractors(ChepyCore):
1413
def extract_mac_address(self: ExtractorsT, is_binary: bool=...) -> ExtractorsT: ...
1514
def extract_urls(self: ExtractorsT, is_binary: bool=...) -> ExtractorsT: ...
1615
def extract_domains(self: ExtractorsT, is_binary: bool=...) -> ExtractorsT: ...
17-
def xpath_selector(self: ExtractorsT, query: str, namespaces: str=...) -> ExtractorsT: ...
18-
def css_selector(self: ExtractorsT, query: str) -> ExtractorsT: ...
19-
def jpath_selector(self: ExtractorsT, query: str) -> ExtractorsT: ...
2016
def html_comments(self: ExtractorsT) -> ExtractorsT: ...
2117
def javascript_comments(self: ExtractorsT) -> ExtractorsT: ...
2218
def html_tags(self: ExtractorsT, tag: str) -> ExtractorsT: ...

0 commit comments

Comments
Β (0)