浏览代码

Split Diff detector methods to class DiffOps

Matthew Wang 11 年前
父节点
当前提交
45b95d6e09
共有 1 个文件被更改,包括 24 次插入25 次删除
  1. 24
    25
      cdiff.py

+ 24
- 25
cdiff.py 查看文件

@@ -119,57 +119,56 @@ class Hunk(object):
119 119
         return out
120 120
 
121 121
 
122
-class Diff(object):
123
-
124
-    def __init__(self, headers, old_path, new_path, hunks):
125
-        self._headers = headers
126
-        self._old_path = old_path
127
-        self._new_path = new_path
128
-        self._hunks = hunks
129
-
130
-    # Following detectors, parse_hunk_meta() and parse_hunk_line() are suppose
131
-    # to be overwritten by derived class.  No is_header() anymore, all
132
-    # non-recognized lines are considered as headers
133
-    #
122
+class DiffOps(object):      # pragma: no cover
123
+    """Methods in this class are supposed to be overwritten by derived class.
124
+    No is_header() anymore, all non-recognized lines are considered as headers
125
+    """
134 126
     def is_old_path(self, line):
135
-        return False        # pragma: no cover
127
+        return False
136 128
 
137 129
     def is_new_path(self, line):
138
-        return False        # pragma: no cover
130
+        return False
139 131
 
140 132
     def is_hunk_meta(self, line):
141
-        return False        # pragma: no cover
133
+        return False
142 134
 
143 135
     def parse_hunk_meta(self, line):
144 136
         """Returns a 2-element tuple, each is a tuple of (start, offset)"""
145
-        return None         # pragma: no cover
137
+        return None
146 138
 
147 139
     def parse_hunk_line(self, line):
148 140
         """Returns a 2-element tuple: (attr, text), where attr is:
149 141
                 '-': old, '+': new, ' ': common
150 142
         """
151
-        return None         # pragma: no cover
143
+        return None
152 144
 
153 145
     def is_old(self, line):
154
-        return False        # pragma: no cover
146
+        return False
155 147
 
156 148
     def is_new(self, line):
157
-        return False        # pragma: no cover
149
+        return False
158 150
 
159 151
     def is_common(self, line):
160
-        return False        # pragma: no cover
152
+        return False
161 153
 
162 154
     def is_eof(self, line):
163
-        return False        # pragma: no cover
155
+        return False
164 156
 
165 157
     def is_only_in_dir(self, line):
166
-        return False        # pragma: no cover
158
+        return False
167 159
 
168 160
     def is_binary_differ(self, line):
169
-        return False        # pragma: no cover
161
+        return False
162
+
163
+
164
+class Diff(DiffOps):
165
+
166
+    def __init__(self, headers, old_path, new_path, hunks):
167
+        self._headers = headers
168
+        self._old_path = old_path
169
+        self._new_path = new_path
170
+        self._hunks = hunks
170 171
 
171
-    # Followings are not suppose to override
172
-    #
173 172
     def markup_traditional(self):
174 173
         """Returns a generator"""
175 174
         for line in self._headers: