Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
JINWOO-J committed Nov 25, 2024
1 parent 9812a73 commit 4b86ec0
Show file tree
Hide file tree
Showing 50 changed files with 5,863 additions and 561 deletions.
6 changes: 3 additions & 3 deletions BUILD_ARGS
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

--build-arg BASE_IMAGE=python:3.9.13-slim-buster
--build-arg BUILD_DATE=2024-11-05T23:05:25UTC
--build-arg BUILD_DATE=2024-11-25T00:37:29UTC
--build-arg DOCKER_BUILD_OPTION=--no-cache --rm=true
--build-arg ECHO_OPTION=
--build-arg GIT_USER=JINWOO-J
--build-arg IS_MULTI_ARCH=false
--build-arg LOCAL_SERVER=20.20.5.172
--build-arg LOCAL_SERVER=asweenter-oracle
--build-arg NAME=pawnlib
--build-arg PRIMARY_BRANCH=master
--build-arg REPO_HUB=jinwoo
--build-arg SED_OPTION=''
--build-arg UNAME_S=Darwin
--build-arg VERSION=2.0.72
--build-arg VERSION=2.0.74
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ build: make_build_args clean test
hatchling build


full_build: make_build_args clean test
@echo "Building Full Version project with name: $(NAME)"
DEPENDENCY_MODE=full hatch build

init:
git init
git add .
Expand Down Expand Up @@ -142,9 +146,9 @@ bash: make_debug_mode print_version
bb:
docker run -it --rm $(REPO_HUB)/$(NAME):$(VERSION) bash

local: build
local: full_build
pip3 install dist/pawnlib-$(VERSION)-py3-none-any.whl --force-reinstall

local_deploy: build
local_deploy: full_build
scp dist/$(NAME)-$(VERSION)-py3-none-any.whl root@$(LOCAL_SERVER):/app/;
ssh root@$(LOCAL_SERVER) pip3 install /app/$(NAME)-$(VERSION)-py3-none-any.whl --force-reinstall
ssh root@$(LOCAL_SERVER) pip3 install /app/$(NAME)-$(VERSION)-py3-none-any.whl --force-reinstall --ignore-installed --no-deps
39 changes: 39 additions & 0 deletions examples/converter/convert_bytes_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
import common
from pawnlib.typing.converter import format_size, format_network_traffic
from pawnlib.config import pawn

class Incrementer:
def __init__(self, start=1000):
self.current = start

def increment(self):
value = self.current
self.current *= 1000
return value


def print_formated_size(unit="", unit_type="storage"):
increment = Incrementer()
for _ in range(7):
value = increment.increment()
formatted_size = format_size(value, unit=unit, decimal_places=5, unit_type=unit_type)
pawn.console.log(f"{value:>42,} {formatted_size:>20}")


def print_formated_network_size(per_second=False):
increment = Incrementer()
for _ in range(7):
value = increment.increment()
formatted_size = format_network_traffic(size=value, per_second=per_second)
pawn.console.log(f"{value:>42,} {formatted_size:>20}")


print_formated_size()
print_formated_size(unit="GB")
print_formated_size( unit_type="network")



print_formated_network_size()
print_formated_network_size(per_second=True)
48 changes: 44 additions & 4 deletions examples/converter/dot2dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pawnlib.output.color_print import dump, classdump
from pawnlib.config import pawnlib_config as pawn
dict_config = {
"key1": "key1 is value",
"111": "sdsdsd",
"1111": "sdsdsd",
"11111": "sdsdsd",
Expand All @@ -21,6 +22,7 @@
res2 = FlatDict(dict_config, delimiter=".")
dump(res2)
pawn.console.log(f"Get 11111-1.2222-1 => {res2.get('11111-1.2222-1')}")

dump(flatten(dict_config))


Expand All @@ -31,10 +33,48 @@
]

dump(FlatDict(list_config))
dump(FlatDict(list_config).as_dict())

flatten_dict_test = FlatDict(list_config)

dump(flatten_dict_test.as_dict())

unflatten_dict = FlatDict(list_config).as_dict()

pawn.console.log(FlatDict(unflatten_dict))

rpc_response = {
"jsonrpc": "2.0",
"result": {
"block_hash": "db0e18176318217d246ff10aee570f8d31a430cacf8bca2e0b0a97fc622f103f",
"confirmed_transaction_list": [
{
"data": {
"result": {
"coveredByFee": "0x0",
"coveredByOverIssuedICX": "0x0",
"issue": "0x201fdfcf45d9425f"
}
},
"dataType": "base",
"timestamp": "0x62760444bdf10",
"txHash": "0xc81ff93eb41f0b762a8342ec62c9bc2a4322586a4cd050d23306d73bbf1392ab",
"version": "0x3"
}
],
"height": 8747878,
"merkle_tree_root_hash": "016a2af5fe5001c053a1856f996ad66f6ae1877f547deb645dee909cac689bd9",
"peer_id": "hxf2b4ef450c4f158b4611e234bb57f00ad7a615ef",
"prev_block_hash": "6ae91471d1aea76544e58fe6e222dcc08a73ed90b5a9c679c0a78b08aca2f111",
"signature": "",
"time_stamp": 1732144276430608,
"version": "2.0"
},
"id": 2848
}

flatten_rpc = FlatDict(rpc_response)
pawn.console.print(flatten_rpc)
pawn.console.print(flatten_rpc.to_dict())


flatten_dict = FlatDict(list_config).as_dict()

pawn.console.log(FlatDict(flatten_dict).unflatten())
pawn.console.log(FlatDict(res2.as_dict(), ).unflatten())
97 changes: 97 additions & 0 deletions examples/converter/new_dot2dict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env python3
import common
from pawnlib.typing.converter import FlatDict, FlatterDict, flatten, Flattener
from pawnlib.output.color_print import dump, classdump
from pawnlib.config import pawnlib_config as pawn
dict_config = {
"key1": "key1 is value",
"111": "sdsdsd",
"1111": "sdsdsd",
"11111": "sdsdsd",
"11111-1": {
"2222-1": "xcxcxc",
"212222-1": "xcxcxc"
},
"list": [
"list1",
"list2",
{"aaaa": "bbbbbbbbbbbbbbbbbbbbbbbb"}
]
}

res2 = Flattener(dict_config, delimiter=".")
pawn.console.rule("Print as String")
dump(res2)
pawn.console.rule("Print as dict ")
dump(res2.to_dict())
pawn.console.rule("Print key ")
pawn.console.log(f"Get 11111-1.2222-1 => {res2.get('11111-1.2222-1')}")

list_config = [
"list1",
"list2",
{"aaaa": "bbbbbbbbbbbbbbbbbbbbbbbb"}
]

dump(Flattener(list_config))

flatten_dict_test = Flattener(list_config)

pawn.console.rule("Unflatten ")
dump(flatten_dict_test.unflatten())

unflatten_dict = FlatDict(list_config).as_dict()

rpc_response = {
"jsonrpc": "2.0",
"result": {
"block_hash": "db0e18176318217d246ff10aee570f8d31a430cacf8bca2e0b0a97fc622f103f",
"confirmed_transaction_list": [
{
"data": {
"result": {
"coveredByFee": "0x0",
"coveredByOverIssuedICX": "0x0",
"issue": "0x201fdfcf45d9425f"
}
},
"dataType": "base",
"timestamp": "0x62760444bdf10",
"txHash": "0xc81ff93eb41f0b762a8342ec62c9bc2a4322586a4cd050d23306d73bbf1392ab",
"version": "0x3"
}
],
"height": 8747878,
"merkle_tree_root_hash": "016a2af5fe5001c053a1856f996ad66f6ae1877f547deb645dee909cac689bd9",
"peer_id": "hxf2b4ef450c4f158b4611e234bb57f00ad7a615ef",
"prev_block_hash": "6ae91471d1aea76544e58fe6e222dcc08a73ed90b5a9c679c0a78b08aca2f111",
"signature": "",
"time_stamp": 1732144276430608,
"version": "2.0"
},
"id": 2848
}

flatten_rpc = Flattener(rpc_response)
pawn.console.print(flatten_rpc.get("result.time_stamp"))
pawn.console.print(repr(flatten_rpc))

pawn.console.print(flatten_rpc.to_dict())

pawn.console.rule("Keep list")

pawn.console.log(Flattener(rpc_response, keep_lists=True).to_dict())

pawn.console.rule("get 'result'")
pawn.console.log(flatten_rpc.get('result'))

pawn.console.rule("get 'result.prev_block_hash'")
pawn.console.log(flatten_rpc.get('result.prev_block_hash'))

exit()

pawn.console.print(flatten_rpc.unflatten())
pawn.console.print(flatten_rpc.original_value)



42 changes: 42 additions & 0 deletions examples/file/null_bytes_remover_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
try:
import common
except:
pass
from pawnlib.output.file import NullByteRemover


def create_test_file(file_path, size_in_bytes, null_byte_positions):
"""
Create a test file with specified size and null bytes at given positions.
:param file_path: Path to the test file to be created.
:param size_in_bytes: Total size of the file in bytes.
:param null_byte_positions: List of byte positions where null bytes should be inserted.
"""
with open(file_path, 'wb') as f:
for i in range(size_in_bytes):
if i in null_byte_positions:
f.write(b'\x00'*10) # Write a null byte
else:
f.write(b'A') # Write a regular byte (e.g., 'A')

def main():
# Create test files
test_files = [
("test_file1.txt", 1024, [0, 20, 30]), # 1 KB file with null bytes at positions 10, 20, 30
("test_file2.txt", 2048, [50, 100, 150]), # 2 KB file with null bytes at positions 50, 100, 150
("test_file3.txt", 512, [5, 15]), # 512 bytes file with null bytes at positions 5, 15
]

for file_name, size, null_positions in test_files:
create_test_file(file_name, size, null_positions)
print(f"Created {file_name} with size {size} bytes and null bytes at positions {null_positions}")

# Now we can use the NullByteRemover class to remove null bytes from these files
remover = NullByteRemover([file_name for file_name, _, _ in test_files])
remover.remove_null_bytes()
remover.print_report()

if __name__ == "__main__":
main()
Binary file added examples/file/test_file1.txt
Binary file not shown.
1 change: 1 addition & 0 deletions examples/file/test_file1.txt_recovered
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Binary file added examples/file/test_file2.txt
Binary file not shown.
1 change: 1 addition & 0 deletions examples/file/test_file2.txt_recovered
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Binary file added examples/file/test_file3.txt
Binary file not shown.
1 change: 1 addition & 0 deletions examples/file/test_file3.txt_recovered
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
5 changes: 1 addition & 4 deletions examples/http/network_info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
from pawnlib.output import *
from pawnlib.utils import NetworkInfo

network_info = NetworkInfo()

pawn.console.rule("Force=False")
pawn.console.log(NetworkInfo(force=False))
network_info = NetworkInfo(force=True)

pawn.console.rule("Force=True")
pawn.console.log(NetworkInfo(force=True))
Expand Down
32 changes: 32 additions & 0 deletions examples/icon_rpc_test/iiss_with_icon_rpc_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
import time
import common
from pawnlib.config import pawnlib_config as pawn
from pawnlib.utils.http import jequest, disable_ssl_warnings, icon_rpc_call, IconRpcHelper, NetworkInfo
from pawnlib.utils import icx_signer, http

disable_ssl_warnings()
# icx_signer.compressed = False


def main():
# private_key = "0x32cf8c963178b1dc15abe5628ce098ce067d7afc8cffa0f27405edd3afa90810"
private_key = "cd405e346fa7b7da8c29fdbb769c76965e1a764c2e2f54337ccd0b35434bafc3"
# pawn.console.log(private_key)
network_info = NetworkInfo(network_name="jw-test", network_api="http://20.20.4.129:9000")
pawn.console.log(network_info)

wallet = icx_signer.load_wallet_key(private_key)
icon_rpc = IconRpcHelper(
network_info=network_info,
wallet=wallet,
raise_on_failure=True,
tx_method='icx_getTransactionByHash',
)

pawn.console.log(icon_rpc.claim_iscore())
pawn.console.log(icon_rpc.unjail())


if __name__ == '__main__':
main()
Loading

0 comments on commit 4b86ec0

Please sign in to comment.