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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620
|
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>API Reference (in progress) — Python-Future documentation</title>
<link rel="stylesheet" href="_static/basic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/my-styles.css" type="text/css" />
<link rel="stylesheet" href="_static/bootswatch-3.3.4/cerulean/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="_static/bootstrap-sphinx.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="_static/js/jquery-fix.js"></script>
<script type="text/javascript" src="_static/bootstrap-3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src="_static/bootstrap-sphinx.js"></script>
<link rel="shortcut icon" href="_static/python-future-icon-32.ico"/>
<link rel="top" title="Python-Future documentation" href="index.html" />
<link rel="prev" title="Licensing and credits" href="credits.html" />
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1'>
<meta name="apple-mobile-web-app-capable" content="yes">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-19344199-2']);
_gaq.push(['_trackPageview']);
</script>
</head>
<body role="document">
<a href="https://github.com/PythonCharmers/python-future"><img style="position: absolute; top: 45px; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub"></a>
<div id="navbar" class="navbar navbar-inverse navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="logo"> <img height="32" width="32" src="_static/python-future-logo-textless-transparent.png" /></a>
<a class="navbar-brand" href="index.html">Python-Future</a>
<span class="navbar-text navbar-version pull-left"><b></b></span>
</div>
<div class="collapse navbar-collapse nav-collapse">
<ul class="nav navbar-nav">
<li class="divider-vertical"></li>
<li><a href="overview.html">Overview</a></li>
<li><a href="compatible_idioms.html">Cheat Sheet</a></li>
<li><a href="faq.html">FAQ</a></li>
<li class="dropdown globaltoc-container">
<a role="button"
id="dLabelGlobalToc"
data-toggle="dropdown"
data-target="#"
href="index.html">Contents <b class="caret"></b></a>
<ul class="dropdown-menu globaltoc"
role="menu"
aria-labelledby="dLabelGlobalToc"><ul class="current">
<li class="toctree-l1"><a class="reference internal" href="whatsnew.html">What’s New</a><ul>
<li class="toctree-l2"><a class="reference internal" href="whatsnew.html#what-s-new-in-version-0-15-0-2015-07-25">What’s new in version 0.15.0 (2015-07-25)</a></li>
<li class="toctree-l2"><a class="reference internal" href="whatsnew.html#what-s-new-in-version-0-14-3-2014-12-15">What’s new in version 0.14.3 (2014-12-15)</a></li>
<li class="toctree-l2"><a class="reference internal" href="whatsnew.html#what-s-new-in-version-0-14-2-2014-11-21">What’s new in version 0.14.2 (2014-11-21)</a></li>
<li class="toctree-l2"><a class="reference internal" href="whatsnew.html#what-s-new-in-version-0-14-1-2014-10-02">What’s new in version 0.14.1 (2014-10-02)</a></li>
<li class="toctree-l2"><a class="reference internal" href="whatsnew.html#what-s-new-in-version-0-14-2014-10-02">What’s new in version 0.14 (2014-10-02)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="whatsnew.html#bug-fixes">Bug fixes</a></li>
<li class="toctree-l3"><a class="reference internal" href="whatsnew.html#internal-cleanups">Internal cleanups</a></li>
<li class="toctree-l3"><a class="reference internal" href="whatsnew.html#deprecations">Deprecations</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="whatsnew.html#previous-versions">Previous versions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="overview.html">Overview: Easy, clean, reliable Python 2/3 compatibility</a><ul>
<li class="toctree-l2"><a class="reference internal" href="overview.html#features">Features</a></li>
<li class="toctree-l2"><a class="reference internal" href="overview.html#code-examples">Code examples</a></li>
<li class="toctree-l2"><a class="reference internal" href="overview.html#automatic-conversion-to-py2-3-compatible-code">Automatic conversion to Py2/3-compatible code</a><ul>
<li class="toctree-l3"><a class="reference internal" href="overview.html#futurize-2-to-both">Futurize: 2 to both</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="overview.html#automatic-translation">Automatic translation</a></li>
<li class="toctree-l2"><a class="reference internal" href="overview.html#licensing">Licensing</a></li>
<li class="toctree-l2"><a class="reference internal" href="overview.html#next-steps">Next steps</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="quickstart.html">Quick-start guide</a><ul>
<li class="toctree-l2"><a class="reference internal" href="quickstart.html#installation">Installation</a></li>
<li class="toctree-l2"><a class="reference internal" href="quickstart.html#if-you-are-writing-code-from-scratch">If you are writing code from scratch</a></li>
<li class="toctree-l2"><a class="reference internal" href="quickstart.html#to-convert-existing-python-3-code">To convert existing Python 3 code</a></li>
<li class="toctree-l2"><a class="reference internal" href="quickstart.html#to-convert-existing-python-2-code">To convert existing Python 2 code</a></li>
<li class="toctree-l2"><a class="reference internal" href="quickstart.html#standard-library-reorganization">Standard library reorganization</a></li>
<li class="toctree-l2"><a class="reference internal" href="quickstart.html#python-2-only-dependencies">Python 2-only dependencies</a></li>
<li class="toctree-l2"><a class="reference internal" href="quickstart.html#next-steps">Next steps</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="compatible_idioms.html">Cheat Sheet: Writing Python 2-3 compatible code</a><ul>
<li class="toctree-l2"><a class="reference internal" href="compatible_idioms.html#setup">Setup</a></li>
<li class="toctree-l2"><a class="reference internal" href="compatible_idioms.html#essential-syntax-differences">Essential syntax differences</a><ul>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#print">print</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#raising-exceptions">Raising exceptions</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#catching-exceptions">Catching exceptions</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#division">Division</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#long-integers">Long integers</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#octal-constants">Octal constants</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#backtick-repr">Backtick repr</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#metaclasses">Metaclasses</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="compatible_idioms.html#strings-and-bytes">Strings and bytes</a><ul>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#unicode-text-string-literals">Unicode (text) string literals</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#byte-string-literals">Byte-string literals</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#basestring">basestring</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#unicode">unicode</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#stringio">StringIO</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="compatible_idioms.html#imports-relative-to-a-package">Imports relative to a package</a></li>
<li class="toctree-l2"><a class="reference internal" href="compatible_idioms.html#dictionaries">Dictionaries</a><ul>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#iterating-through-dict-keys-values-items">Iterating through <code class="docutils literal"><span class="pre">dict</span></code> keys/values/items</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#dict-keys-values-items-as-a-list">dict keys/values/items as a list</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="compatible_idioms.html#custom-class-behaviour">Custom class behaviour</a><ul>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#custom-iterators">Custom iterators</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#custom-str-methods">Custom <code class="docutils literal"><span class="pre">__str__</span></code> methods</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#custom-nonzero-vs-bool-method">Custom <code class="docutils literal"><span class="pre">__nonzero__</span></code> vs <code class="docutils literal"><span class="pre">__bool__</span></code> method:</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="compatible_idioms.html#lists-versus-iterators">Lists versus iterators</a><ul>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#xrange">xrange</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#range">range</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#map">map</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#imap">imap</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#zip-izip">zip, izip</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#filter-ifilter">filter, ifilter</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="compatible_idioms.html#other-builtins">Other builtins</a><ul>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#file-io-with-open">File IO with open()</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#reduce">reduce()</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#raw-input">raw_input()</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#input">input()</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#file">file()</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#execfile">execfile()</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#unichr">unichr()</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#intern">intern()</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#apply">apply()</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#chr">chr()</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#cmp">cmp()</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#reload">reload()</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="compatible_idioms.html#standard-library">Standard library</a><ul>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#dbm-modules">dbm modules</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#commands-subprocess-modules">commands / subprocess modules</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#subprocess-check-output">subprocess.check_output()</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#collections-counter-and-ordereddict">collections: Counter and OrderedDict</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#stringio-module">StringIO module</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#http-module">http module</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#xmlrpc-module">xmlrpc module</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#html-escaping-and-entities">html escaping and entities</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#html-parsing">html parsing</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#urllib-module">urllib module</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#tkinter">Tkinter</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#socketserver">socketserver</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#copy-reg-copyreg">copy_reg, copyreg</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#configparser">configparser</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#queue">queue</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#repr-reprlib">repr, reprlib</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#userdict-userlist-userstring">UserDict, UserList, UserString</a></li>
<li class="toctree-l3"><a class="reference internal" href="compatible_idioms.html#itertools-filterfalse-zip-longest">itertools: filterfalse, zip_longest</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="imports.html">Imports</a><ul>
<li class="toctree-l2"><a class="reference internal" href="imports.html#future-imports">__future__ imports</a></li>
<li class="toctree-l2"><a class="reference internal" href="imports.html#imports-of-builtins">Imports of builtins</a><ul>
<li class="toctree-l3"><a class="reference internal" href="imports.html#implicit-imports">Implicit imports</a></li>
<li class="toctree-l3"><a class="reference internal" href="imports.html#explicit-imports">Explicit imports</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="imports.html#standard-library-imports">Standard library imports</a><ul>
<li class="toctree-l3"><a class="reference internal" href="imports.html#direct-imports">Direct imports</a></li>
<li class="toctree-l3"><a class="reference internal" href="imports.html#aliased-imports">Aliased imports</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="imports.html#external-standard-library-backports">External standard-library backports</a></li>
<li class="toctree-l2"><a class="reference internal" href="imports.html#included-full-backports">Included full backports</a></li>
<li class="toctree-l2"><a class="reference internal" href="imports.html#using-python-2-only-dependencies-on-python-3">Using Python 2-only dependencies on Python 3</a></li>
<li class="toctree-l2"><a class="reference internal" href="imports.html#should-i-import-unicode-literals">Should I import unicode_literals?</a><ul>
<li class="toctree-l3"><a class="reference internal" href="imports.html#benefits">Benefits</a></li>
<li class="toctree-l3"><a class="reference internal" href="imports.html#drawbacks">Drawbacks</a></li>
<li class="toctree-l3"><a class="reference internal" href="imports.html#others-perspectives">Others’ perspectives</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="imports.html#next-steps">Next steps</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="what_else.html">What else you need to know</a><ul>
<li class="toctree-l2"><a class="reference internal" href="what_else.html#bytes">bytes</a></li>
<li class="toctree-l2"><a class="reference internal" href="what_else.html#str">str</a></li>
<li class="toctree-l2"><a class="reference internal" href="what_else.html#dict">dict</a><ul>
<li class="toctree-l3"><a class="reference internal" href="what_else.html#memory-efficiency-and-alternatives">Memory-efficiency and alternatives</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="what_else.html#int">int</a></li>
<li class="toctree-l2"><a class="reference internal" href="what_else.html#isinstance">isinstance</a></li>
<li class="toctree-l2"><a class="reference internal" href="what_else.html#passing-data-to-from-python-2-libraries">Passing data to/from Python 2 libraries</a></li>
<li class="toctree-l2"><a class="reference internal" href="what_else.html#native-string-type">Native string type</a></li>
<li class="toctree-l2"><a class="reference internal" href="what_else.html#open">open()</a></li>
<li class="toctree-l2"><a class="reference internal" href="what_else.html#custom-str-methods">Custom __str__ methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="what_else.html#custom-iterators">Custom iterators</a></li>
<li class="toctree-l2"><a class="reference internal" href="what_else.html#binding-a-method-to-a-class">Binding a method to a class</a></li>
<li class="toctree-l2"><a class="reference internal" href="what_else.html#metaclasses">Metaclasses</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="automatic_conversion.html">Automatic conversion to Py2/3</a><ul>
<li class="toctree-l2"><a class="reference internal" href="automatic_conversion.html#futurize-py2-to-py2-3"><code class="docutils literal"><span class="pre">futurize</span></code>: Py2 to Py2/3</a><ul>
<li class="toctree-l3"><a class="reference internal" href="automatic_conversion.html#stage-1-safe-fixes">Stage 1: “safe” fixes</a></li>
<li class="toctree-l3"><a class="reference internal" href="automatic_conversion.html#stage-2-py3-style-code-with-wrappers-for-py2">Stage 2: Py3-style code with wrappers for Py2</a></li>
<li class="toctree-l3"><a class="reference internal" href="automatic_conversion.html#separating-text-from-bytes">Separating text from bytes</a></li>
<li class="toctree-l3"><a class="reference internal" href="automatic_conversion.html#post-conversion">Post-conversion</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="automatic_conversion.html#futurize-quick-start-guide"><code class="docutils literal"><span class="pre">futurize</span></code> quick-start guide</a><ul>
<li class="toctree-l3"><a class="reference internal" href="automatic_conversion.html#step-0-setup">Step 0: setup</a></li>
<li class="toctree-l3"><a class="reference internal" href="automatic_conversion.html#step-1-modern-py2-code">Step 1: modern Py2 code</a></li>
<li class="toctree-l3"><a class="reference internal" href="automatic_conversion.html#step-2-working-py3-code-that-still-supports-py2">Step 2: working Py3 code that still supports Py2</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="automatic_conversion.html#pasteurize-py3-to-py2-3"><code class="docutils literal"><span class="pre">pasteurize</span></code>: Py3 to Py2/3</a></li>
<li class="toctree-l2"><a class="reference internal" href="automatic_conversion.html#known-limitations">Known limitations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions (FAQ)</a><ul>
<li class="toctree-l2"><a class="reference internal" href="faq.html#who-is-this-for">Who is this for?</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#why-upgrade-to-python-3">Why upgrade to Python 3?</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#porting-philosophy">Porting philosophy</a><ul>
<li class="toctree-l3"><a class="reference internal" href="faq.html#why-write-python-3-style-code">Why write Python 3-style code?</a></li>
<li class="toctree-l3"><a class="reference internal" href="faq.html#can-t-i-just-roll-my-own-py2-3-compatibility-layer">Can’t I just roll my own Py2/3 compatibility layer?</a></li>
<li class="toctree-l3"><a class="reference internal" href="faq.html#what-inspired-this-project">What inspired this project?</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#maturity">Maturity</a><ul>
<li class="toctree-l3"><a class="reference internal" href="faq.html#how-well-has-it-been-tested">How well has it been tested?</a></li>
<li class="toctree-l3"><a class="reference internal" href="faq.html#is-the-api-stable">Is the API stable?</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#relationship-between-python-future-and-other-compatibility-tools">Relationship between python-future and other compatibility tools</a><ul>
<li class="toctree-l3"><a class="reference internal" href="faq.html#how-does-this-relate-to-2to3">How does this relate to <code class="docutils literal"><span class="pre">2to3</span></code>?</a></li>
<li class="toctree-l3"><a class="reference internal" href="faq.html#can-i-maintain-a-python-2-codebase-and-use-2to3-to-automatically-convert-to-python-3-in-the-setup-script">Can I maintain a Python 2 codebase and use 2to3 to automatically convert to Python 3 in the setup script?</a></li>
<li class="toctree-l3"><a class="reference internal" href="faq.html#what-is-the-relationship-between-future-and-six">What is the relationship between <code class="docutils literal"><span class="pre">future</span></code> and <code class="docutils literal"><span class="pre">six</span></code>?</a></li>
<li class="toctree-l3"><a class="reference internal" href="faq.html#what-is-the-relationship-between-python-future-and-python-modernize">What is the relationship between <code class="docutils literal"><span class="pre">python-future</span></code> and <code class="docutils literal"><span class="pre">python-modernize</span></code>?</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#platform-and-version-support">Platform and version support</a><ul>
<li class="toctree-l3"><a class="reference internal" href="faq.html#which-versions-of-python-does-python-future-support">Which versions of Python does <code class="docutils literal"><span class="pre">python-future</span></code> support?</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#support">Support</a><ul>
<li class="toctree-l3"><a class="reference internal" href="faq.html#is-there-a-mailing-list">Is there a mailing list?</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#contributing">Contributing</a><ul>
<li class="toctree-l3"><a class="reference internal" href="faq.html#can-i-help">Can I help?</a></li>
<li class="toctree-l3"><a class="reference internal" href="faq.html#where-is-the-repo">Where is the repo?</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="stdlib_incompatibilities.html">Standard library incompatibilities</a><ul>
<li class="toctree-l2"><a class="reference internal" href="stdlib_incompatibilities.html#array-array">array.array()</a></li>
<li class="toctree-l2"><a class="reference internal" href="stdlib_incompatibilities.html#array-array-read">array.array.read()</a></li>
<li class="toctree-l2"><a class="reference internal" href="stdlib_incompatibilities.html#base64-decodebytes-and-base64-encodebytes">base64.decodebytes() and base64.encodebytes()</a></li>
<li class="toctree-l2"><a class="reference internal" href="stdlib_incompatibilities.html#re-ascii">re.ASCII</a></li>
<li class="toctree-l2"><a class="reference internal" href="stdlib_incompatibilities.html#struct-pack">struct.pack()</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="older_interfaces.html">Older interfaces</a><ul>
<li class="toctree-l2"><a class="reference internal" href="older_interfaces.html#context-manager-for-import-hooks">Context-manager for import hooks</a></li>
<li class="toctree-l2"><a class="reference internal" href="older_interfaces.html#future-moves-interface"><code class="docutils literal"><span class="pre">future.moves</span></code> interface</a><ul>
<li class="toctree-l3"><a class="reference internal" href="older_interfaces.html#comparing-future-moves-and-six-moves">Comparing future.moves and six.moves</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="older_interfaces.html#import-and-from-import-functions"><code class="docutils literal"><span class="pre">import_</span></code> and <code class="docutils literal"><span class="pre">from_import</span></code> functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="older_interfaces.html#install-hooks-call">install_hooks() call</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="changelog.html">Changes in previous versions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-13-1-2014-09-23">Changes in version 0.13.1 (2014-09-23)</a></li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-13-2014-08-13">Changes in version 0.13 (2014-08-13)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#deprecations">Deprecations</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#new-features">New features</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#bug-fixes">Bug fixes</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-12-4-2014-07-18">Changes in version 0.12.4 (2014-07-18)</a></li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-12-3-2014-06-19">Changes in version 0.12.3 (2014-06-19)</a></li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-12-2-2014-05-25">Changes in version 0.12.2 (2014-05-25)</a></li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-12-1-2014-05-14">Changes in version 0.12.1 (2014-05-14)</a></li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-12-0-2014-05-06">Changes in version 0.12.0 (2014-05-06)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#more-robust-standard-library-import-hooks">More robust standard-library import hooks</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#newobject-base-object-defines-fallback-py2-compatible-special-methods"><code class="docutils literal"><span class="pre">newobject</span></code> base object defines fallback Py2-compatible special methods</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#past-builtins-module-improved"><code class="docutils literal"><span class="pre">past.builtins</span></code> module improved</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#surrogateescape-error-handler"><code class="docutils literal"><span class="pre">surrogateescape</span></code> error handler</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#newlist-type"><code class="docutils literal"><span class="pre">newlist</span></code> type</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#listvalues-and-listitems"><code class="docutils literal"><span class="pre">listvalues</span></code> and <code class="docutils literal"><span class="pre">listitems</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#tests">Tests</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#refactoring-of-future-standard-library-future-backports">Refactoring of <code class="docutils literal"><span class="pre">future.standard_library.*</span></code> -> <code class="docutils literal"><span class="pre">future.backports</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#backported-http-server-and-urllib-modules">Backported <code class="docutils literal"><span class="pre">http.server</span></code> and <code class="docutils literal"><span class="pre">urllib</span></code> modules</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#internal-refactoring">Internal refactoring</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#id1">Bug fixes</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-11-4-2014-05-25">Changes in version 0.11.4 (2014-05-25)</a></li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-11-3-2014-02-27">Changes in version 0.11.3 (2014-02-27)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#improved-compatibility-with-requests">Improved compatibility with <code class="docutils literal"><span class="pre">requests</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#conversion-scripts-explicitly-install-import-hooks">Conversion scripts explicitly install import hooks</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#futurize-script-no-longer-adds-unicode-literals-by-default"><code class="docutils literal"><span class="pre">futurize</span></code> script no longer adds <code class="docutils literal"><span class="pre">unicode_literals</span></code> by default</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-11-2014-01-28">Changes in version 0.11 (2014-01-28)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#past-package"><code class="docutils literal"><span class="pre">past</span></code> package</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#auto-translation-of-python-2-modules-upon-import">Auto-translation of Python 2 modules upon import</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#separate-pasteurize-script">Separate <code class="docutils literal"><span class="pre">pasteurize</span></code> script</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#pow">pow()</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#input-no-longer-disabled-globally-on-py2">input() no longer disabled globally on Py2</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#deprecated-feature-auto-installation-of-standard-library-import-hooks">Deprecated feature: auto-installation of standard-library import hooks</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#internal-changes">Internal changes</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-10-2-2014-01-11">Changes in version 0.10.2 (2014-01-11)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#new-context-manager-interface-to-standard-library-hooks">New context-manager interface to standard_library hooks</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-10-0-2013-12-02">Changes in version 0.10.0 (2013-12-02)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#backported-dict-type">Backported <code class="docutils literal"><span class="pre">dict</span></code> type</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#utility-functions-raise-and-exec">Utility functions <code class="docutils literal"><span class="pre">raise_</span></code> and <code class="docutils literal"><span class="pre">exec_</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#bugfixes">Bugfixes</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-9-2013-11-06">Changes in version 0.9 (2013-11-06)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#isinstance-checks-are-supported-natively-with-backported-types"><code class="docutils literal"><span class="pre">isinstance</span></code> checks are supported natively with backported types</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#futurize-minimal-imports-by-default"><code class="docutils literal"><span class="pre">futurize</span></code>: minimal imports by default</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#looser-type-checking-for-the-backported-str-object">Looser type-checking for the backported <code class="docutils literal"><span class="pre">str</span></code> object</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#suspend-hooks-context-manager-added-to-future-standard-library">suspend_hooks() context manager added to <code class="docutils literal"><span class="pre">future.standard_library</span></code></a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-version-0-8-2013-10-28">Changes in version 0.8 (2013-10-28)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#python-2-6-support">Python 2.6 support</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#unused-modules-removed">Unused modules removed</a></li>
<li class="toctree-l3"><a class="reference internal" href="changelog.html#isinstance-added-to-future-builtins-v0-8-2">isinstance() added to <code class="docutils literal"><span class="pre">future.builtins</span></code> (v0.8.2)</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#summary-of-all-changes">Summary of all changes</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="credits.html">Licensing and credits</a><ul>
<li class="toctree-l2"><a class="reference internal" href="credits.html#licence">Licence</a></li>
<li class="toctree-l2"><a class="reference internal" href="credits.html#sponsor">Sponsor</a></li>
<li class="toctree-l2"><a class="reference internal" href="credits.html#authors">Authors</a><ul>
<li class="toctree-l3"><a class="reference internal" href="credits.html#development-lead">Development Lead</a></li>
<li class="toctree-l3"><a class="reference internal" href="credits.html#patches">Patches</a></li>
<li class="toctree-l3"><a class="reference internal" href="credits.html#suggestions-and-feedback">Suggestions and Feedback</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="credits.html#other-credits">Other Credits</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="current reference internal" href="">API Reference (in progress)</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#module-future.builtins">future.builtins Interface</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-future.types">Backported types from Python 3</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#for-more-information">For more information:</a></li>
<li class="toctree-l3"><a class="reference internal" href="#range">range()</a></li>
<li class="toctree-l3"><a class="reference internal" href="#super">super()</a></li>
<li class="toctree-l3"><a class="reference internal" href="#round">round()</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#module-future.standard_library">future.standard_library Interface</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#limitations">Limitations</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#module-future.utils">future.utils Interface</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-past.builtins">past.builtins Interface</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-past.types">Forward-ported types from Python 2</a></li>
</ul>
</li>
</ul>
</ul>
</li>
<li class="dropdown">
<a role="button"
id="dLabelLocalToc"
data-toggle="dropdown"
data-target="#"
href="#">Page <b class="caret"></b></a>
<ul class="dropdown-menu localtoc"
role="menu"
aria-labelledby="dLabelLocalToc"><ul>
<li><a class="reference internal" href="#">API Reference (in progress)</a><ul>
<li><a class="reference internal" href="#module-future.builtins">future.builtins Interface</a></li>
<li><a class="reference internal" href="#module-future.types">Backported types from Python 3</a><ul>
<li><a class="reference internal" href="#for-more-information">For more information:</a><ul>
<li><a class="reference internal" href="#notes">Notes</a></li>
</ul>
</li>
<li><a class="reference internal" href="#range">range()</a></li>
<li><a class="reference internal" href="#super">super()</a></li>
<li><a class="reference internal" href="#round">round()</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-future.standard_library">future.standard_library Interface</a><ul>
<li><a class="reference internal" href="#limitations">Limitations</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-future.utils">future.utils Interface</a></li>
<li><a class="reference internal" href="#module-past.builtins">past.builtins Interface</a></li>
<li><a class="reference internal" href="#module-past.types">Forward-ported types from Python 2</a></li>
</ul>
</li>
</ul>
</ul>
</li>
</ul>
<form class="navbar-form navbar-right" action="search.html" method="get">
<div class="form-group">
<input type="text" name="q" class="form-control" placeholder="Search" />
</div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-3">
<div id="sidebar" class="bs-sidenav" role="complementary"><!--<h3>Python-Future</h3>
<p>-->
<h4>Easy, clean, reliable Python 2/3 compatibility</h4>
<a href="http://python-future.org">Table of Contents</a>
<!--
</p>
<h3>Other Formats</h3>
<p>
You can download the documentation in other formats as well:
</p>
<ul>
<li><a href="http://jinja.pocoo.org/docs/jinja-docs.pdf">as PDF</a>
<li><a href="http://jinja.pocoo.org/docs/jinja-docs.zip">as zipped HTML</a>
</ul>
-->
<!--<h3>Useful Links</h3>
<ul>
<li><a href="http://pypi.python.org/pypi/future">on PyPI</a></li>
<li><a href="https://github.com/PythonCharmers/python-future">on GitHub</a></li>
</ul>
--><ul class="current">
<li class="toctree-l1"><a class="reference internal" href="whatsnew.html">What’s New</a></li>
<li class="toctree-l1"><a class="reference internal" href="overview.html">Overview: Easy, clean, reliable Python 2/3 compatibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="quickstart.html">Quick-start guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="compatible_idioms.html">Cheat Sheet: Writing Python 2-3 compatible code</a></li>
<li class="toctree-l1"><a class="reference internal" href="imports.html">Imports</a></li>
<li class="toctree-l1"><a class="reference internal" href="what_else.html">What else you need to know</a></li>
<li class="toctree-l1"><a class="reference internal" href="automatic_conversion.html">Automatic conversion to Py2/3</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions (FAQ)</a></li>
<li class="toctree-l1"><a class="reference internal" href="stdlib_incompatibilities.html">Standard library incompatibilities</a></li>
<li class="toctree-l1"><a class="reference internal" href="older_interfaces.html">Older interfaces</a></li>
<li class="toctree-l1"><a class="reference internal" href="changelog.html">Changes in previous versions</a></li>
<li class="toctree-l1"><a class="reference internal" href="credits.html">Licensing and credits</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="">API Reference (in progress)</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#module-future.builtins">future.builtins Interface</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-future.types">Backported types from Python 3</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#for-more-information">For more information:</a></li>
<li class="toctree-l3"><a class="reference internal" href="#range">range()</a></li>
<li class="toctree-l3"><a class="reference internal" href="#super">super()</a></li>
<li class="toctree-l3"><a class="reference internal" href="#round">round()</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#module-future.standard_library">future.standard_library Interface</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#limitations">Limitations</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#module-future.utils">future.utils Interface</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-past.builtins">past.builtins Interface</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-past.types">Forward-ported types from Python 2</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="col-md-9">
<div class="section" id="api-reference-in-progress">
<h1>API Reference (in progress)<a class="headerlink" href="#api-reference-in-progress" title="Permalink to this headline">¶</a></h1>
<p><strong>NOTE: This page is still a work in progress... We need to go through our
docstrings and make them sphinx-compliant, and figure out how to improve
formatting with the sphinx-bootstrap-theme plugin. Pull requests would be
very welcome.</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#module-future.builtins" id="id3">future.builtins Interface</a></li>
<li><a class="reference internal" href="#module-future.types" id="id4">Backported types from Python 3</a><ul>
<li><a class="reference internal" href="#for-more-information" id="id5">For more information:</a></li>
<li><a class="reference internal" href="#range" id="id6">range()</a></li>
<li><a class="reference internal" href="#super" id="id7">super()</a></li>
<li><a class="reference internal" href="#round" id="id8">round()</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-future.standard_library" id="id9">future.standard_library Interface</a><ul>
<li><a class="reference internal" href="#limitations" id="id10">Limitations</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-future.utils" id="id11">future.utils Interface</a></li>
<li><a class="reference internal" href="#module-past.builtins" id="id12">past.builtins Interface</a></li>
<li><a class="reference internal" href="#module-past.types" id="id13">Forward-ported types from Python 2</a></li>
</ul>
</div>
<div class="section" id="module-future.builtins">
<span id="future-builtins-interface"></span><h2><a class="toc-backref" href="#id3">future.builtins Interface</a><a class="headerlink" href="#module-future.builtins" title="Permalink to this headline">¶</a></h2>
<p>A module that brings in equivalents of the new and modified Python 3
builtins into Py2. Has no effect on Py3.</p>
<p>See the docs <a class="reference external" href="http://python-future.org/what-else.html">here</a>
(<code class="docutils literal"><span class="pre">docs/what-else.rst</span></code>) for more information.</p>
</div>
<div class="section" id="module-future.types">
<span id="backported-types-from-python-3"></span><h2><a class="toc-backref" href="#id4">Backported types from Python 3</a><a class="headerlink" href="#module-future.types" title="Permalink to this headline">¶</a></h2>
<p>This module contains backports the data types that were significantly changed
in the transition from Python 2 to Python 3.</p>
<ul class="simple">
<li>an implementation of Python 3’s bytes object (pure Python subclass of
Python 2’s builtin 8-bit str type)</li>
<li>an implementation of Python 3’s str object (pure Python subclass of
Python 2’s builtin unicode type)</li>
<li>a backport of the range iterator from Py3 with slicing support</li>
</ul>
<p>It is used as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">division</span><span class="p">,</span> <span class="n">absolute_import</span><span class="p">,</span> <span class="n">print_function</span>
<span class="kn">from</span> <span class="nn">builtins</span> <span class="kn">import</span> <span class="nb">bytes</span><span class="p">,</span> <span class="nb">dict</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">range</span><span class="p">,</span> <span class="nb">str</span>
</pre></div>
</div>
<p>to bring in the new semantics for these functions from Python 3. And
then, for example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">b</span> <span class="o">=</span> <span class="nb">bytes</span><span class="p">(</span><span class="n">b</span><span class="s">'ABCD'</span><span class="p">)</span>
<span class="k">assert</span> <span class="nb">list</span><span class="p">(</span><span class="n">b</span><span class="p">)</span> <span class="o">==</span> <span class="p">[</span><span class="mi">65</span><span class="p">,</span> <span class="mi">66</span><span class="p">,</span> <span class="mi">67</span><span class="p">,</span> <span class="mi">68</span><span class="p">]</span>
<span class="k">assert</span> <span class="nb">repr</span><span class="p">(</span><span class="n">b</span><span class="p">)</span> <span class="o">==</span> <span class="s">"b'ABCD'"</span>
<span class="k">assert</span> <span class="p">[</span><span class="mi">65</span><span class="p">,</span> <span class="mi">66</span><span class="p">]</span> <span class="ow">in</span> <span class="n">b</span>
<span class="c"># These raise TypeErrors:</span>
<span class="c"># b + u'EFGH'</span>
<span class="c"># b.split(u'B')</span>
<span class="c"># bytes(b',').join([u'Fred', u'Bill'])</span>
<span class="n">s</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="s">u'ABCD'</span><span class="p">)</span>
<span class="c"># These raise TypeErrors:</span>
<span class="c"># s.join([b'Fred', b'Bill'])</span>
<span class="c"># s.startswith(b'A')</span>
<span class="c"># b'B' in s</span>
<span class="c"># s.find(b'A')</span>
<span class="c"># s.replace(u'A', b'a')</span>
<span class="c"># This raises an AttributeError:</span>
<span class="c"># s.decode('utf-8')</span>
<span class="k">assert</span> <span class="nb">repr</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="o">==</span> <span class="s">'ABCD'</span> <span class="c"># consistent repr with Py3 (no u prefix)</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="o">**</span><span class="mi">11</span><span class="p">)[:</span><span class="mi">10</span><span class="p">]:</span>
<span class="k">pass</span>
</pre></div>
</div>
<p>and:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">VerboseList</span><span class="p">(</span><span class="nb">list</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">append</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Adding an item'</span><span class="p">)</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">item</span><span class="p">)</span> <span class="c"># new simpler super() function</span>
</pre></div>
</div>
<div class="section" id="for-more-information">
<h3><a class="toc-backref" href="#id5">For more information:</a><a class="headerlink" href="#for-more-information" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li>future.types.newbytes</li>
<li>future.types.newdict</li>
<li>future.types.newint</li>
<li>future.types.newobject</li>
<li>future.types.newrange</li>
<li>future.types.newstr</li>
</ul>
<div class="section" id="notes">
<h4>Notes<a class="headerlink" href="#notes" title="Permalink to this headline">¶</a></h4>
</div>
</div>
<div class="section" id="range">
<h3><a class="toc-backref" href="#id6">range()</a><a class="headerlink" href="#range" title="Permalink to this headline">¶</a></h3>
<p><code class="docutils literal"><span class="pre">range</span></code> is a custom class that backports the slicing behaviour from
Python 3 (based on the <code class="docutils literal"><span class="pre">xrange</span></code> module by Dan Crosta). See the
<code class="docutils literal"><span class="pre">newrange</span></code> module docstring for more details.</p>
</div>
<div class="section" id="super">
<h3><a class="toc-backref" href="#id7">super()</a><a class="headerlink" href="#super" title="Permalink to this headline">¶</a></h3>
<p><code class="docutils literal"><span class="pre">super()</span></code> is based on Ryan Kelly’s <code class="docutils literal"><span class="pre">magicsuper</span></code> module. See the
<code class="docutils literal"><span class="pre">newsuper</span></code> module docstring for more details.</p>
</div>
<div class="section" id="round">
<h3><a class="toc-backref" href="#id8">round()</a><a class="headerlink" href="#round" title="Permalink to this headline">¶</a></h3>
<p>Python 3 modifies the behaviour of <code class="docutils literal"><span class="pre">round()</span></code> to use “Banker’s Rounding”.
See <a class="reference external" href="http://stackoverflow.com/a/10825998">http://stackoverflow.com/a/10825998</a>. See the <code class="docutils literal"><span class="pre">newround</span></code> module
docstring for more details.</p>
</div>
</div>
<div class="section" id="module-future.standard_library">
<span id="future-standard-library-interface"></span><h2><a class="toc-backref" href="#id9">future.standard_library Interface</a><a class="headerlink" href="#module-future.standard_library" title="Permalink to this headline">¶</a></h2>
<p>Python 3 reorganized the standard library (PEP 3108). This module exposes
several standard library modules to Python 2 under their new Python 3
names.</p>
<p>It is designed to be used as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">future</span> <span class="kn">import</span> <span class="n">standard_library</span>
<span class="n">standard_library</span><span class="o">.</span><span class="n">install_aliases</span><span class="p">()</span>
</pre></div>
</div>
<p>And then these normal Py3 imports work on both Py3 and Py2:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">builtins</span>
<span class="kn">import</span> <span class="nn">configparser</span>
<span class="kn">import</span> <span class="nn">copyreg</span>
<span class="kn">import</span> <span class="nn">queue</span>
<span class="kn">import</span> <span class="nn">reprlib</span>
<span class="kn">import</span> <span class="nn">socketserver</span>
<span class="kn">import</span> <span class="nn">winreg</span> <span class="c"># on Windows only</span>
<span class="kn">import</span> <span class="nn">test.support</span>
<span class="kn">import</span> <span class="nn">html</span><span class="o">,</span> <span class="nn">html.parser</span><span class="o">,</span> <span class="nn">html.entites</span>
<span class="kn">import</span> <span class="nn">http</span><span class="o">,</span> <span class="nn">http.client</span><span class="o">,</span> <span class="nn">http.server</span>
<span class="kn">import</span> <span class="nn">http.cookies</span><span class="o">,</span> <span class="nn">http.cookiejar</span>
<span class="kn">import</span> <span class="nn">urllib.parse</span><span class="o">,</span> <span class="nn">urllib.request</span><span class="o">,</span> <span class="nn">urllib.response</span><span class="o">,</span> <span class="nn">urllib.error</span><span class="o">,</span> <span class="nn">urllib.robotparser</span>
<span class="kn">import</span> <span class="nn">xmlrpc.client</span><span class="o">,</span> <span class="nn">xmlrpc.server</span>
<span class="kn">import</span> <span class="nn">_thread</span>
<span class="kn">import</span> <span class="nn">_dummy_thread</span>
<span class="kn">import</span> <span class="nn">_markupbase</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">filterfalse</span><span class="p">,</span> <span class="n">zip_longest</span>
<span class="kn">from</span> <span class="nn">sys</span> <span class="kn">import</span> <span class="nb">intern</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">UserDict</span><span class="p">,</span> <span class="n">UserList</span><span class="p">,</span> <span class="n">UserString</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">OrderedDict</span><span class="p">,</span> <span class="n">Counter</span> <span class="c"># even on Py2.6</span>
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">getoutput</span><span class="p">,</span> <span class="n">getstatusoutput</span>
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">check_output</span> <span class="c"># even on Py2.6</span>
</pre></div>
</div>
<p>(The renamed modules and functions are still available under their old
names on Python 2.)</p>
<p>This is a cleaner alternative to this idiom (see
<a class="reference external" href="http://docs.pythonsprints.com/python3_porting/py-porting.html">http://docs.pythonsprints.com/python3_porting/py-porting.html</a>):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">try</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">queue</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">Queue</span> <span class="kn">as</span> <span class="nn">queue</span>
</pre></div>
</div>
<div class="section" id="limitations">
<h3><a class="toc-backref" href="#id10">Limitations</a><a class="headerlink" href="#limitations" title="Permalink to this headline">¶</a></h3>
<p>We don’t currently support these modules, but would like to:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">dbm</span>
<span class="kn">import</span> <span class="nn">dbm.dumb</span>
<span class="kn">import</span> <span class="nn">dbm.gnu</span>
<span class="kn">import</span> <span class="nn">collections.abc</span> <span class="c"># on Py33</span>
<span class="kn">import</span> <span class="nn">pickle</span> <span class="c"># should (optionally) bring in cPickle on Python 2</span>
</pre></div>
</div>
<dl class="class">
<dt id="future.standard_library.RenameImport">
<em class="property">class </em><code class="descclassname">future.standard_library.</code><code class="descname">RenameImport</code><span class="sig-paren">(</span><em>old_to_new</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#RenameImport"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.RenameImport" title="Permalink to this definition">¶</a></dt>
<dd><p>A class for import hooks mapping Py3 module names etc. to the Py2 equivalents.</p>
</dd></dl>
<dl class="function">
<dt id="future.standard_library.cache_py2_modules">
<code class="descclassname">future.standard_library.</code><code class="descname">cache_py2_modules</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#cache_py2_modules"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.cache_py2_modules" title="Permalink to this definition">¶</a></dt>
<dd><p>Currently this function is unneeded, as we are not attempting to provide import hooks
for modules with ambiguous names: email, urllib, pickle.</p>
</dd></dl>
<dl class="function">
<dt id="future.standard_library.detect_hooks">
<code class="descclassname">future.standard_library.</code><code class="descname">detect_hooks</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#detect_hooks"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.detect_hooks" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns True if the import hooks are installed, False if not.</p>
</dd></dl>
<dl class="function">
<dt id="future.standard_library.disable_hooks">
<code class="descclassname">future.standard_library.</code><code class="descname">disable_hooks</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#disable_hooks"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.disable_hooks" title="Permalink to this definition">¶</a></dt>
<dd><p>Deprecated. Use remove_hooks() instead. This will be removed by
<code class="docutils literal"><span class="pre">future</span></code> v1.0.</p>
</dd></dl>
<dl class="function">
<dt id="future.standard_library.enable_hooks">
<code class="descclassname">future.standard_library.</code><code class="descname">enable_hooks</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#enable_hooks"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.enable_hooks" title="Permalink to this definition">¶</a></dt>
<dd><p>Deprecated. Use install_hooks() instead. This will be removed by
<code class="docutils literal"><span class="pre">future</span></code> v1.0.</p>
</dd></dl>
<dl class="class">
<dt id="future.standard_library.exclude_local_folder_imports">
<em class="property">class </em><code class="descclassname">future.standard_library.</code><code class="descname">exclude_local_folder_imports</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#exclude_local_folder_imports"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.exclude_local_folder_imports" title="Permalink to this definition">¶</a></dt>
<dd><p>A context-manager that prevents standard library modules like configparser
from being imported from the local python-future source folder on Py3.</p>
<p>(The presence of a configparser folder would otherwise prevent setuptools
from running on Py3.)</p>
</dd></dl>
<dl class="function">
<dt id="future.standard_library.from_import">
<code class="descclassname">future.standard_library.</code><code class="descname">from_import</code><span class="sig-paren">(</span><em>module_name</em>, <em>*symbol_names</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#from_import"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.from_import" title="Permalink to this definition">¶</a></dt>
<dd><dl class="docutils">
<dt>Example use:</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">HTTPConnection</span> <span class="o">=</span> <span class="n">from_import</span><span class="p">(</span><span class="s">'http.client'</span><span class="p">,</span> <span class="s">'HTTPConnection'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">HTTPServer</span> <span class="o">=</span> <span class="n">from_import</span><span class="p">(</span><span class="s">'http.server'</span><span class="p">,</span> <span class="s">'HTTPServer'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">urlopen</span><span class="p">,</span> <span class="n">urlparse</span> <span class="o">=</span> <span class="n">from_import</span><span class="p">(</span><span class="s">'urllib.request'</span><span class="p">,</span> <span class="s">'urlopen'</span><span class="p">,</span> <span class="s">'urlparse'</span><span class="p">)</span>
</pre></div>
</div>
</dd>
</dl>
<p>Equivalent to this on Py3:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">module_name</span> <span class="kn">import</span> <span class="n">symbol_names</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">symbol_names</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="o">...</span>
</pre></div>
</div>
<p>and this on Py2:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future.moves.module_name</span> <span class="kn">import</span> <span class="n">symbol_names</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="o">...</span>
</pre></div>
</div>
<p>or:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future.backports.module_name</span> <span class="kn">import</span> <span class="n">symbol_names</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="o">...</span>
</pre></div>
</div>
<p>except that it also handles dotted module names such as <code class="docutils literal"><span class="pre">http.client</span></code>.</p>
</dd></dl>
<dl class="class">
<dt id="future.standard_library.hooks">
<em class="property">class </em><code class="descclassname">future.standard_library.</code><code class="descname">hooks</code><a class="reference internal" href="_modules/future/standard_library.html#hooks"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.hooks" title="Permalink to this definition">¶</a></dt>
<dd><p>Acts as a context manager. Saves the state of sys.modules and restores it
after the ‘with’ block.</p>
<p>Use like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future</span> <span class="kn">import</span> <span class="n">standard_library</span>
<span class="gp">>>> </span><span class="k">with</span> <span class="n">standard_library</span><span class="o">.</span><span class="n">hooks</span><span class="p">():</span>
<span class="gp">... </span> <span class="kn">import</span> <span class="nn">http.client</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">requests</span>
</pre></div>
</div>
<p>For this to work, http.client will be scrubbed from sys.modules after the
‘with’ block. That way the modules imported in the ‘with’ block will
continue to be accessible in the current namespace but not from any
imported modules (like requests).</p>
</dd></dl>
<dl class="function">
<dt id="future.standard_library.import_">
<code class="descclassname">future.standard_library.</code><code class="descname">import_</code><span class="sig-paren">(</span><em>module_name</em>, <em>backport=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#import_"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.import_" title="Permalink to this definition">¶</a></dt>
<dd><p>Pass a (potentially dotted) module name of a Python 3 standard library
module. This function imports the module compatibly on Py2 and Py3 and
returns the top-level module.</p>
<dl class="docutils">
<dt>Example use:</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">http</span> <span class="o">=</span> <span class="n">import_</span><span class="p">(</span><span class="s">'http.client'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">http</span> <span class="o">=</span> <span class="n">import_</span><span class="p">(</span><span class="s">'http.server'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">urllib</span> <span class="o">=</span> <span class="n">import_</span><span class="p">(</span><span class="s">'urllib.request'</span><span class="p">)</span>
</pre></div>
</div>
</dd>
<dt>Then:</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">conn</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">HTTPConnection</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">response</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s">'http://mywebsite.com'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="c"># etc.</span>
</pre></div>
</div>
</dd>
<dt>Use as follows:</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">package_name</span> <span class="o">=</span> <span class="n">import_</span><span class="p">(</span><span class="n">module_name</span><span class="p">)</span>
</pre></div>
</div>
</dd>
</dl>
<p>On Py3, equivalent to this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">module_name</span>
</pre></div>
</div>
<p>On Py2, equivalent to this if backport=False:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future.moves</span> <span class="kn">import</span> <span class="n">module_name</span>
</pre></div>
</div>
<p>or to this if backport=True:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future.backports</span> <span class="kn">import</span> <span class="n">module_name</span>
</pre></div>
</div>
<p>except that it also handles dotted module names such as <code class="docutils literal"><span class="pre">http.client</span></code>
The effect then is like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future.backports</span> <span class="kn">import</span> <span class="n">module</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future.backports.module</span> <span class="kn">import</span> <span class="n">submodule</span>
<span class="gp">>>> </span><span class="n">module</span><span class="o">.</span><span class="n">submodule</span> <span class="o">=</span> <span class="n">submodule</span>
</pre></div>
</div>
<p>Note that this would be a SyntaxError in Python:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future.backports</span> <span class="kn">import</span> <span class="n">http</span><span class="o">.</span><span class="n">client</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="future.standard_library.install_aliases">
<code class="descclassname">future.standard_library.</code><code class="descname">install_aliases</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#install_aliases"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.install_aliases" title="Permalink to this definition">¶</a></dt>
<dd><p>Monkey-patches the standard library in Py2.6/7 to provide
aliases for better Py3 compatibility.</p>
</dd></dl>
<dl class="function">
<dt id="future.standard_library.install_hooks">
<code class="descclassname">future.standard_library.</code><code class="descname">install_hooks</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#install_hooks"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.install_hooks" title="Permalink to this definition">¶</a></dt>
<dd><p>This function installs the future.standard_library import hook into
sys.meta_path.</p>
</dd></dl>
<dl class="function">
<dt id="future.standard_library.is_py2_stdlib_module">
<code class="descclassname">future.standard_library.</code><code class="descname">is_py2_stdlib_module</code><span class="sig-paren">(</span><em>m</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#is_py2_stdlib_module"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.is_py2_stdlib_module" title="Permalink to this definition">¶</a></dt>
<dd><p>Tries to infer whether the module m is from the Python 2 standard library.
This may not be reliable on all systems.</p>
</dd></dl>
<dl class="function">
<dt id="future.standard_library.remove_hooks">
<code class="descclassname">future.standard_library.</code><code class="descname">remove_hooks</code><span class="sig-paren">(</span><em>scrub_sys_modules=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#remove_hooks"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.remove_hooks" title="Permalink to this definition">¶</a></dt>
<dd><p>This function removes the import hook from sys.meta_path.</p>
</dd></dl>
<dl class="function">
<dt id="future.standard_library.restore_sys_modules">
<code class="descclassname">future.standard_library.</code><code class="descname">restore_sys_modules</code><span class="sig-paren">(</span><em>scrubbed</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#restore_sys_modules"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.restore_sys_modules" title="Permalink to this definition">¶</a></dt>
<dd><p>Add any previously scrubbed modules back to the sys.modules cache,
but only if it’s safe to do so.</p>
</dd></dl>
<dl class="function">
<dt id="future.standard_library.scrub_future_sys_modules">
<code class="descclassname">future.standard_library.</code><code class="descname">scrub_future_sys_modules</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#scrub_future_sys_modules"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.scrub_future_sys_modules" title="Permalink to this definition">¶</a></dt>
<dd><p>Deprecated.</p>
</dd></dl>
<dl class="function">
<dt id="future.standard_library.scrub_py2_sys_modules">
<code class="descclassname">future.standard_library.</code><code class="descname">scrub_py2_sys_modules</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/standard_library.html#scrub_py2_sys_modules"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.scrub_py2_sys_modules" title="Permalink to this definition">¶</a></dt>
<dd><p>Removes any Python 2 standard library modules from <code class="docutils literal"><span class="pre">sys.modules</span></code> that
would interfere with Py3-style imports using import hooks. Examples are
modules with the same names (like urllib or email).</p>
<p>(Note that currently import hooks are disabled for modules like these
with ambiguous names anyway ...)</p>
</dd></dl>
<dl class="class">
<dt id="future.standard_library.suspend_hooks">
<em class="property">class </em><code class="descclassname">future.standard_library.</code><code class="descname">suspend_hooks</code><a class="reference internal" href="_modules/future/standard_library.html#suspend_hooks"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.standard_library.suspend_hooks" title="Permalink to this definition">¶</a></dt>
<dd><p>Acts as a context manager. Use like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future</span> <span class="kn">import</span> <span class="n">standard_library</span>
<span class="gp">>>> </span><span class="n">standard_library</span><span class="o">.</span><span class="n">install_hooks</span><span class="p">()</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">http.client</span>
<span class="gp">>>> </span><span class="c"># ...</span>
<span class="gp">>>> </span><span class="k">with</span> <span class="n">standard_library</span><span class="o">.</span><span class="n">suspend_hooks</span><span class="p">():</span>
<span class="gp">>>> </span> <span class="kn">import</span> <span class="nn">requests</span> <span class="c"># incompatible with ``future``'s standard library hooks</span>
</pre></div>
</div>
<p>If the hooks were disabled before the context, they are not installed when
the context is left.</p>
</dd></dl>
</div>
</div>
<div class="section" id="module-future.utils">
<span id="future-utils-interface"></span><h2><a class="toc-backref" href="#id11">future.utils Interface</a><a class="headerlink" href="#module-future.utils" title="Permalink to this headline">¶</a></h2>
<p>A selection of cross-compatible functions for Python 2 and 3.</p>
<p>This module exports useful functions for 2/3 compatible code:</p>
<blockquote>
<div><ul>
<li><p class="first">bind_method: binds functions to classes</p>
</li>
<li><p class="first"><code class="docutils literal"><span class="pre">native_str_to_bytes</span></code> and <code class="docutils literal"><span class="pre">bytes_to_native_str</span></code></p>
</li>
<li><p class="first"><code class="docutils literal"><span class="pre">native_str</span></code>: always equal to the native platform string object (because
this may be shadowed by imports from future.builtins)</p>
</li>
<li><p class="first">lists: lrange(), lmap(), lzip(), lfilter()</p>
</li>
<li><dl class="first docutils">
<dt>iterable method compatibility:</dt>
<dd><ul class="first simple">
<li>iteritems, iterkeys, itervalues</li>
<li>viewitems, viewkeys, viewvalues</li>
</ul>
<p class="last">These use the original method if available, otherwise they use items,
keys, values.</p>
</dd>
</dl>
</li>
<li><p class="first">types:</p>
<blockquote>
<div><ul class="simple">
<li>text_type: unicode in Python 2, str in Python 3</li>
<li>binary_type: str in Python 2, bythes in Python 3</li>
<li>string_types: basestring in Python 2, str in Python 3</li>
</ul>
</div></blockquote>
</li>
<li><dl class="first docutils">
<dt>bchr(c):</dt>
<dd><p class="first last">Take an integer and make a 1-character byte string</p>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>bord(c)</dt>
<dd><p class="first last">Take the result of indexing on a byte string and make an integer</p>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>tobytes(s)</dt>
<dd><p class="first last">Take a text string, a byte string, or a sequence of characters taken
from a byte string, and make a byte string.</p>
</dd>
</dl>
</li>
<li><p class="first">raise_from()</p>
</li>
<li><p class="first">raise_with_traceback()</p>
</li>
</ul>
</div></blockquote>
<p>This module also defines these decorators:</p>
<blockquote>
<div><ul class="simple">
<li><code class="docutils literal"><span class="pre">python_2_unicode_compatible</span></code></li>
<li><code class="docutils literal"><span class="pre">with_metaclass</span></code></li>
<li><code class="docutils literal"><span class="pre">implements_iterator</span></code></li>
</ul>
</div></blockquote>
<p>Some of the functions in this module come from the following sources:</p>
<blockquote>
<div><ul class="simple">
<li>Jinja2 (BSD licensed: see
<a class="reference external" href="https://github.com/mitsuhiko/jinja2/blob/master/LICENSE">https://github.com/mitsuhiko/jinja2/blob/master/LICENSE</a>)</li>
<li>Pandas compatibility module pandas.compat</li>
<li>six.py by Benjamin Peterson</li>
<li>Django</li>
</ul>
</div></blockquote>
<dl class="function">
<dt id="future.utils.as_native_str">
<code class="descclassname">future.utils.</code><code class="descname">as_native_str</code><span class="sig-paren">(</span><em>encoding='utf-8'</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#as_native_str"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.as_native_str" title="Permalink to this definition">¶</a></dt>
<dd><p>A decorator to turn a function or method call that returns text, i.e.
unicode, into one that returns a native platform str.</p>
<p>Use it as a decorator like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">unicode_literals</span>
<span class="k">class</span> <span class="nc">MyClass</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="nd">@as_native_str</span><span class="p">(</span><span class="n">encoding</span><span class="o">=</span><span class="s">'ascii'</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">next</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_iter</span><span class="p">)</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="future.utils.bind_method">
<code class="descclassname">future.utils.</code><code class="descname">bind_method</code><span class="sig-paren">(</span><em>cls</em>, <em>name</em>, <em>func</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#bind_method"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.bind_method" title="Permalink to this definition">¶</a></dt>
<dd><p>Bind a method to class, python 2 and python 3 compatible.</p>
<dl class="docutils">
<dt>cls <span class="classifier-delimiter">:</span> <span class="classifier">type</span></dt>
<dd>class to receive bound method</dd>
<dt>name <span class="classifier-delimiter">:</span> <span class="classifier">basestring</span></dt>
<dd>name of method on class instance</dd>
<dt>func <span class="classifier-delimiter">:</span> <span class="classifier">function</span></dt>
<dd>function to be bound as method</dd>
</dl>
<p>None</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.exec_">
<code class="descclassname">future.utils.</code><code class="descname">exec_</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#future.utils.exec_" title="Permalink to this definition">¶</a></dt>
<dd><p>exec(object[, globals[, locals]])</p>
<p>Read and execute code from an object, which can be a string or a code
object.
The globals and locals are dictionaries, defaulting to the current
globals and locals. If only globals is given, locals defaults to it.</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.implements_iterator">
<code class="descclassname">future.utils.</code><code class="descname">implements_iterator</code><span class="sig-paren">(</span><em>cls</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#implements_iterator"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.implements_iterator" title="Permalink to this definition">¶</a></dt>
<dd><p>From jinja2/_compat.py. License: BSD.</p>
<p>Use as a decorator like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@implements_iterator</span>
<span class="k">class</span> <span class="nc">UppercasingIterator</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">iterable</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_iter</span> <span class="o">=</span> <span class="nb">iter</span><span class="p">(</span><span class="n">iterable</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span>
<span class="k">def</span> <span class="nf">__next__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">next</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_iter</span><span class="p">)</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="future.utils.is_new_style">
<code class="descclassname">future.utils.</code><code class="descname">is_new_style</code><span class="sig-paren">(</span><em>cls</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#is_new_style"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.is_new_style" title="Permalink to this definition">¶</a></dt>
<dd><p>Python 2.7 has both new-style and old-style classes. Old-style classes can
be pesky in some circumstances, such as when using inheritance. Use this
function to test for whether a class is new-style. (Python 3 only has
new-style classes.)</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.isbytes">
<code class="descclassname">future.utils.</code><code class="descname">isbytes</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#isbytes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.isbytes" title="Permalink to this definition">¶</a></dt>
<dd><dl class="docutils">
<dt>Deprecated. Use::</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="nb">bytes</span><span class="p">)</span>
</pre></div>
</div>
</dd>
<dt>after this import:</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future.builtins</span> <span class="kn">import</span> <span class="nb">bytes</span>
</pre></div>
</div>
</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="future.utils.isidentifier">
<code class="descclassname">future.utils.</code><code class="descname">isidentifier</code><span class="sig-paren">(</span><em>s</em>, <em>dotted=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#isidentifier"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.isidentifier" title="Permalink to this definition">¶</a></dt>
<dd><p>A function equivalent to the str.isidentifier method on Py3</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.isint">
<code class="descclassname">future.utils.</code><code class="descname">isint</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#isint"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.isint" title="Permalink to this definition">¶</a></dt>
<dd><p>Deprecated. Tests whether an object is a Py3 <code class="docutils literal"><span class="pre">int</span></code> or either a Py2 <code class="docutils literal"><span class="pre">int</span></code> or
<code class="docutils literal"><span class="pre">long</span></code>.</p>
<p>Instead of using this function, you can use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future.builtins</span> <span class="kn">import</span> <span class="nb">int</span>
<span class="gp">>>> </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
</pre></div>
</div>
<p>The following idiom is equivalent:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">numbers</span> <span class="kn">import</span> <span class="n">Integral</span>
<span class="gp">>>> </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">Integral</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="future.utils.isnewbytes">
<code class="descclassname">future.utils.</code><code class="descname">isnewbytes</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#isnewbytes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.isnewbytes" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to the result of <code class="docutils literal"><span class="pre">isinstance(obj,</span> <span class="pre">newbytes)</span></code> were
<code class="docutils literal"><span class="pre">__instancecheck__</span></code> not overridden on the newbytes subclass. In
other words, it is REALLY a newbytes instance, not a Py2 native str
object?</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.istext">
<code class="descclassname">future.utils.</code><code class="descname">istext</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#istext"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.istext" title="Permalink to this definition">¶</a></dt>
<dd><dl class="docutils">
<dt>Deprecated. Use::</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span>
</pre></div>
</div>
</dd>
<dt>after this import:</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future.builtins</span> <span class="kn">import</span> <span class="nb">str</span>
</pre></div>
</div>
</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="future.utils.iteritems">
<code class="descclassname">future.utils.</code><code class="descname">iteritems</code><span class="sig-paren">(</span><em>obj</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#iteritems"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.iteritems" title="Permalink to this definition">¶</a></dt>
<dd><p>Use this only if compatibility with Python versions before 2.7 is
required. Otherwise, prefer viewitems().</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.iterkeys">
<code class="descclassname">future.utils.</code><code class="descname">iterkeys</code><span class="sig-paren">(</span><em>obj</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#iterkeys"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.iterkeys" title="Permalink to this definition">¶</a></dt>
<dd><p>Use this only if compatibility with Python versions before 2.7 is
required. Otherwise, prefer viewkeys().</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.itervalues">
<code class="descclassname">future.utils.</code><code class="descname">itervalues</code><span class="sig-paren">(</span><em>obj</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#itervalues"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.itervalues" title="Permalink to this definition">¶</a></dt>
<dd><p>Use this only if compatibility with Python versions before 2.7 is
required. Otherwise, prefer viewvalues().</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.native">
<code class="descclassname">future.utils.</code><code class="descname">native</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#native"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.native" title="Permalink to this definition">¶</a></dt>
<dd><p>On Py3, this is a no-op: native(obj) -> obj</p>
<p>On Py2, returns the corresponding native Py2 types that are
superclasses for backported objects from Py3:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">builtins</span> <span class="kn">import</span> <span class="nb">str</span><span class="p">,</span> <span class="nb">bytes</span><span class="p">,</span> <span class="nb">int</span>
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">native</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="s">u'ABC'</span><span class="p">))</span>
<span class="go">u'ABC'</span>
<span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="n">native</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="s">u'ABC'</span><span class="p">)))</span>
<span class="go">unicode</span>
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">native</span><span class="p">(</span><span class="nb">bytes</span><span class="p">(</span><span class="n">b</span><span class="s">'ABC'</span><span class="p">))</span>
<span class="go">b'ABC'</span>
<span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="n">native</span><span class="p">(</span><span class="nb">bytes</span><span class="p">(</span><span class="n">b</span><span class="s">'ABC'</span><span class="p">)))</span>
<span class="go">bytes</span>
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">native</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="mi">10</span><span class="o">**</span><span class="mi">20</span><span class="p">))</span>
<span class="go">100000000000000000000L</span>
<span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="n">native</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="mi">10</span><span class="o">**</span><span class="mi">20</span><span class="p">)))</span>
<span class="go">long</span>
</pre></div>
</div>
<p>Existing native types on Py2 will be returned unchanged:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="n">native</span><span class="p">(</span><span class="s">u'ABC'</span><span class="p">))</span>
<span class="go">unicode</span>
</pre></div>
</div>
</dd></dl>
<dl class="attribute">
<dt id="future.utils.native_bytes">
<code class="descclassname">future.utils.</code><code class="descname">native_bytes</code><a class="headerlink" href="#future.utils.native_bytes" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <code class="xref py py-class docutils literal"><span class="pre">bytes</span></code></p>
</dd></dl>
<dl class="attribute">
<dt id="future.utils.native_str">
<code class="descclassname">future.utils.</code><code class="descname">native_str</code><a class="headerlink" href="#future.utils.native_str" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference external" href="http://docs.python.org/library/functions.html#str" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">str</span></code></a></p>
</dd></dl>
<dl class="function">
<dt id="future.utils.native_str_to_bytes">
<code class="descclassname">future.utils.</code><code class="descname">native_str_to_bytes</code><span class="sig-paren">(</span><em>s</em>, <em>encoding='utf-8'</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#native_str_to_bytes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.native_str_to_bytes" title="Permalink to this definition">¶</a></dt>
<dd><p>On Py3, returns an encoded string.
On Py2, returns a newbytes type, ignoring the <code class="docutils literal"><span class="pre">encoding</span></code> argument.</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.old_div">
<code class="descclassname">future.utils.</code><code class="descname">old_div</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#old_div"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.old_div" title="Permalink to this definition">¶</a></dt>
<dd><p>DEPRECATED: import <code class="docutils literal"><span class="pre">old_div</span></code> from <code class="docutils literal"><span class="pre">past.utils</span></code> instead.</p>
<p>Equivalent to <code class="docutils literal"><span class="pre">a</span> <span class="pre">/</span> <span class="pre">b</span></code> on Python 2 without <code class="docutils literal"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span>
<span class="pre">division</span></code>.</p>
<p>TODO: generalize this to other objects (like arrays etc.)</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.python_2_unicode_compatible">
<code class="descclassname">future.utils.</code><code class="descname">python_2_unicode_compatible</code><span class="sig-paren">(</span><em>cls</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#python_2_unicode_compatible"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.python_2_unicode_compatible" title="Permalink to this definition">¶</a></dt>
<dd><p>A decorator that defines __unicode__ and __str__ methods under Python
2. Under Python 3, this decorator is a no-op.</p>
<p>To support Python 2 and 3 with a single code base, define a __str__
method returning unicode text and apply this decorator to the class, like
this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future.utils</span> <span class="kn">import</span> <span class="n">python_2_unicode_compatible</span>
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="nd">@python_2_unicode_compatible</span>
<span class="gp">... </span><span class="k">class</span> <span class="nc">MyClass</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">return</span> <span class="s">u'Unicode string: 孔子'</span>
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">MyClass</span><span class="p">()</span>
</pre></div>
</div>
<p>Then, after this import:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">future.builtins</span> <span class="kn">import</span> <span class="nb">str</span>
</pre></div>
</div>
<p>the following is <code class="docutils literal"><span class="pre">True</span></code> on both Python 3 and 2:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="nb">str</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> <span class="o">==</span> <span class="n">a</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s">'utf-8'</span><span class="p">)</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s">'utf-8'</span><span class="p">)</span>
</pre></div>
</div>
<p>True</p>
<p>and, on a Unicode-enabled terminal with the right fonts, these both print the
Chinese characters for Confucius:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">a</span><span class="p">))</span>
</pre></div>
</div>
<p>The implementation comes from django.utils.encoding.</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.raise_">
<code class="descclassname">future.utils.</code><code class="descname">raise_</code><span class="sig-paren">(</span><em>tp</em>, <em>value=None</em>, <em>tb=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#raise_"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.raise_" title="Permalink to this definition">¶</a></dt>
<dd><p>A function that matches the Python 2.x <code class="docutils literal"><span class="pre">raise</span></code> statement. This
allows re-raising exceptions with the cls value and traceback on
Python 2 and 3.</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.raise_with_traceback">
<code class="descclassname">future.utils.</code><code class="descname">raise_with_traceback</code><span class="sig-paren">(</span><em>exc</em>, <em>traceback=Ellipsis</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#raise_with_traceback"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.raise_with_traceback" title="Permalink to this definition">¶</a></dt>
<dd><p>Raise exception with existing traceback.
If traceback is not passed, uses sys.exc_info() to get traceback.</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.reraise">
<code class="descclassname">future.utils.</code><code class="descname">reraise</code><span class="sig-paren">(</span><em>tp</em>, <em>value=None</em>, <em>tb=None</em><span class="sig-paren">)</span><a class="headerlink" href="#future.utils.reraise" title="Permalink to this definition">¶</a></dt>
<dd><p>A function that matches the Python 2.x <code class="docutils literal"><span class="pre">raise</span></code> statement. This
allows re-raising exceptions with the cls value and traceback on
Python 2 and 3.</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.tobytes">
<code class="descclassname">future.utils.</code><code class="descname">tobytes</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#tobytes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.tobytes" title="Permalink to this definition">¶</a></dt>
<dd><p>Encodes to latin-1 (where the first 256 chars are the same as
ASCII.)</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.viewitems">
<code class="descclassname">future.utils.</code><code class="descname">viewitems</code><span class="sig-paren">(</span><em>obj</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#viewitems"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.viewitems" title="Permalink to this definition">¶</a></dt>
<dd><p>Function for iterating over dictionary items with the same set-like
behaviour on Py2.7 as on Py3.</p>
<p>Passes kwargs to method.</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.viewkeys">
<code class="descclassname">future.utils.</code><code class="descname">viewkeys</code><span class="sig-paren">(</span><em>obj</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#viewkeys"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.viewkeys" title="Permalink to this definition">¶</a></dt>
<dd><p>Function for iterating over dictionary keys with the same set-like
behaviour on Py2.7 as on Py3.</p>
<p>Passes kwargs to method.</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.viewvalues">
<code class="descclassname">future.utils.</code><code class="descname">viewvalues</code><span class="sig-paren">(</span><em>obj</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#viewvalues"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.viewvalues" title="Permalink to this definition">¶</a></dt>
<dd><p>Function for iterating over dictionary values with the same set-like
behaviour on Py2.7 as on Py3.</p>
<p>Passes kwargs to method.</p>
</dd></dl>
<dl class="function">
<dt id="future.utils.with_metaclass">
<code class="descclassname">future.utils.</code><code class="descname">with_metaclass</code><span class="sig-paren">(</span><em>meta</em>, <em>*bases</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/future/utils.html#with_metaclass"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#future.utils.with_metaclass" title="Permalink to this definition">¶</a></dt>
<dd><p>Function from jinja2/_compat.py. License: BSD.</p>
<p>Use it like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">BaseForm</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">pass</span>
<span class="k">class</span> <span class="nc">FormType</span><span class="p">(</span><span class="nb">type</span><span class="p">):</span>
<span class="k">pass</span>
<span class="k">class</span> <span class="nc">Form</span><span class="p">(</span><span class="n">with_metaclass</span><span class="p">(</span><span class="n">FormType</span><span class="p">,</span> <span class="n">BaseForm</span><span class="p">)):</span>
<span class="k">pass</span>
</pre></div>
</div>
<p>This requires a bit of explanation: the basic idea is to make a
dummy metaclass for one level of class instantiation that replaces
itself with the actual metaclass. Because of internal type checks
we also need to make sure that we downgrade the custom metaclass
for one level to something closer to type (that’s why __call__ and
__init__ comes back from type etc.).</p>
<p>This has the advantage over six.with_metaclass of not introducing
dummy classes into the final MRO.</p>
</dd></dl>
</div>
<div class="section" id="module-past.builtins">
<span id="past-builtins-interface"></span><h2><a class="toc-backref" href="#id12">past.builtins Interface</a><a class="headerlink" href="#module-past.builtins" title="Permalink to this headline">¶</a></h2>
<p>A resurrection of some old functions from Python 2 for use in Python 3. These
should be used sparingly, to help with porting efforts, since code using them
is no longer standard Python 3 code.</p>
<p>This module provides the following:</p>
<ol class="arabic simple">
<li>Implementations of these builtin functions which have no equivalent on Py3:</li>
</ol>
<ul class="simple">
<li>apply</li>
<li>chr</li>
<li>cmp</li>
<li>execfile</li>
</ul>
<ol class="arabic simple" start="2">
<li>Aliases:</li>
</ol>
<ul class="simple">
<li>intern <- sys.intern</li>
<li>raw_input <- input</li>
<li>reduce <- functools.reduce</li>
<li>reload <- imp.reload</li>
<li>unichr <- chr</li>
<li>unicode <- str</li>
<li>xrange <- range</li>
</ul>
<ol class="arabic simple" start="3">
<li>List-producing versions of the corresponding Python 3 iterator-producing functions:</li>
</ol>
<ul class="simple">
<li>filter</li>
<li>map</li>
<li>range</li>
<li>zip</li>
</ul>
<ol class="arabic simple" start="4">
<li>Forward-ported Py2 types:</li>
</ol>
<ul class="simple">
<li>basestring</li>
<li>dict</li>
<li>str</li>
<li>long</li>
<li>unicode</li>
</ul>
<dl class="function">
<dt id="past.builtins.filter">
<code class="descclassname">past.builtins.</code><code class="descname">filter</code><span class="sig-paren">(</span><em>function or None</em>, <em>sequence</em><span class="sig-paren">)</span> → list, tuple, or string<a class="headerlink" href="#past.builtins.filter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return those items of sequence for which function(item) is true.
If function is None, return the items that are true. If sequence
is a tuple or string, return the same type, else return a list.</p>
</dd></dl>
<dl class="function">
<dt id="past.builtins.map">
<code class="descclassname">past.builtins.</code><code class="descname">map</code><span class="sig-paren">(</span><em>function</em>, <em>sequence</em><span class="optional">[</span>, <em>sequence</em>, <em>...</em><span class="optional">]</span><span class="sig-paren">)</span> → list<a class="headerlink" href="#past.builtins.map" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of the results of applying the function to the
items of the argument sequence(s). If more than one sequence is
given, the function is called with an argument list consisting of
the corresponding item of each sequence, substituting None for
missing values when not all sequences have the same length. If
the function is None, return a list of the items of the sequence
(or a list of tuples if more than one sequence).</p>
<p>Test cases:
>>> oldmap(None, ‘hello world’)
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’, ‘ ‘, ‘w’, ‘o’, ‘r’, ‘l’, ‘d’]</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">oldmap</span><span class="p">(</span><span class="bp">None</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="go">[0, 1, 2, 3]</span>
</pre></div>
</div>
<p>More test cases are in past.tests.test_builtins.</p>
</dd></dl>
<dl class="function">
<dt id="past.builtins.reduce">
<code class="descclassname">past.builtins.</code><code class="descname">reduce</code><span class="sig-paren">(</span><em>function</em>, <em>sequence</em><span class="optional">[</span>, <em>initial</em><span class="optional">]</span><span class="sig-paren">)</span> → value<a class="headerlink" href="#past.builtins.reduce" title="Permalink to this definition">¶</a></dt>
<dd><p>Apply a function of two arguments cumulatively to the items of a sequence,
from left to right, so as to reduce the sequence to a single value.
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
((((1+2)+3)+4)+5). If initial is present, it is placed before the items
of the sequence in the calculation, and serves as a default when the
sequence is empty.</p>
</dd></dl>
<dl class="class">
<dt id="past.builtins.basestring">
<em class="property">class </em><code class="descclassname">past.builtins.</code><code class="descname">basestring</code><a class="reference internal" href="_modules/past/types/basestring.html#basestring"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#past.builtins.basestring" title="Permalink to this definition">¶</a></dt>
<dd><p>A minimal backport of the Python 2 basestring type to Py3</p>
</dd></dl>
<dl class="attribute">
<dt id="past.builtins.dict">
<code class="descclassname">past.builtins.</code><code class="descname">dict</code><a class="headerlink" href="#past.builtins.dict" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <code class="xref py py-class docutils literal"><span class="pre">olddict</span></code></p>
</dd></dl>
<dl class="attribute">
<dt id="past.builtins.str">
<code class="descclassname">past.builtins.</code><code class="descname">str</code><a class="headerlink" href="#past.builtins.str" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <code class="xref py py-class docutils literal"><span class="pre">oldstr</span></code></p>
</dd></dl>
<dl class="attribute">
<dt id="past.builtins.long">
<code class="descclassname">past.builtins.</code><code class="descname">long</code><a class="headerlink" href="#past.builtins.long" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference external" href="http://docs.python.org/library/functions.html#int" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">int</span></code></a></p>
</dd></dl>
<dl class="attribute">
<dt id="past.builtins.unicode">
<code class="descclassname">past.builtins.</code><code class="descname">unicode</code><a class="headerlink" href="#past.builtins.unicode" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#past.builtins.str" title="past.builtins.str"><code class="xref py py-class docutils literal"><span class="pre">str</span></code></a></p>
</dd></dl>
<dl class="function">
<dt id="past.builtins.chr">
<code class="descclassname">past.builtins.</code><code class="descname">chr</code><span class="sig-paren">(</span><em>i</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/past/builtins/misc.html#chr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#past.builtins.chr" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a byte-string of one character with ordinal i; 0 <= i <= 256</p>
</dd></dl>
<dl class="function">
<dt id="past.builtins.cmp">
<code class="descclassname">past.builtins.</code><code class="descname">cmp</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span> → integer<a class="reference internal" href="_modules/past/builtins/misc.html#cmp"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#past.builtins.cmp" title="Permalink to this definition">¶</a></dt>
<dd><p>Return negative if x<y, zero if x==y, positive if x>y.</p>
</dd></dl>
<dl class="function">
<dt id="past.builtins.execfile">
<code class="descclassname">past.builtins.</code><code class="descname">execfile</code><span class="sig-paren">(</span><em>filename</em>, <em>myglobals=None</em>, <em>mylocals=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/past/builtins/misc.html#execfile"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#past.builtins.execfile" title="Permalink to this definition">¶</a></dt>
<dd><p>Read and execute a Python script from a file in the given namespaces.
The globals and locals are dictionaries, defaulting to the current
globals and locals. If only globals is given, locals defaults to it.</p>
</dd></dl>
<dl class="function">
<dt id="past.builtins.intern">
<code class="descclassname">past.builtins.</code><code class="descname">intern</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span> → string<a class="headerlink" href="#past.builtins.intern" title="Permalink to this definition">¶</a></dt>
<dd><p><a href="#id1"><span class="problematic" id="id2">``</span></a>Intern’’ the given string. This enters the string in the (global)
table of interned strings whose purpose is to speed up dictionary lookups.
Return the string itself or the previously interned string object with the
same value.</p>
</dd></dl>
<dl class="function">
<dt id="past.builtins.raw_input">
<code class="descclassname">past.builtins.</code><code class="descname">raw_input</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#past.builtins.raw_input" title="Permalink to this definition">¶</a></dt>
<dd><p>input([prompt]) -> string</p>
<p>Read a string from standard input. The trailing newline is stripped.
If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
On Unix, GNU readline is used if enabled. The prompt string, if given,
is printed without a trailing newline before reading.</p>
</dd></dl>
<dl class="function">
<dt id="past.builtins.reload">
<code class="descclassname">past.builtins.</code><code class="descname">reload</code><span class="sig-paren">(</span><em>module</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/imp.html#reload"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#past.builtins.reload" title="Permalink to this definition">¶</a></dt>
<dd><p><strong>DEPRECATED</strong></p>
<p>Reload the module and return it.</p>
<p>The module must have been successfully imported before.</p>
</dd></dl>
<dl class="function">
<dt id="past.builtins.unichr">
<code class="descclassname">past.builtins.</code><code class="descname">unichr</code><span class="sig-paren">(</span><em>i</em><span class="sig-paren">)</span><a class="headerlink" href="#past.builtins.unichr" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a byte-string of one character with ordinal i; 0 <= i <= 256</p>
</dd></dl>
<dl class="attribute">
<dt id="past.builtins.xrange">
<code class="descclassname">past.builtins.</code><code class="descname">xrange</code><a class="headerlink" href="#past.builtins.xrange" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <code class="xref py py-class docutils literal"><span class="pre">range</span></code></p>
</dd></dl>
</div>
<div class="section" id="module-past.types">
<span id="forward-ported-types-from-python-2"></span><h2><a class="toc-backref" href="#id13">Forward-ported types from Python 2</a><a class="headerlink" href="#module-past.types" title="Permalink to this headline">¶</a></h2>
<p>Forward-ports of types from Python 2 for use with Python 3:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">basestring</span></code>: equivalent to <code class="docutils literal"><span class="pre">(str,</span> <span class="pre">bytes)</span></code> in <code class="docutils literal"><span class="pre">isinstance</span></code> checks</li>
<li><code class="docutils literal"><span class="pre">dict</span></code>: with list-producing .keys() etc. methods</li>
<li><code class="docutils literal"><span class="pre">str</span></code>: bytes-like, but iterating over them doesn’t product integers</li>
<li><code class="docutils literal"><span class="pre">long</span></code>: alias of Py3 int with <code class="docutils literal"><span class="pre">L</span></code> suffix in the <code class="docutils literal"><span class="pre">repr</span></code></li>
<li><code class="docutils literal"><span class="pre">unicode</span></code>: alias of Py3 str with <code class="docutils literal"><span class="pre">u</span></code> prefix in the <code class="docutils literal"><span class="pre">repr</span></code></li>
</ul>
<dl class="class">
<dt id="past.types.basestring">
<em class="property">class </em><code class="descclassname">past.types.</code><code class="descname">basestring</code><a class="reference internal" href="_modules/past/types/basestring.html#basestring"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#past.types.basestring" title="Permalink to this definition">¶</a></dt>
<dd><p>A minimal backport of the Python 2 basestring type to Py3</p>
</dd></dl>
<dl class="class">
<dt id="past.types.olddict">
<em class="property">class </em><code class="descclassname">past.types.</code><code class="descname">olddict</code><a class="reference internal" href="_modules/past/types/olddict.html#olddict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#past.types.olddict" title="Permalink to this definition">¶</a></dt>
<dd><p>A backport of the Python 3 dict object to Py2</p>
<dl class="method">
<dt id="past.types.olddict.has_key">
<code class="descname">has_key</code><span class="sig-paren">(</span><em>k</em><span class="sig-paren">)</span> → True if D has a key k, else False<a class="reference internal" href="_modules/past/types/olddict.html#olddict.has_key"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#past.types.olddict.has_key" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="method">
<dt id="past.types.olddict.iteritems">
<code class="descname">iteritems</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#past.types.olddict.iteritems" title="Permalink to this definition">¶</a></dt>
<dd><p>D.items() -> a set-like object providing a view on D’s items</p>
</dd></dl>
<dl class="method">
<dt id="past.types.olddict.iterkeys">
<code class="descname">iterkeys</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#past.types.olddict.iterkeys" title="Permalink to this definition">¶</a></dt>
<dd><p>D.keys() -> a set-like object providing a view on D’s keys</p>
</dd></dl>
<dl class="method">
<dt id="past.types.olddict.itervalues">
<code class="descname">itervalues</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#past.types.olddict.itervalues" title="Permalink to this definition">¶</a></dt>
<dd><p>D.values() -> an object providing a view on D’s values</p>
</dd></dl>
<dl class="method">
<dt id="past.types.olddict.viewitems">
<code class="descname">viewitems</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#past.types.olddict.viewitems" title="Permalink to this definition">¶</a></dt>
<dd><p>D.items() -> a set-like object providing a view on D’s items</p>
</dd></dl>
<dl class="method">
<dt id="past.types.olddict.viewkeys">
<code class="descname">viewkeys</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#past.types.olddict.viewkeys" title="Permalink to this definition">¶</a></dt>
<dd><p>D.keys() -> a set-like object providing a view on D’s keys</p>
</dd></dl>
<dl class="method">
<dt id="past.types.olddict.viewvalues">
<code class="descname">viewvalues</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#past.types.olddict.viewvalues" title="Permalink to this definition">¶</a></dt>
<dd><p>D.values() -> an object providing a view on D’s values</p>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="past.types.oldstr">
<em class="property">class </em><code class="descclassname">past.types.</code><code class="descname">oldstr</code><a class="reference internal" href="_modules/past/types/oldstr.html#oldstr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#past.types.oldstr" title="Permalink to this definition">¶</a></dt>
<dd><p>A forward port of the Python 2 8-bit string object to Py3</p>
</dd></dl>
<dl class="attribute">
<dt id="past.types.long">
<code class="descclassname">past.types.</code><code class="descname">long</code><a class="headerlink" href="#past.types.long" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference external" href="http://docs.python.org/library/functions.html#int" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">int</span></code></a></p>
</dd></dl>
<dl class="attribute">
<dt id="past.types.unicode">
<code class="descclassname">past.types.</code><code class="descname">unicode</code><a class="headerlink" href="#past.types.unicode" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference external" href="http://docs.python.org/library/functions.html#str" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">str</span></code></a></p>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<p class="pull-right">
<a href="#">Back to top</a>
</p>
<p>
© Copyright 2013-2015, Python Charmers Pty Ltd, Australia.<br/>
</p>
</div>
</footer>
<div class="footer">
<script type="text/javascript">
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ?
'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();
</script>
</div>
</body>
</html>
|