From c5281aefe8d304b3eafcae71fd1b4798371d00ee Mon Sep 17 00:00:00 2001 From: pancake Date: Thu, 11 Jan 2024 18:50:38 +0100 Subject: [PATCH] Fix some pylint issues --- python/Makefile | 1 + python/r2pipe/README.md | 2 -- python/r2pipe/__init__.py | 28 +++++++++++++--------------- python/r2pipe/open_sync.py | 4 ++++ 4 files changed, 18 insertions(+), 17 deletions(-) delete mode 100644 python/r2pipe/README.md diff --git a/python/Makefile b/python/Makefile index a8d2cea..48b4132 100644 --- a/python/Makefile +++ b/python/Makefile @@ -30,6 +30,7 @@ testpy2: PYTHONPATH=$$PWD $(PYTHON) -m pip install coverage pytest PYTHONPATH=$$PWD $(PYTHON) -m coverage run --omit="*.local*" -m pytest -k "test_" test PYTHONPATH=$$PWD $(PYTHON) -m coverage report + -pylint r2pipe/*.py test-examples: $(PYTHON) examples/test.py diff --git a/python/r2pipe/README.md b/python/r2pipe/README.md deleted file mode 100644 index 57aad0b..0000000 --- a/python/r2pipe/README.md +++ /dev/null @@ -1,2 +0,0 @@ -r2-pipe python api -================== diff --git a/python/r2pipe/__init__.py b/python/r2pipe/__init__.py index 3ca91e3..2bf3b64 100644 --- a/python/r2pipe/__init__.py +++ b/python/r2pipe/__init__.py @@ -27,6 +27,7 @@ import os import sys import time +from r2pipe.open_sync import open as r2pipe_open try: import r2lang @@ -35,8 +36,6 @@ VERSION = "1.8.6" -from r2pipe.open_sync import open - def version(): """Return string with the version of the r2pipe library @@ -44,11 +43,8 @@ def version(): return VERSION -"""open class is now in open_base.py""" - -# Hello World +# Open class is now in open_base.py if __name__ == "__main__": - print("[+] Spawning r2 tcp and http servers") os.system("pkill r2") os.system("radare2 -qc.:9080 /bin/ls &") @@ -58,7 +54,7 @@ def version(): if sys.version_info <= (3, 0): # Test r2pipe with local process print("[+] Testing python r2pipe local") - rlocal = open("/bin/ls") + rlocal = r2pipe_open("/bin/ls") print(rlocal.cmd("pi 5")) # print rlocal.cmd("pn") info = rlocal.cmdj("ij") @@ -66,7 +62,7 @@ def version(): # Test r2pipe with remote tcp process (launch it with "radare2 -qc.:9080 myfile") print("[+] Testing python r2pipe tcp://") - rremote = open("tcp://127.0.0.1:9080") + rremote = r2pipe_open("tcp://127.0.0.1:9080") disas = rremote.cmd("pi 5") if not disas: print("Error with remote tcp conection") @@ -75,7 +71,7 @@ def version(): # Test r2pipe with remote http process (launch it with "radare2 -qc=H myfile") print("[+] Testing python r2pipe http://") - rremote = open("http://127.0.0.1:9090") + rremote = r2pipe_open("http://127.0.0.1:9090") disas = rremote.cmd("pi 5") if not disas: print("Error with remote http conection") @@ -86,6 +82,8 @@ def version(): # Python 3 examples, with non-blocking API and callbacks # -------------------------------------------------------------------------- def callback(result): + """Dummy callback printing command execution result + """ print(result) # @@ -93,7 +91,7 @@ def callback(result): # # Start 1 task print("[+] Testing python r2pipe local") - rlocal = open("/bin/ls") + rlocal = r2pipe_open("/bin/ls") t = rlocal.cmd("pi 5", callback=callback) rlocal.wait(t) # Wait for task end info = rlocal.cmdj("ij") @@ -102,7 +100,7 @@ def callback(result): rlocal.close() # Start 3 tasks with Context manager print("[+] Testing python r2pipe local with 3 queries") - with open("/bin/ls") as rlocall: + with r2pipe_open("/bin/ls") as rlocall: t1 = rlocall.cmd("pi 5", callback=callback) t2 = rlocall.cmd("pi 5", callback=callback) t3 = rlocall.cmd("pi 5", callback=callback) @@ -113,14 +111,14 @@ def callback(result): # # Start 1 task print("[+] Testing python r2pipe tcp://") - rremote = open("tcp://127.0.0.1:9080") + rremote = r2pipe_open("tcp://127.0.0.1:9080") t = rremote.cmd("pi 5", callback=callback) rremote.wait(t) rremote.close() # Start 3 tasks with Context manager print("[+] Testing python r2pipe tcp:// with 3 queries") - with open("tcp://127.0.0.1:9080") as rremote: + with r2pipe_open("tcp://127.0.0.1:9080") as rremote: t1 = rremote.cmd("pi 5", callback=callback) t2 = rremote.cmd("pi 5", callback=callback) t3 = rremote.cmd("pi 5", callback=callback) @@ -131,14 +129,14 @@ def callback(result): # Test r2pipe with remote http process (launch it with "radare2 -qc=H myfile") # print("[+] Testing python r2pipe http://") - rremote = open("tcp://127.0.0.1:9080") + rremote = r2pipe_open("tcp://127.0.0.1:9080") t = rremote.cmd("pi 5", callback=callback) rremote.wait(t) rremote.close() # Start 3 tasks with Context manager print("[+] Testing python r2pipe http:// with 3 queries") - with open("http://127.0.0.1:9090") as rremote: + with r2pipe_open("http://127.0.0.1:9090") as rremote: t1 = rremote.cmd("pi 10", callback=callback) t2 = rremote.cmd("pi 5", callback=callback) t3 = rremote.cmd("pi 5", callback=callback) diff --git a/python/r2pipe/open_sync.py b/python/r2pipe/open_sync.py index 837cbf7..3ec26af 100644 --- a/python/r2pipe/open_sync.py +++ b/python/r2pipe/open_sync.py @@ -29,6 +29,10 @@ def no_urlopen(): class open(OpenBase): + def __enter__(self): + return + def __exit__(self): + return def __init__(self, filename="", flags=[], radare2home=None): super(open, self).__init__(filename, flags) self.pipe_read_sleep = 0.001