mirror of
https://github.com/aydwi/chaos.git
synced 2025-12-21 13:39:32 -06:00
Test intermediate changes
This commit is contained in:
@@ -18,7 +18,6 @@ from daemon import DaemonContext
|
||||
from PyQt5.QtGui import QGuiApplication, QClipboard
|
||||
from PyQt5.QtCore import QObject, QMimeData, QTimer
|
||||
from random import random
|
||||
from utils.pidfile import PidFile
|
||||
|
||||
|
||||
TGT = "a"
|
||||
@@ -45,7 +44,9 @@ def enable_ri(flag):
|
||||
@functools.wraps(func)
|
||||
def decorated_func(*args, **kwargs):
|
||||
text = args[0]
|
||||
occurences = [index for index, val in enumerate(text) if val == TGT]
|
||||
occurences = [
|
||||
index for index, val in enumerate(text) if val == TGT
|
||||
]
|
||||
for occurence in occurences:
|
||||
if random() < 0.5:
|
||||
text = text[:occurence] + GQM + text[occurence + 1 :]
|
||||
@@ -88,7 +89,9 @@ class MimeHandler:
|
||||
self.fin_mime_data = fin_mime_data
|
||||
self.format_list = format_list
|
||||
self.config_dict = config_dict
|
||||
self.modify_text = enable_ri(config_dict["random_instances"])(self.modify_text)
|
||||
self.modify_text = enable_ri(config_dict["random_instances"])(
|
||||
self.modify_text
|
||||
)
|
||||
|
||||
def restricted_type(self):
|
||||
if not self.format_list:
|
||||
@@ -126,7 +129,9 @@ class MimeHandler:
|
||||
markup = self.mime_data.html()
|
||||
soup = BeautifulSoup(markup, "html.parser")
|
||||
for inner_text in list(soup.strings):
|
||||
inner_text.replace_with(NavigableString(self.modify_text(inner_text)))
|
||||
inner_text.replace_with(
|
||||
NavigableString(self.modify_text(inner_text))
|
||||
)
|
||||
self.fin_mime_data.setHtml(str(soup))
|
||||
self.format_list.remove("text/html")
|
||||
|
||||
@@ -161,7 +166,9 @@ class Clipboard(QObject):
|
||||
mime_data = self.clipboard.mimeData(mode=0)
|
||||
fin_mime_data = QMimeData()
|
||||
format_list = mime_data.formats()
|
||||
mimeobj = MimeHandler(mime_data, fin_mime_data, format_list, self.config_dict)
|
||||
mimeobj = MimeHandler(
|
||||
mime_data, fin_mime_data, format_list, self.config_dict
|
||||
)
|
||||
|
||||
if not mimeobj.restricted_type():
|
||||
if not self.config_dict["plaintext_only"]:
|
||||
@@ -198,10 +205,12 @@ def execute_app(config_dict):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
uid = os.geteuid()
|
||||
pid_path = "/tmp/chaos-{}.pid".format(uid)
|
||||
context = DaemonContext(umask=0o002, pidfile=PidFile(pid_path))
|
||||
# uid = os.geteuid()
|
||||
# pid_path = "/tmp/chaos-{}.pid".format(uid)
|
||||
config_dict = get_config()
|
||||
context = DaemonContext(
|
||||
stdin=sys.stdin, stderr=sys.stderr, stdout=sys.stdout
|
||||
)
|
||||
|
||||
with context:
|
||||
execute_app(config_dict)
|
||||
|
||||
Reference in New Issue
Block a user