Skip to content

Commit

Permalink
Fix some pylint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Jan 11, 2024
1 parent 98d8fe8 commit c5281ae
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions python/r2pipe/README.md

This file was deleted.

28 changes: 13 additions & 15 deletions python/r2pipe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import os
import sys
import time
from r2pipe.open_sync import open as r2pipe_open

try:
import r2lang
Expand All @@ -35,20 +36,15 @@

VERSION = "1.8.6"

from r2pipe.open_sync import open


def version():
"""Return string with the version of the r2pipe library
"""
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 &")
Expand All @@ -58,15 +54,15 @@ 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")
print("Architecture: " + info["bin"]["machine"])

# 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")
Expand All @@ -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")
Expand All @@ -86,14 +82,16 @@ def version():
# Python 3 examples, with non-blocking API and callbacks
# --------------------------------------------------------------------------
def callback(result):
"""Dummy callback printing command execution result
"""
print(result)

#
# Test r2pipe with local process
#
# 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")
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions python/r2pipe/open_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c5281ae

Please sign in to comment.