Skip to content
Snippets Groups Projects
Commit fab3c9a0 authored by Teena Hassan's avatar Teena Hassan
Browse files

Ported ipaaca-iu-injector and ipaaca-iu-sniffer scripts to Python3

parent b59f0e38
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
# Forschungsgemeinschaft (DFG) in the context of the German # Forschungsgemeinschaft (DFG) in the context of the German
# Excellence Initiative. # Excellence Initiative.
from __future__ import division, print_function #from __future__ import division, print_function
import itertools import itertools
import os import os
...@@ -44,7 +44,7 @@ import ipaaca ...@@ -44,7 +44,7 @@ import ipaaca
def iu_update_handler(iu, event_type, local): def iu_update_handler(iu, event_type, local):
try: try:
print(event_type + ': ' + unicode(iu)) print(event_type + ': ' + str(iu))
except: except:
print(u"An error occurred printing an IU for an event of type "+event_type) print(u"An error occurred printing an IU for an event of type "+event_type)
...@@ -93,9 +93,9 @@ if __name__ == '__main__': ...@@ -93,9 +93,9 @@ if __name__ == '__main__':
iu = ipaaca.Message(arguments.category) if arguments.iu_type == 'Message' else ipaaca.IU(arguments.category) iu = ipaaca.Message(arguments.category) if arguments.iu_type == 'Message' else ipaaca.IU(arguments.category)
if arguments.json_payload: if arguments.json_payload:
# Treat payload values as Python expressions # Treat payload values as Python expressions
iu.payload = {k: eval(v) for (k, v) in itertools.izip_longest(arguments.payload[::2], arguments.payload[1::2])} iu.payload = {k: eval(v) for (k, v) in itertools.zip_longest(arguments.payload[::2], arguments.payload[1::2])}
else: else:
iu.payload = {k: v for (k, v) in itertools.izip_longest(arguments.payload[::2], arguments.payload[1::2])} iu.payload = {k: v for (k, v) in itertools.zip_longest(arguments.payload[::2], arguments.payload[1::2])}
ob.add(iu) ob.add(iu)
print( print(
...@@ -114,7 +114,7 @@ if __name__ == '__main__': ...@@ -114,7 +114,7 @@ if __name__ == '__main__':
time.sleep(0.1) time.sleep(0.1)
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
except Exception, e: except Exception as e:
print(u'Exception: '+unicode(traceback.format_exc())) print(u'Exception: '+str(traceback.format_exc()))
ipaaca.exit(1) ipaaca.exit(1)
ipaaca.exit(0) ipaaca.exit(0)
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
# Forschungsgemeinschaft (DFG) in the context of the German # Forschungsgemeinschaft (DFG) in the context of the German
# Excellence Initiative. # Excellence Initiative.
from __future__ import division, print_function #from __future__ import division, print_function
import logging import logging
import os import os
...@@ -61,13 +61,13 @@ def highlight_if_color(s, c='1'): ...@@ -61,13 +61,13 @@ def highlight_if_color(s, c='1'):
def pretty_printed_dict(d): def pretty_printed_dict(d):
s='{\n' s='{\n'
for k, v in d.items(): for k, v in d.items():
if isinstance(v, unicode) or isinstance(v, str): if isinstance(v, str) or isinstance(v, str):
v = "'"+unicode(v)+"'" v = "'"+str(v)+"'"
else: else:
v = unicode(v) v = str(v)
v2 = v if len(v) <= arguments.max_size else v[:arguments.max_size] + '<excess length omitted>' v2 = v if len(v) <= arguments.max_size else v[:arguments.max_size] + '<excess length omitted>'
v2.replace('\\','\\\\').replace('\n', highlight_if_color('\\n')) v2.replace('\\','\\\\').replace('\n', highlight_if_color('\\n'))
s += "\t '%s': %s,\n" % (highlight_if_color(unicode(k),'1'), unicode(v2)) s += "\t '%s': %s,\n" % (highlight_if_color(str(k),'1'), str(v2))
s+='}' s+='}'
return s return s
...@@ -200,7 +200,7 @@ if __name__ == '__main__': ...@@ -200,7 +200,7 @@ if __name__ == '__main__':
time.sleep(1) time.sleep(1)
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
except Exception, e: except Exception as e:
print(u'Exception: '+unicode(traceback.format_exc())) print(u'Exception: '+str(traceback.format_exc()))
ipaaca.exit(1) ipaaca.exit(1)
ipaaca.exit(0) ipaaca.exit(0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment