62 </table> |
62 </table> |
63 <h3>Methods</h3> |
63 <h3>Methods</h3> |
64 <table> |
64 <table> |
65 <tr> |
65 <tr> |
66 <td><a href="#DiffDialog.__init__">DiffDialog</a></td> |
66 <td><a href="#DiffDialog.__init__">DiffDialog</a></td> |
67 <td>Constructor</td> |
67 <td>Constructor</td> |
68 </tr><tr> |
68 </tr><tr> |
69 <td><a href="#DiffDialog.__appendText">__appendText</a></td> |
69 <td><a href="#DiffDialog.__appendText">__appendText</a></td> |
70 <td>Private method to append text to the end of the contents pane.</td> |
70 <td>Private method to append text to the end of the contents pane.</td> |
71 </tr><tr> |
71 </tr><tr> |
72 <td><a href="#DiffDialog.__fileChanged">__fileChanged</a></td> |
72 <td><a href="#DiffDialog.__fileChanged">__fileChanged</a></td> |
73 <td>Private slot to enable/disable the Compare button.</td> |
73 <td>Private slot to enable/disable the Compare button.</td> |
74 </tr><tr> |
74 </tr><tr> |
75 <td><a href="#DiffDialog.__generateContextDiff">__generateContextDiff</a></td> |
75 <td><a href="#DiffDialog.__generateContextDiff">__generateContextDiff</a></td> |
76 <td>Private slot to generate a context diff output.</td> |
76 <td>Private slot to generate a context diff output.</td> |
77 </tr><tr> |
77 </tr><tr> |
78 <td><a href="#DiffDialog.__generateUnifiedDiff">__generateUnifiedDiff</a></td> |
78 <td><a href="#DiffDialog.__generateUnifiedDiff">__generateUnifiedDiff</a></td> |
79 <td>Private slot to generate a unified diff output.</td> |
79 <td>Private slot to generate a unified diff output.</td> |
80 </tr><tr> |
80 </tr><tr> |
81 <td><a href="#DiffDialog.__selectFile">__selectFile</a></td> |
81 <td><a href="#DiffDialog.__selectFile">__selectFile</a></td> |
82 <td>Private slot to display a file selection dialog.</td> |
82 <td>Private slot to display a file selection dialog.</td> |
83 </tr><tr> |
83 </tr><tr> |
84 <td><a href="#DiffDialog.on_buttonBox_clicked">on_buttonBox_clicked</a></td> |
84 <td><a href="#DiffDialog.on_buttonBox_clicked">on_buttonBox_clicked</a></td> |
85 <td>Private slot called by a button of the button box clicked.</td> |
85 <td>Private slot called by a button of the button box clicked.</td> |
86 </tr><tr> |
86 </tr><tr> |
87 <td><a href="#DiffDialog.on_diffButton_clicked">on_diffButton_clicked</a></td> |
87 <td><a href="#DiffDialog.on_diffButton_clicked">on_diffButton_clicked</a></td> |
88 <td>Private slot to handle the Compare button press.</td> |
88 <td>Private slot to handle the Compare button press.</td> |
89 </tr><tr> |
89 </tr><tr> |
90 <td><a href="#DiffDialog.on_file1Button_clicked">on_file1Button_clicked</a></td> |
90 <td><a href="#DiffDialog.on_file1Button_clicked">on_file1Button_clicked</a></td> |
91 <td>Private slot to handle the file 1 file selection button press.</td> |
91 <td>Private slot to handle the file 1 file selection button press.</td> |
92 </tr><tr> |
92 </tr><tr> |
93 <td><a href="#DiffDialog.on_file2Button_clicked">on_file2Button_clicked</a></td> |
93 <td><a href="#DiffDialog.on_file2Button_clicked">on_file2Button_clicked</a></td> |
94 <td>Private slot to handle the file 2 file selection button press.</td> |
94 <td>Private slot to handle the file 2 file selection button press.</td> |
95 </tr><tr> |
95 </tr><tr> |
96 <td><a href="#DiffDialog.on_saveButton_clicked">on_saveButton_clicked</a></td> |
96 <td><a href="#DiffDialog.on_saveButton_clicked">on_saveButton_clicked</a></td> |
97 <td>Private slot to handle the Save button press.</td> |
97 <td>Private slot to handle the Save button press.</td> |
98 </tr><tr> |
98 </tr><tr> |
99 <td><a href="#DiffDialog.show">show</a></td> |
99 <td><a href="#DiffDialog.show">show</a></td> |
100 <td>Public slot to show the dialog.</td> |
100 <td>Public slot to show the dialog.</td> |
101 </tr> |
101 </tr> |
102 </table> |
102 </table> |
103 <a NAME="DiffDialog.__init__" ID="DiffDialog.__init__"></a> |
103 <a NAME="DiffDialog.__init__" ID="DiffDialog.__init__"></a> |
104 <h4>DiffDialog (Constructor)</h4> |
104 <h4>DiffDialog (Constructor)</h4> |
105 <b>DiffDialog</b>(<i>parent = None</i>) |
105 <b>DiffDialog</b>(<i>parent = None</i>) |
106 <p> |
106 <p> |
107 Constructor |
107 Constructor |
108 </p><a NAME="DiffDialog.__appendText" ID="DiffDialog.__appendText"></a> |
108 </p><a NAME="DiffDialog.__appendText" ID="DiffDialog.__appendText"></a> |
109 <h4>DiffDialog.__appendText</h4> |
109 <h4>DiffDialog.__appendText</h4> |
110 <b>__appendText</b>(<i>txt, format</i>) |
110 <b>__appendText</b>(<i>txt, format</i>) |
111 <p> |
111 <p> |
112 Private method to append text to the end of the contents pane. |
112 Private method to append text to the end of the contents pane. |
113 </p><dl> |
113 </p><dl> |
114 <dt><i>txt</i></dt> |
114 <dt><i>txt</i></dt> |
115 <dd> |
115 <dd> |
116 text to insert (string) |
116 text to insert (string) |
117 </dd><dt><i>format</i></dt> |
117 </dd><dt><i>format</i></dt> |
118 <dd> |
118 <dd> |
119 text format to be used (QTextCharFormat) |
119 text format to be used (QTextCharFormat) |
120 </dd> |
120 </dd> |
121 </dl><a NAME="DiffDialog.__fileChanged" ID="DiffDialog.__fileChanged"></a> |
121 </dl><a NAME="DiffDialog.__fileChanged" ID="DiffDialog.__fileChanged"></a> |
122 <h4>DiffDialog.__fileChanged</h4> |
122 <h4>DiffDialog.__fileChanged</h4> |
123 <b>__fileChanged</b>(<i></i>) |
123 <b>__fileChanged</b>(<i></i>) |
124 <p> |
124 <p> |
125 Private slot to enable/disable the Compare button. |
125 Private slot to enable/disable the Compare button. |
126 </p><a NAME="DiffDialog.__generateContextDiff" ID="DiffDialog.__generateContextDiff"></a> |
126 </p><a NAME="DiffDialog.__generateContextDiff" ID="DiffDialog.__generateContextDiff"></a> |
127 <h4>DiffDialog.__generateContextDiff</h4> |
127 <h4>DiffDialog.__generateContextDiff</h4> |
128 <b>__generateContextDiff</b>(<i>a, b, fromfile, tofile, fromfiledate, tofiledate</i>) |
128 <b>__generateContextDiff</b>(<i>a, b, fromfile, tofile, fromfiledate, tofiledate</i>) |
129 <p> |
129 <p> |
130 Private slot to generate a context diff output. |
130 Private slot to generate a context diff output. |
131 </p><dl> |
131 </p><dl> |
132 <dt><i>a</i></dt> |
132 <dt><i>a</i></dt> |
133 <dd> |
133 <dd> |
134 first sequence of lines (list of strings) |
134 first sequence of lines (list of strings) |
135 </dd><dt><i>b</i></dt> |
135 </dd><dt><i>b</i></dt> |
136 <dd> |
136 <dd> |
137 second sequence of lines (list of strings) |
137 second sequence of lines (list of strings) |
138 </dd><dt><i>fromfile</i></dt> |
138 </dd><dt><i>fromfile</i></dt> |
139 <dd> |
139 <dd> |
140 filename of the first file (string) |
140 filename of the first file (string) |
141 </dd><dt><i>tofile</i></dt> |
141 </dd><dt><i>tofile</i></dt> |
142 <dd> |
142 <dd> |
143 filename of the second file (string) |
143 filename of the second file (string) |
144 </dd><dt><i>fromfiledate</i></dt> |
144 </dd><dt><i>fromfiledate</i></dt> |
145 <dd> |
145 <dd> |
146 modification time of the first file (string) |
146 modification time of the first file (string) |
147 </dd><dt><i>tofiledate</i></dt> |
147 </dd><dt><i>tofiledate</i></dt> |
148 <dd> |
148 <dd> |
149 modification time of the second file (string) |
149 modification time of the second file (string) |
150 </dd> |
150 </dd> |
151 </dl><a NAME="DiffDialog.__generateUnifiedDiff" ID="DiffDialog.__generateUnifiedDiff"></a> |
151 </dl><a NAME="DiffDialog.__generateUnifiedDiff" ID="DiffDialog.__generateUnifiedDiff"></a> |
152 <h4>DiffDialog.__generateUnifiedDiff</h4> |
152 <h4>DiffDialog.__generateUnifiedDiff</h4> |
153 <b>__generateUnifiedDiff</b>(<i>a, b, fromfile, tofile, fromfiledate, tofiledate</i>) |
153 <b>__generateUnifiedDiff</b>(<i>a, b, fromfile, tofile, fromfiledate, tofiledate</i>) |
154 <p> |
154 <p> |
155 Private slot to generate a unified diff output. |
155 Private slot to generate a unified diff output. |
156 </p><dl> |
156 </p><dl> |
157 <dt><i>a</i></dt> |
157 <dt><i>a</i></dt> |
158 <dd> |
158 <dd> |
159 first sequence of lines (list of strings) |
159 first sequence of lines (list of strings) |
160 </dd><dt><i>b</i></dt> |
160 </dd><dt><i>b</i></dt> |
161 <dd> |
161 <dd> |
162 second sequence of lines (list of strings) |
162 second sequence of lines (list of strings) |
163 </dd><dt><i>fromfile</i></dt> |
163 </dd><dt><i>fromfile</i></dt> |
164 <dd> |
164 <dd> |
165 filename of the first file (string) |
165 filename of the first file (string) |
166 </dd><dt><i>tofile</i></dt> |
166 </dd><dt><i>tofile</i></dt> |
167 <dd> |
167 <dd> |
168 filename of the second file (string) |
168 filename of the second file (string) |
169 </dd><dt><i>fromfiledate</i></dt> |
169 </dd><dt><i>fromfiledate</i></dt> |
170 <dd> |
170 <dd> |
171 modification time of the first file (string) |
171 modification time of the first file (string) |
172 </dd><dt><i>tofiledate</i></dt> |
172 </dd><dt><i>tofiledate</i></dt> |
173 <dd> |
173 <dd> |
174 modification time of the second file (string) |
174 modification time of the second file (string) |
175 </dd> |
175 </dd> |
176 </dl><a NAME="DiffDialog.__selectFile" ID="DiffDialog.__selectFile"></a> |
176 </dl><a NAME="DiffDialog.__selectFile" ID="DiffDialog.__selectFile"></a> |
177 <h4>DiffDialog.__selectFile</h4> |
177 <h4>DiffDialog.__selectFile</h4> |
178 <b>__selectFile</b>(<i>lineEdit</i>) |
178 <b>__selectFile</b>(<i>lineEdit</i>) |
179 <p> |
179 <p> |
180 Private slot to display a file selection dialog. |
180 Private slot to display a file selection dialog. |
181 </p><dl> |
181 </p><dl> |
182 <dt><i>lineEdit</i></dt> |
182 <dt><i>lineEdit</i></dt> |
183 <dd> |
183 <dd> |
184 field for the display of the selected filename |
184 field for the display of the selected filename |
185 (QLineEdit) |
185 (QLineEdit) |
186 </dd> |
186 </dd> |
187 </dl><a NAME="DiffDialog.on_buttonBox_clicked" ID="DiffDialog.on_buttonBox_clicked"></a> |
187 </dl><a NAME="DiffDialog.on_buttonBox_clicked" ID="DiffDialog.on_buttonBox_clicked"></a> |
188 <h4>DiffDialog.on_buttonBox_clicked</h4> |
188 <h4>DiffDialog.on_buttonBox_clicked</h4> |
189 <b>on_buttonBox_clicked</b>(<i>button</i>) |
189 <b>on_buttonBox_clicked</b>(<i>button</i>) |
190 <p> |
190 <p> |
191 Private slot called by a button of the button box clicked. |
191 Private slot called by a button of the button box clicked. |
192 </p><dl> |
192 </p><dl> |
193 <dt><i>button</i></dt> |
193 <dt><i>button</i></dt> |
194 <dd> |
194 <dd> |
195 button that was clicked (QAbstractButton) |
195 button that was clicked (QAbstractButton) |
196 </dd> |
196 </dd> |
197 </dl><a NAME="DiffDialog.on_diffButton_clicked" ID="DiffDialog.on_diffButton_clicked"></a> |
197 </dl><a NAME="DiffDialog.on_diffButton_clicked" ID="DiffDialog.on_diffButton_clicked"></a> |
198 <h4>DiffDialog.on_diffButton_clicked</h4> |
198 <h4>DiffDialog.on_diffButton_clicked</h4> |
199 <b>on_diffButton_clicked</b>(<i></i>) |
199 <b>on_diffButton_clicked</b>(<i></i>) |
200 <p> |
200 <p> |
201 Private slot to handle the Compare button press. |
201 Private slot to handle the Compare button press. |
202 </p><a NAME="DiffDialog.on_file1Button_clicked" ID="DiffDialog.on_file1Button_clicked"></a> |
202 </p><a NAME="DiffDialog.on_file1Button_clicked" ID="DiffDialog.on_file1Button_clicked"></a> |
203 <h4>DiffDialog.on_file1Button_clicked</h4> |
203 <h4>DiffDialog.on_file1Button_clicked</h4> |
204 <b>on_file1Button_clicked</b>(<i></i>) |
204 <b>on_file1Button_clicked</b>(<i></i>) |
205 <p> |
205 <p> |
206 Private slot to handle the file 1 file selection button press. |
206 Private slot to handle the file 1 file selection button press. |
207 </p><a NAME="DiffDialog.on_file2Button_clicked" ID="DiffDialog.on_file2Button_clicked"></a> |
207 </p><a NAME="DiffDialog.on_file2Button_clicked" ID="DiffDialog.on_file2Button_clicked"></a> |
208 <h4>DiffDialog.on_file2Button_clicked</h4> |
208 <h4>DiffDialog.on_file2Button_clicked</h4> |
209 <b>on_file2Button_clicked</b>(<i></i>) |
209 <b>on_file2Button_clicked</b>(<i></i>) |
210 <p> |
210 <p> |
211 Private slot to handle the file 2 file selection button press. |
211 Private slot to handle the file 2 file selection button press. |
212 </p><a NAME="DiffDialog.on_saveButton_clicked" ID="DiffDialog.on_saveButton_clicked"></a> |
212 </p><a NAME="DiffDialog.on_saveButton_clicked" ID="DiffDialog.on_saveButton_clicked"></a> |
213 <h4>DiffDialog.on_saveButton_clicked</h4> |
213 <h4>DiffDialog.on_saveButton_clicked</h4> |
214 <b>on_saveButton_clicked</b>(<i></i>) |
214 <b>on_saveButton_clicked</b>(<i></i>) |
215 <p> |
215 <p> |
216 Private slot to handle the Save button press. |
216 Private slot to handle the Save button press. |
217 </p><p> |
217 </p><p> |
218 It saves the diff shown in the dialog to a file in the local |
218 It saves the diff shown in the dialog to a file in the local |
219 filesystem. |
219 filesystem. |
220 </p><a NAME="DiffDialog.show" ID="DiffDialog.show"></a> |
220 </p><a NAME="DiffDialog.show" ID="DiffDialog.show"></a> |
221 <h4>DiffDialog.show</h4> |
221 <h4>DiffDialog.show</h4> |
222 <b>show</b>(<i>filename = None</i>) |
222 <b>show</b>(<i>filename = None</i>) |
223 <p> |
223 <p> |
224 Public slot to show the dialog. |
224 Public slot to show the dialog. |
225 </p><dl> |
225 </p><dl> |
226 <dt><i>filename</i></dt> |
226 <dt><i>filename</i></dt> |
227 <dd> |
227 <dd> |
228 name of a file to use as the first file (string) |
228 name of a file to use as the first file (string) |
229 </dd> |
229 </dd> |
230 </dl> |
230 </dl> |
231 <div align="right"><a href="#top">Up</a></div> |
231 <div align="right"><a href="#top">Up</a></div> |
232 <hr /><hr /> |
232 <hr /><hr /> |
233 <a NAME="DiffWindow" ID="DiffWindow"></a> |
233 <a NAME="DiffWindow" ID="DiffWindow"></a> |
234 <h2>DiffWindow</h2> |
234 <h2>DiffWindow</h2> |
235 <p> |
235 <p> |
236 Main window class for the standalone dialog. |
236 Main window class for the standalone dialog. |
237 </p> |
237 </p> |
238 <h3>Derived from</h3> |
238 <h3>Derived from</h3> |
239 QMainWindow |
239 QMainWindow |
240 <h3>Class Attributes</h3> |
240 <h3>Class Attributes</h3> |
241 <table> |
241 <table> |
243 </table> |
243 </table> |
244 <h3>Methods</h3> |
244 <h3>Methods</h3> |
245 <table> |
245 <table> |
246 <tr> |
246 <tr> |
247 <td><a href="#DiffWindow.__init__">DiffWindow</a></td> |
247 <td><a href="#DiffWindow.__init__">DiffWindow</a></td> |
248 <td>Constructor</td> |
248 <td>Constructor</td> |
249 </tr><tr> |
249 </tr><tr> |
250 <td><a href="#DiffWindow.eventFilter">eventFilter</a></td> |
250 <td><a href="#DiffWindow.eventFilter">eventFilter</a></td> |
251 <td>Public method to filter events.</td> |
251 <td>Public method to filter events.</td> |
252 </tr> |
252 </tr> |
253 </table> |
253 </table> |
254 <a NAME="DiffWindow.__init__" ID="DiffWindow.__init__"></a> |
254 <a NAME="DiffWindow.__init__" ID="DiffWindow.__init__"></a> |
255 <h4>DiffWindow (Constructor)</h4> |
255 <h4>DiffWindow (Constructor)</h4> |
256 <b>DiffWindow</b>(<i>parent = None</i>) |
256 <b>DiffWindow</b>(<i>parent = None</i>) |
257 <p> |
257 <p> |
258 Constructor |
258 Constructor |
259 </p><dl> |
259 </p><dl> |
260 <dt><i>parent</i></dt> |
260 <dt><i>parent</i></dt> |
261 <dd> |
261 <dd> |
262 reference to the parent widget (QWidget) |
262 reference to the parent widget (QWidget) |
263 </dd> |
263 </dd> |
264 </dl><a NAME="DiffWindow.eventFilter" ID="DiffWindow.eventFilter"></a> |
264 </dl><a NAME="DiffWindow.eventFilter" ID="DiffWindow.eventFilter"></a> |
265 <h4>DiffWindow.eventFilter</h4> |
265 <h4>DiffWindow.eventFilter</h4> |
266 <b>eventFilter</b>(<i>obj, event</i>) |
266 <b>eventFilter</b>(<i>obj, event</i>) |
267 <p> |
267 <p> |
268 Public method to filter events. |
268 Public method to filter events. |
269 </p><dl> |
269 </p><dl> |
270 <dt><i>obj</i></dt> |
270 <dt><i>obj</i></dt> |
271 <dd> |
271 <dd> |
272 reference to the object the event is meant for (QObject) |
272 reference to the object the event is meant for (QObject) |
273 </dd><dt><i>event</i></dt> |
273 </dd><dt><i>event</i></dt> |
274 <dd> |
274 <dd> |
275 reference to the event object (QEvent) |
275 reference to the event object (QEvent) |
276 </dd> |
276 </dd> |
277 </dl><dl> |
277 </dl><dl> |
278 <dt>Returns:</dt> |
278 <dt>Returns:</dt> |
279 <dd> |
279 <dd> |
280 flag indicating, whether the event was handled (boolean) |
280 flag indicating, whether the event was handled (boolean) |
281 </dd> |
281 </dd> |
282 </dl> |
282 </dl> |
283 <div align="right"><a href="#top">Up</a></div> |
283 <div align="right"><a href="#top">Up</a></div> |
284 <hr /><hr /> |
284 <hr /><hr /> |
285 <a NAME="context_diff" ID="context_diff"></a> |
285 <a NAME="context_diff" ID="context_diff"></a> |
286 <h2>context_diff</h2> |
286 <h2>context_diff</h2> |
287 <b>context_diff</b>(<i>a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'</i>) |
287 <b>context_diff</b>(<i>a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'</i>) |
288 <p> |
288 <p> |
289 Compare two sequences of lines; generate the delta as a context diff. |
289 Compare two sequences of lines; generate the delta as a context diff. |
290 </p><p> |
290 </p><p> |
291 Context diffs are a compact way of showing line changes and a few |
291 Context diffs are a compact way of showing line changes and a few |
292 lines of context. The number of context lines is set by 'n' which |
292 lines of context. The number of context lines is set by 'n' which |
293 defaults to three. |
293 defaults to three. |
294 </p><p> |
294 </p><p> |
295 By default, the diff control lines (those with *** or ---) are |
295 By default, the diff control lines (those with *** or ---) are |
296 created with a trailing newline. This is helpful so that inputs |
296 created with a trailing newline. This is helpful so that inputs |
297 created from file.readlines() result in diffs that are suitable for |
297 created from file.readlines() result in diffs that are suitable for |
298 file.writelines() since both the inputs and outputs have trailing |
298 file.writelines() since both the inputs and outputs have trailing |
299 newlines. |
299 newlines. |
300 </p><p> |
300 </p><p> |
301 For inputs that do not have trailing newlines, set the lineterm |
301 For inputs that do not have trailing newlines, set the lineterm |
302 argument to "" so that the output will be uniformly newline free. |
302 argument to "" so that the output will be uniformly newline free. |
303 </p><p> |
303 </p><p> |
304 The context diff format normally has a header for filenames and |
304 The context diff format normally has a header for filenames and |
305 modification times. Any or all of these may be specified using |
305 modification times. Any or all of these may be specified using |
306 strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. |
306 strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. |
307 The modification times are normally expressed in the format returned |
307 The modification times are normally expressed in the format returned |
308 by time.ctime(). If not specified, the strings default to blanks. |
308 by time.ctime(). If not specified, the strings default to blanks. |
309 </p><p> |
309 </p><p> |
310 Example: |
310 Example: |
311 </p><p> |
311 </p><p> |
312 <pre> |
312 <pre> |
313 &gt;&gt;&gt; print ''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(1), |
313 >>> print ''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(1), |
314 ... 'zero\none\ntree\nfour\n'.splitlines(1), 'Original', 'Current', |
314 ... 'zero\none\ntree\nfour\n'.splitlines(1), 'Original', 'Current', |
315 ... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:22:46 2003')), |
315 ... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:22:46 2003')), |
316 *** Original Sat Jan 26 23:30:50 1991 |
316 *** Original Sat Jan 26 23:30:50 1991 |
317 --- Current Fri Jun 06 10:22:46 2003 |
317 --- Current Fri Jun 06 10:22:46 2003 |
318 *************** |
318 *************** |
319 *** 1,4 **** |
319 *** 1,4 **** |
320 one |
320 one |
321 ! two |
321 ! two |
322 ! three |
322 ! three |
323 four |
323 four |
324 --- 1,4 ---- |
324 --- 1,4 ---- |
325 + zero |
325 + zero |
326 one |
326 one |
327 ! tree |
327 ! tree |
328 four |
328 four |
329 </pre> |
329 </pre> |
330 </p><dl> |
330 </p><dl> |
331 <dt><i>a</i></dt> |
331 <dt><i>a</i></dt> |
332 <dd> |
332 <dd> |
333 first sequence of lines (list of strings) |
333 first sequence of lines (list of strings) |
334 </dd><dt><i>b</i></dt> |
334 </dd><dt><i>b</i></dt> |
335 <dd> |
335 <dd> |
336 second sequence of lines (list of strings) |
336 second sequence of lines (list of strings) |
337 </dd><dt><i>fromfile</i></dt> |
337 </dd><dt><i>fromfile</i></dt> |
338 <dd> |
338 <dd> |
339 filename of the first file (string) |
339 filename of the first file (string) |
340 </dd><dt><i>tofile</i></dt> |
340 </dd><dt><i>tofile</i></dt> |
341 <dd> |
341 <dd> |
342 filename of the second file (string) |
342 filename of the second file (string) |
343 </dd><dt><i>fromfiledate</i></dt> |
343 </dd><dt><i>fromfiledate</i></dt> |
344 <dd> |
344 <dd> |
345 modification time of the first file (string) |
345 modification time of the first file (string) |
346 </dd><dt><i>tofiledate</i></dt> |
346 </dd><dt><i>tofiledate</i></dt> |
347 <dd> |
347 <dd> |
348 modification time of the second file (string) |
348 modification time of the second file (string) |
349 </dd><dt><i>n</i></dt> |
349 </dd><dt><i>n</i></dt> |
350 <dd> |
350 <dd> |
351 number of lines of context (integer) |
351 number of lines of context (integer) |
352 </dd><dt><i>lineterm</i></dt> |
352 </dd><dt><i>lineterm</i></dt> |
353 <dd> |
353 <dd> |
354 line termination string (string) |
354 line termination string (string) |
355 </dd> |
355 </dd> |
356 </dl><dl> |
356 </dl><dl> |
357 <dt>Returns:</dt> |
357 <dt>Returns:</dt> |
358 <dd> |
358 <dd> |
359 a generator yielding lines of differences |
359 a generator yielding lines of differences |
360 </dd> |
360 </dd> |
361 </dl> |
361 </dl> |
362 <div align="right"><a href="#top">Up</a></div> |
362 <div align="right"><a href="#top">Up</a></div> |
363 <hr /><hr /> |
363 <hr /><hr /> |
364 <a NAME="unified_diff" ID="unified_diff"></a> |
364 <a NAME="unified_diff" ID="unified_diff"></a> |
365 <h2>unified_diff</h2> |
365 <h2>unified_diff</h2> |
366 <b>unified_diff</b>(<i>a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'</i>) |
366 <b>unified_diff</b>(<i>a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'</i>) |
367 <p> |
367 <p> |
368 Compare two sequences of lines; generate the delta as a unified diff. |
368 Compare two sequences of lines; generate the delta as a unified diff. |
369 </p><p> |
369 </p><p> |
370 Unified diffs are a compact way of showing line changes and a few |
370 Unified diffs are a compact way of showing line changes and a few |
371 lines of context. The number of context lines is set by 'n' which |
371 lines of context. The number of context lines is set by 'n' which |
372 defaults to three. |
372 defaults to three. |
373 </p><p> |
373 </p><p> |
374 By default, the diff control lines (those with ---, +++, or @@) are |
374 By default, the diff control lines (those with ---, +++, or @@) are |
375 created with a trailing newline. This is helpful so that inputs |
375 created with a trailing newline. This is helpful so that inputs |
376 created from file.readlines() result in diffs that are suitable for |
376 created from file.readlines() result in diffs that are suitable for |
377 file.writelines() since both the inputs and outputs have trailing |
377 file.writelines() since both the inputs and outputs have trailing |
378 newlines. |
378 newlines. |
379 </p><p> |
379 </p><p> |
380 For inputs that do not have trailing newlines, set the lineterm |
380 For inputs that do not have trailing newlines, set the lineterm |
381 argument to "" so that the output will be uniformly newline free. |
381 argument to "" so that the output will be uniformly newline free. |
382 </p><p> |
382 </p><p> |
383 The unidiff format normally has a header for filenames and modification |
383 The unidiff format normally has a header for filenames and modification |
384 times. Any or all of these may be specified using strings for |
384 times. Any or all of these may be specified using strings for |
385 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification |
385 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification |
386 times are normally expressed in the format returned by time.ctime(). |
386 times are normally expressed in the format returned by time.ctime(). |
387 </p><p> |
387 </p><p> |
388 Example: |
388 Example: |
389 </p><p> |
389 </p><p> |
390 <pre> |
390 <pre> |
391 &gt;&gt;&gt; for line in unified_diff('one two three four'.split(), |
391 >>> for line in unified_diff('one two three four'.split(), |
392 ... 'zero one tree four'.split(), 'Original', 'Current', |
392 ... 'zero one tree four'.split(), 'Original', 'Current', |
393 ... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:20:52 2003', |
393 ... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:20:52 2003', |
394 ... lineterm=''): |
394 ... lineterm=''): |
395 ... print line |
395 ... print line |
396 --- Original Sat Jan 26 23:30:50 1991 |
396 --- Original Sat Jan 26 23:30:50 1991 |
397 +++ Current Fri Jun 06 10:20:52 2003 |
397 +++ Current Fri Jun 06 10:20:52 2003 |
398 @ -1,4 +1,4 @@ |
398 @ -1,4 +1,4 @@ |
399 +zero |
399 +zero |
400 one |
400 one |
401 -two |
401 -two |
402 -three |
402 -three |
403 +tree |
403 +tree |
404 four |
404 four |
405 </pre> |
405 </pre> |
406 </p><dl> |
406 </p><dl> |
407 <dt><i>a</i></dt> |
407 <dt><i>a</i></dt> |
408 <dd> |
408 <dd> |
409 first sequence of lines (list of strings) |
409 first sequence of lines (list of strings) |
410 </dd><dt><i>b</i></dt> |
410 </dd><dt><i>b</i></dt> |
411 <dd> |
411 <dd> |
412 second sequence of lines (list of strings) |
412 second sequence of lines (list of strings) |
413 </dd><dt><i>fromfile</i></dt> |
413 </dd><dt><i>fromfile</i></dt> |
414 <dd> |
414 <dd> |
415 filename of the first file (string) |
415 filename of the first file (string) |
416 </dd><dt><i>tofile</i></dt> |
416 </dd><dt><i>tofile</i></dt> |
417 <dd> |
417 <dd> |
418 filename of the second file (string) |
418 filename of the second file (string) |
419 </dd><dt><i>fromfiledate</i></dt> |
419 </dd><dt><i>fromfiledate</i></dt> |
420 <dd> |
420 <dd> |
421 modification time of the first file (string) |
421 modification time of the first file (string) |
422 </dd><dt><i>tofiledate</i></dt> |
422 </dd><dt><i>tofiledate</i></dt> |
423 <dd> |
423 <dd> |
424 modification time of the second file (string) |
424 modification time of the second file (string) |
425 </dd><dt><i>n</i></dt> |
425 </dd><dt><i>n</i></dt> |
426 <dd> |
426 <dd> |
427 number of lines of context (integer) |
427 number of lines of context (integer) |
428 </dd><dt><i>lineterm</i></dt> |
428 </dd><dt><i>lineterm</i></dt> |
429 <dd> |
429 <dd> |
430 line termination string (string) |
430 line termination string (string) |
431 </dd> |
431 </dd> |
432 </dl><dl> |
432 </dl><dl> |
433 <dt>Returns:</dt> |
433 <dt>Returns:</dt> |
434 <dd> |
434 <dd> |
435 a generator yielding lines of differences |
435 a generator yielding lines of differences |
436 </dd> |
436 </dd> |
437 </dl> |
437 </dl> |
438 <div align="right"><a href="#top">Up</a></div> |
438 <div align="right"><a href="#top">Up</a></div> |
439 <hr /> |
439 <hr /> |
440 </body></html> |
440 </body></html> |