Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

final release on chain.py and colordiff.py

  • Loading branch information...
commit 97822d401e02d08ac5427559251ffcdd0328cc4f 1 parent 24feb99
@etheld etheld authored
View
13 coding/chain.py
@@ -19,19 +19,20 @@ def run(self):
if self.verbosity: print(codec.__repr__(), "coder")
print(output)
outputs.append(output)
- output_coder = output
output = self.channel.run(output)
if self.verbosity: print(self.channel.__repr__())
- print(output)
+ print(colordiff.Diff(output,outputs[-1]))
outputs.append(output)
for codec in reversed(self.codecs):
output = codec.decoder(output)
if self.verbosity: print(codec.__repr__(), "decoder")
- #print(output)
+ print(output)
outputs.append(output)
- print("Diffing: ",output_coder,output)
- print(colordiff.Diff(output_coder,output))
if self.verbosity and outputs[0].message != outputs[-1].message:
print("Differs from the original:")
- print(colordiff.Diff(outputs[0], output))
+ print(colordiff.Diff(outputs[0],outputs[-1]))
+
return outputs
+
+
+
View
25 coding/colordiff.py
@@ -3,22 +3,31 @@
red = '\033[31m'
reset = '\033[0m'
def Diff(message1, message2):
- if (type(message1) is base.Message or type(message1) is base.Bits):
+ """Usage: import:
+ from coding import colordiff
+ Then use it colordiff.Diff(text1, text2)
+ text1,text2 parameters can be string, message or bits, otherwise it needs to be cast to string
+ it will print the text1 with the correct markings(green means correct, red means wrong)."""
+ return_text = ""
+ if (type(message1) is base.Message or type(message1) is base.Bits): # convert to string
text1 = message1.message
else:
text1 = message1
- if (type(message2) is base.Message or type(message2) is base.Bits):
+ if (type(message2) is base.Message or type(message2) is base.Bits): # convert to string
text2 = message2.message
else:
text2 = message2
- max = len(text1) if len(text1)>len(text2) else len(text2)
+
+ max = len(text1) if len(text1)>len(text2) else len(text2) # check, which string is the longest
+
for i in range(max):
try:
if text1[i] == text2[i]:
- print (green + text2[i], end = "")
+ return_text += green + text1[i] # green characters are marked with green
else:
- print (red + text2[i], end = "")
- except IndexError:
+ return_text += red + text1[i] # wrong characters are marked with red
+ except IndexError: # catch index error, so it wont stop the program
pass
- print (reset)
- return max
+ return_text += reset # reset the terminal, required to dismiss the effect green/red color on text
+ return "{0}:{1}".format(max, return_text) # return with the specified format
+
View
8 coding/tests/test_colordiff.py
@@ -1,8 +0,0 @@
-#!/usr/bin/env python3
-
-"""Unittest for Colordiff.py"""
-import coding
-from coding import Colordiff
-
-if __name__ == "__main__":
- print (Colordiff.Diff("aa","bb"))
Please sign in to comment.
Something went wrong with that request. Please try again.