summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-26 11:30:00 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-26 11:30:00 +0200
commit30e0e9f56c874eeca9d6cfe601e525f6235523d5 (patch)
treefef37cc04ba067efb0951620a26542b9e5566b63
parentd6d7f5027434bdf437c4e0778c809ea0dc89582d (diff)
downloadregex-30e0e9f56c874eeca9d6cfe601e525f6235523d5.zip
regex-30e0e9f56c874eeca9d6cfe601e525f6235523d5.tar.bz2
Adds "replacement" option.HEADmaster
-rwxr-xr-xjabberhive-regex.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/jabberhive-regex.py b/jabberhive-regex.py
index 22885dd..4e4e543 100755
--- a/jabberhive-regex.py
+++ b/jabberhive-regex.py
@@ -40,7 +40,17 @@ def client_main (source, params):
if ((valid == 1) and pattern.match(up_data)):
if (t_connect != None):
- t_connect.sendall(in_data)
+ if (params.replacement != None):
+ print("Transformed \"" + up_data + "\"")
+ up_data = re.sub(
+ pattern,
+ params.replacement,
+ up_data
+ )
+ print("into \"" + up_data + "\"")
+ t_connect.sendall(up_data.encode("UTF-8"))
+ else:
+ t_connect.sendall(in_data)
current_target = 't'
state = ClientState.CLIENT_IS_SENDING_UPSTREAM
print("[Matched] Sending upstream...")
@@ -61,7 +71,6 @@ def client_main (source, params):
c = b"\0"
while (c != b"\n"):
- print("67: sending upstream")
if (current_target == 't'):
c = t_connect.recv(1)
else:
@@ -143,6 +152,14 @@ parser.add_argument(
help = 'The regex to test the message against.',
)
+parser.add_argument(
+ '-x',
+ '--replacement',
+ type = str,
+ required = False,
+ help = 'The transformation regex to be applied',
+)
+
args = parser.parse_args()
################################################################################