Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pytest = "^7.1.3"
requests = "^2.28.1"
jupyter = "^1.0.0"
ipython = "^8.5.0"
security = "==1.3.1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library holds security tools for protecting Python API calls.

License: MITOpen SourceMore facts



[tool.poetry.group.dev.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions python3/10_Modules/06_subprocess/00_subprocess_ex.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import subprocess
from security import safe_command


def execute_command(cmd):
Expand All @@ -13,8 +14,7 @@ def execute_command(cmd):


def get_execution_result(cmd):
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
p = safe_command.run(subprocess.Popen, cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
output, err = p.communicate()

Expand Down
4 changes: 2 additions & 2 deletions python3/10_Modules/06_subprocess/03_ping_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
import os
import subprocess
from security import safe_command


def ping_website(site_name):
Expand All @@ -12,8 +13,7 @@ def ping_website(site_name):


def get_time_delays(site_name):
p = subprocess.Popen(
f"ping {site_name}", stdout=subprocess.PIPE, stderr=subprocess.PIPE
p = safe_command.run(subprocess.Popen, f"ping {site_name}", stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
output, error = p.communicate()
if error:
Expand Down
3 changes: 2 additions & 1 deletion python3/10_Modules/06_subprocess/cleanup_pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import subprocess
from security import safe_command

base_dir = "/tmp/pid_dir"
pid_files = ("ut.pid", "ft.pid")
Expand All @@ -21,7 +22,7 @@ def check_pid(pid):
def get_elapsed_time(pid):
"""get the elapsed time of the process with this pid"""
cmd = f"ps -p {str(pid)} -o pid,etime"
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
proc = safe_command.run(subprocess.Popen, cmd, shell=True, stdout=subprocess.PIPE)
# get data from stdout
proc.wait()
results = proc.stdout.readlines()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from reportlab.lib.utils import simpleSplit
from reportlab.pdfbase.pdfmetrics import stringWidth
from reportlab.platypus import Paragraph, SimpleDocTemplate
from security import safe_command


class form:
Expand Down Expand Up @@ -106,8 +107,7 @@ def __init__(self):
path_to_pdf = os.path.abspath(
os.path.join(os.path.expanduser("~"), "Desktop") + "\hello1.pdf"
)
process = subprocess.Popen(
[path_to_pdf],
process = safe_command.run(subprocess.Popen, [path_to_pdf],
bufsize=2048,
shell=True,
stdin=subprocess.PIPE,
Expand Down
Loading