94 text = re.sub('[ \t\r]+', '', text) |
98 text = re.sub('[ \t\r]+', '', text) |
95 else: |
99 else: |
96 text = re.sub('[ \t\r]+', ' ', text) |
100 text = re.sub('[ \t\r]+', ' ', text) |
97 text = text.replace(' \n', '\n') |
101 text = text.replace(' \n', '\n') |
98 return text |
102 return text |
|
103 |
|
104 if modulepolicy not in policynocffi: |
|
105 try: |
|
106 from _bdiff_cffi import ffi, lib |
|
107 except ImportError: |
|
108 if modulepolicy == 'cffi': # strict cffi import |
|
109 raise |
|
110 else: |
|
111 def blocks(sa, sb): |
|
112 a = ffi.new("struct bdiff_line**") |
|
113 b = ffi.new("struct bdiff_line**") |
|
114 ac = ffi.new("char[]", sa) |
|
115 bc = ffi.new("char[]", sb) |
|
116 try: |
|
117 an = lib.bdiff_splitlines(ac, len(sa), a) |
|
118 bn = lib.bdiff_splitlines(bc, len(sb), b) |
|
119 if not a[0] or not b[0]: |
|
120 raise MemoryError |
|
121 l = ffi.new("struct bdiff_hunk*") |
|
122 count = lib.bdiff_diff(a[0], an, b[0], bn, l) |
|
123 if count < 0: |
|
124 raise MemoryError |
|
125 rl = [None] * count |
|
126 h = l.next |
|
127 i = 0 |
|
128 while h: |
|
129 rl[i] = (h.a1, h.a2, h.b1, h.b2) |
|
130 h = h.next |
|
131 i += 1 |
|
132 finally: |
|
133 lib.free(a[0]) |
|
134 lib.free(b[0]) |
|
135 lib.bdiff_freehunks(l.next) |
|
136 return rl |