- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18.py
More file actions
Latest commit
57 lines (45 loc) · 1.29 KB
/
Copy path18.py
File metadata and controls
57 lines (45 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
importdifflib
defmain():
left, right=first_step()
diff=second_step(left, right)
third_step(diff)
deffirst_step():
deltas=open("swan/deltas", 'r')
left=""
right=""
whileTrue:
line=deltas.readline()
ifline:
left+=line[:53]
left+="\n"
right+=line[56:]
else:
break
returnleft, right
defsecond_step(left, right):
diff=difflib.ndiff(left.splitlines(keepends=True), right.splitlines(keepends=True))
result="".join(diff)
returnresult
defthird_step(diff):
plus=open("swan/plus.png", "wb")
subtraction=open("swan/subtraction.png", "wb")
space=open("swan/space.png", "wb")
lines=diff.split("\n")
forlineinlines:
iflen(line) >0:
first_byte=line[0]
iffirst_byte=="+":
write_file(plus, line)
eliffirst_byte=="-":
write_file(subtraction, line)
eliffirst_byte==" ":
write_file(space, line)
defwrite_file(file, strings):
sub_strings=strings[2:]
ary=sub_strings.split(" ")
forpointinary:
ifpoint.isalnum():
b=bytes.fromhex(point)
file.write(b)
if__name__=="__main__":
main()