1074 Public method to replicate logic in pep8.py, to know what level to |
1125 Public method to replicate logic in pep8.py, to know what level to |
1075 indent things to. |
1126 indent things to. |
1076 </p><dl> |
1127 </p><dl> |
1077 <dt>Returns:</dt> |
1128 <dt>Returns:</dt> |
1078 <dd> |
1129 <dd> |
1079 list of lists, where each list represents valid indent levels for |
1130 list of lists, where each list represents valid indent levels |
1080 the line in question, relative from the initial indent. However, the |
1131 for the line in question, relative from the initial indent. However, |
1081 first entry is the indent level which was expected. |
1132 the first entry is the indent level which was expected. |
|
1133 </dd> |
|
1134 </dl> |
|
1135 <div align="right"><a href="#top">Up</a></div> |
|
1136 <hr /><hr /> |
|
1137 <a NAME="Pep8LineShortener" ID="Pep8LineShortener"></a> |
|
1138 <h2>Pep8LineShortener</h2> |
|
1139 <p> |
|
1140 Class used to shorten lines to a given maximum of characters. |
|
1141 </p> |
|
1142 <h3>Derived from</h3> |
|
1143 object |
|
1144 <h3>Class Attributes</h3> |
|
1145 <table> |
|
1146 <tr><td>None</td></tr> |
|
1147 </table> |
|
1148 <h3>Class Methods</h3> |
|
1149 <table> |
|
1150 <tr><td>None</td></tr> |
|
1151 </table> |
|
1152 <h3>Methods</h3> |
|
1153 <table> |
|
1154 <tr> |
|
1155 <td><a href="#Pep8LineShortener.__init__">Pep8LineShortener</a></td> |
|
1156 <td>Constructor</td> |
|
1157 </tr><tr> |
|
1158 <td><a href="#Pep8LineShortener.__breakMultiline">__breakMultiline</a></td> |
|
1159 <td>Private method to break multi line strings.</td> |
|
1160 </tr><tr> |
|
1161 <td><a href="#Pep8LineShortener.__checkSyntax">__checkSyntax</a></td> |
|
1162 <td>Private method to check the syntax of the given code fragment.</td> |
|
1163 </tr><tr> |
|
1164 <td><a href="#Pep8LineShortener.__countUnbalancedBrackets">__countUnbalancedBrackets</a></td> |
|
1165 <td>Private method to determine the number of unmatched open/close brackets.</td> |
|
1166 </tr><tr> |
|
1167 <td><a href="#Pep8LineShortener.__getIndent">__getIndent</a></td> |
|
1168 <td>Private method to get the indentation string.</td> |
|
1169 </tr><tr> |
|
1170 <td><a href="#Pep8LineShortener.__isProbablyInsideStringOrComment">__isProbablyInsideStringOrComment</a></td> |
|
1171 <td>Private method to check, if the given string might be inside a string or comment.</td> |
|
1172 </tr><tr> |
|
1173 <td><a href="#Pep8LineShortener.__lineShorteningRank">__lineShorteningRank</a></td> |
|
1174 <td>Private method to rank a candidate.</td> |
|
1175 </tr><tr> |
|
1176 <td><a href="#Pep8LineShortener.__normalizeMultiline">__normalizeMultiline</a></td> |
|
1177 <td>Private method to remove multiline-related code that will cause syntax error.</td> |
|
1178 </tr><tr> |
|
1179 <td><a href="#Pep8LineShortener.__shortenComment">__shortenComment</a></td> |
|
1180 <td>Private method to shorten a comment line.</td> |
|
1181 </tr><tr> |
|
1182 <td><a href="#Pep8LineShortener.__shortenLine">__shortenLine</a></td> |
|
1183 <td>Private method to shorten a line of code at an operator.</td> |
|
1184 </tr><tr> |
|
1185 <td><a href="#Pep8LineShortener.shorten">shorten</a></td> |
|
1186 <td>Public method to shorten the line wrapped by the class instance.</td> |
|
1187 </tr> |
|
1188 </table> |
|
1189 <h3>Static Methods</h3> |
|
1190 <table> |
|
1191 <tr><td>None</td></tr> |
|
1192 </table> |
|
1193 <a NAME="Pep8LineShortener.__init__" ID="Pep8LineShortener.__init__"></a> |
|
1194 <h4>Pep8LineShortener (Constructor)</h4> |
|
1195 <b>Pep8LineShortener</b>(<i>curLine, prevLine, nextLine, maxLength=79, eol="\n", indentWord=" ", isDocString=False</i>) |
|
1196 <p> |
|
1197 Constructor |
|
1198 </p><dl> |
|
1199 <dt><i>curLine</i></dt> |
|
1200 <dd> |
|
1201 text to work on (string) |
|
1202 </dd><dt><i>prevLine</i></dt> |
|
1203 <dd> |
|
1204 line before the text to work on (string) |
|
1205 </dd><dt><i>nextLine</i></dt> |
|
1206 <dd> |
|
1207 line after the text to work on (string) |
|
1208 </dd><dt><i>maxLength=</i></dt> |
|
1209 <dd> |
|
1210 maximum allowed line length (integer) |
|
1211 </dd><dt><i>eol=</i></dt> |
|
1212 <dd> |
|
1213 eond-of-line marker (string) |
|
1214 </dd><dt><i>indentWord=</i></dt> |
|
1215 <dd> |
|
1216 string used for indentation (string) |
|
1217 </dd><dt><i>isDocString=</i></dt> |
|
1218 <dd> |
|
1219 flag indicating that the line belongs to |
|
1220 a documentation string (boolean) |
|
1221 </dd> |
|
1222 </dl><a NAME="Pep8LineShortener.__breakMultiline" ID="Pep8LineShortener.__breakMultiline"></a> |
|
1223 <h4>Pep8LineShortener.__breakMultiline</h4> |
|
1224 <b>__breakMultiline</b>(<i></i>) |
|
1225 <p> |
|
1226 Private method to break multi line strings. |
|
1227 </p><dl> |
|
1228 <dt>Returns:</dt> |
|
1229 <dd> |
|
1230 tuple of the shortened line and the changed next line |
|
1231 (string, string) |
|
1232 </dd> |
|
1233 </dl><a NAME="Pep8LineShortener.__checkSyntax" ID="Pep8LineShortener.__checkSyntax"></a> |
|
1234 <h4>Pep8LineShortener.__checkSyntax</h4> |
|
1235 <b>__checkSyntax</b>(<i>code</i>) |
|
1236 <p> |
|
1237 Private method to check the syntax of the given code fragment. |
|
1238 </p><dl> |
|
1239 <dt><i>code</i></dt> |
|
1240 <dd> |
|
1241 code fragment to check (string) |
|
1242 </dd> |
|
1243 </dl><dl> |
|
1244 <dt>Returns:</dt> |
|
1245 <dd> |
|
1246 flag indicating syntax is ok (boolean) |
|
1247 </dd> |
|
1248 </dl><a NAME="Pep8LineShortener.__countUnbalancedBrackets" ID="Pep8LineShortener.__countUnbalancedBrackets"></a> |
|
1249 <h4>Pep8LineShortener.__countUnbalancedBrackets</h4> |
|
1250 <b>__countUnbalancedBrackets</b>(<i>line</i>) |
|
1251 <p> |
|
1252 Private method to determine the number of unmatched open/close |
|
1253 brackets. |
|
1254 </p><dl> |
|
1255 <dt><i>line</i></dt> |
|
1256 <dd> |
|
1257 line to work at (string) |
|
1258 </dd> |
|
1259 </dl><dl> |
|
1260 <dt>Returns:</dt> |
|
1261 <dd> |
|
1262 number of unmatched open/close brackets (integer) |
|
1263 </dd> |
|
1264 </dl><a NAME="Pep8LineShortener.__getIndent" ID="Pep8LineShortener.__getIndent"></a> |
|
1265 <h4>Pep8LineShortener.__getIndent</h4> |
|
1266 <b>__getIndent</b>(<i>line</i>) |
|
1267 <p> |
|
1268 Private method to get the indentation string. |
|
1269 </p><dl> |
|
1270 <dt><i>line</i></dt> |
|
1271 <dd> |
|
1272 line to determine the indentation string from (string) |
|
1273 </dd> |
|
1274 </dl><dl> |
|
1275 <dt>Returns:</dt> |
|
1276 <dd> |
|
1277 indentation string (string) |
|
1278 </dd> |
|
1279 </dl><a NAME="Pep8LineShortener.__isProbablyInsideStringOrComment" ID="Pep8LineShortener.__isProbablyInsideStringOrComment"></a> |
|
1280 <h4>Pep8LineShortener.__isProbablyInsideStringOrComment</h4> |
|
1281 <b>__isProbablyInsideStringOrComment</b>(<i>line, index</i>) |
|
1282 <p> |
|
1283 Private method to check, if the given string might be inside a string |
|
1284 or comment. |
|
1285 </p><dl> |
|
1286 <dt><i>line</i></dt> |
|
1287 <dd> |
|
1288 line to check (string) |
|
1289 </dd><dt><i>index</i></dt> |
|
1290 <dd> |
|
1291 position inside line to check (integer) |
|
1292 </dd> |
|
1293 </dl><dl> |
|
1294 <dt>Returns:</dt> |
|
1295 <dd> |
|
1296 flag indicating the possibility of being inside a string |
|
1297 or comment |
|
1298 </dd> |
|
1299 </dl><a NAME="Pep8LineShortener.__lineShorteningRank" ID="Pep8LineShortener.__lineShorteningRank"></a> |
|
1300 <h4>Pep8LineShortener.__lineShorteningRank</h4> |
|
1301 <b>__lineShorteningRank</b>(<i>candidate</i>) |
|
1302 <p> |
|
1303 Private method to rank a candidate. |
|
1304 </p><dl> |
|
1305 <dt><i>candidate</i></dt> |
|
1306 <dd> |
|
1307 candidate line to rank (string) |
|
1308 </dd> |
|
1309 </dl><dl> |
|
1310 <dt>Returns:</dt> |
|
1311 <dd> |
|
1312 rank of the candidate (integer) |
|
1313 </dd> |
|
1314 </dl><a NAME="Pep8LineShortener.__normalizeMultiline" ID="Pep8LineShortener.__normalizeMultiline"></a> |
|
1315 <h4>Pep8LineShortener.__normalizeMultiline</h4> |
|
1316 <b>__normalizeMultiline</b>(<i>text</i>) |
|
1317 <p> |
|
1318 Private method to remove multiline-related code that will cause syntax |
|
1319 error. |
|
1320 </p><dl> |
|
1321 <dt><i>line</i></dt> |
|
1322 <dd> |
|
1323 code line to work on (string) |
|
1324 </dd> |
|
1325 </dl><dl> |
|
1326 <dt>Returns:</dt> |
|
1327 <dd> |
|
1328 normalized code line (string) |
|
1329 </dd> |
|
1330 </dl><a NAME="Pep8LineShortener.__shortenComment" ID="Pep8LineShortener.__shortenComment"></a> |
|
1331 <h4>Pep8LineShortener.__shortenComment</h4> |
|
1332 <b>__shortenComment</b>(<i>isLast</i>) |
|
1333 <p> |
|
1334 Private method to shorten a comment line. |
|
1335 </p><dl> |
|
1336 <dt><i>isLast</i></dt> |
|
1337 <dd> |
|
1338 flag indicating, that the line is the last comment line |
|
1339 (boolean) |
|
1340 </dd> |
|
1341 </dl><dl> |
|
1342 <dt>Returns:</dt> |
|
1343 <dd> |
|
1344 shortened comment line (string) |
|
1345 </dd> |
|
1346 </dl><a NAME="Pep8LineShortener.__shortenLine" ID="Pep8LineShortener.__shortenLine"></a> |
|
1347 <h4>Pep8LineShortener.__shortenLine</h4> |
|
1348 <b>__shortenLine</b>(<i>tokens, source, indent</i>) |
|
1349 <p> |
|
1350 Private method to shorten a line of code at an operator. |
|
1351 </p><dl> |
|
1352 <dt><i>tokens</i></dt> |
|
1353 <dd> |
|
1354 tokens of the line as generated by tokenize |
|
1355 (list of token) |
|
1356 </dd><dt><i>source</i></dt> |
|
1357 <dd> |
|
1358 code string to work at (string) |
|
1359 </dd><dt><i>indent</i></dt> |
|
1360 <dd> |
|
1361 indentation string of the code line (string) |
|
1362 </dd> |
|
1363 </dl><dl> |
|
1364 <dt>Returns:</dt> |
|
1365 <dd> |
|
1366 list of candidates (list of string) |
|
1367 </dd> |
|
1368 </dl><a NAME="Pep8LineShortener.shorten" ID="Pep8LineShortener.shorten"></a> |
|
1369 <h4>Pep8LineShortener.shorten</h4> |
|
1370 <b>shorten</b>(<i></i>) |
|
1371 <p> |
|
1372 Public method to shorten the line wrapped by the class instance. |
|
1373 </p><dl> |
|
1374 <dt>Returns:</dt> |
|
1375 <dd> |
|
1376 tuple of a flag indicating successful shortening, the |
|
1377 shortened line and the changed next line (boolean, string, string) |
1082 </dd> |
1378 </dd> |
1083 </dl> |
1379 </dl> |
1084 <div align="right"><a href="#top">Up</a></div> |
1380 <div align="right"><a href="#top">Up</a></div> |
1085 <hr /><hr /> |
1381 <hr /><hr /> |
1086 <a NAME="Pep8Reindenter" ID="Pep8Reindenter"></a> |
1382 <a NAME="Pep8Reindenter" ID="Pep8Reindenter"></a> |
1087 <h2>Pep8Reindenter</h2> |
1383 <h2>Pep8Reindenter</h2> |
1088 <p> |
1384 <p> |
1089 Class to reindent badly-indented code to uniformly use four-space indentation. |
1385 Class to reindent badly-indented code to uniformly use four-space |
|
1386 indentation. |
1090 </p><p> |
1387 </p><p> |
1091 Released to the public domain, by Tim Peters, 03 October 2000. |
1388 Released to the public domain, by Tim Peters, 03 October 2000. |
1092 </p> |
1389 </p> |
1093 <h3>Derived from</h3> |
1390 <h3>Derived from</h3> |
1094 object |
1391 object |