/usr/share/doc/python3-postgresql/html/_modules/postgresql/api.html is in python3-postgresql 1.1.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>postgresql.api — py-postgresql 1.1.0 documentation</title>
<link rel="stylesheet" href="../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../',
VERSION: '1.1.0',
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>
<link rel="top" title="py-postgresql 1.1.0 documentation" href="../../index.html" />
<link rel="up" title="postgresql" href="../postgresql.html" />
<link rel="stylesheet" href="_static/unsuck.css" type="text/css" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">py-postgresql 1.1.0 documentation</a> »</li>
<li><a href="../index.html" >Module code</a> »</li>
<li><a href="../postgresql.html" accesskey="U">postgresql</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<h1>Source code for postgresql.api</h1><div class="highlight"><pre>
<span class="c">##</span>
<span class="c"># .api - ABCs for database interface elements</span>
<span class="c">##</span>
<span class="sd">"""</span>
<span class="sd">Application Programmer Interfaces for PostgreSQL.</span>
<span class="sd">``postgresql.api`` is a collection of Python APIs for the PostgreSQL DBMS. It</span>
<span class="sd">is designed to take full advantage of PostgreSQL's features to provide the</span>
<span class="sd">Python programmer with substantial convenience.</span>
<span class="sd">This module is used to define "PG-API". It creates a set of ABCs</span>
<span class="sd">that makes up the basic interfaces used to work with a PostgreSQL server.</span>
<span class="sd">"""</span>
<span class="kn">import</span> <span class="nn">collections</span>
<span class="kn">import</span> <span class="nn">abc</span>
<span class="kn">from</span> <span class="nn">.python.element</span> <span class="kn">import</span> <span class="n">Element</span>
<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span>
<span class="s">'Message'</span><span class="p">,</span>
<span class="s">'Statement'</span><span class="p">,</span>
<span class="s">'Chunks'</span><span class="p">,</span>
<span class="s">'Cursor'</span><span class="p">,</span>
<span class="s">'Connector'</span><span class="p">,</span>
<span class="s">'Category'</span><span class="p">,</span>
<span class="s">'Database'</span><span class="p">,</span>
<span class="s">'TypeIO'</span><span class="p">,</span>
<span class="s">'Connection'</span><span class="p">,</span>
<span class="s">'Transaction'</span><span class="p">,</span>
<span class="s">'Settings'</span><span class="p">,</span>
<span class="s">'StoredProcedure'</span><span class="p">,</span>
<span class="s">'Driver'</span><span class="p">,</span>
<span class="s">'Installation'</span><span class="p">,</span>
<span class="s">'Cluster'</span><span class="p">,</span>
<span class="p">]</span>
<div class="viewcode-block" id="Message"><a class="viewcode-back" href="../../reference.html#postgresql.api.Message">[docs]</a><span class="k">class</span> <span class="nc">Message</span><span class="p">(</span><span class="n">Element</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> A message emitted by PostgreSQL.</span>
<span class="sd"> A message being a NOTICE, WARNING, INFO, etc.</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">'MESSAGE'</span>
<span class="n">severities</span> <span class="o">=</span> <span class="p">(</span>
<span class="s">'DEBUG'</span><span class="p">,</span>
<span class="s">'INFO'</span><span class="p">,</span>
<span class="s">'NOTICE'</span><span class="p">,</span>
<span class="s">'WARNING'</span><span class="p">,</span>
<span class="s">'ERROR'</span><span class="p">,</span>
<span class="s">'FATAL'</span><span class="p">,</span>
<span class="s">'PANIC'</span><span class="p">,</span>
<span class="p">)</span>
<span class="n">sources</span> <span class="o">=</span> <span class="p">(</span>
<span class="s">'SERVER'</span><span class="p">,</span>
<span class="s">'CLIENT'</span><span class="p">,</span>
<span class="p">)</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Message.source"><a class="viewcode-back" href="../../reference.html#postgresql.api.Message.source">[docs]</a> <span class="k">def</span> <span class="nf">source</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Where the message originated from. Normally, 'SERVER', but sometimes</span>
<span class="sd"> 'CLIENT'.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Message.code"><a class="viewcode-back" href="../../reference.html#postgresql.api.Message.code">[docs]</a> <span class="k">def</span> <span class="nf">code</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The SQL state code of the message.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Message.message"><a class="viewcode-back" href="../../reference.html#postgresql.api.Message.message">[docs]</a> <span class="k">def</span> <span class="nf">message</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The primary message string.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Message.details"><a class="viewcode-back" href="../../reference.html#postgresql.api.Message.details">[docs]</a> <span class="k">def</span> <span class="nf">details</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">dict</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The additional details given with the message. Common keys *should* be the</span>
<span class="sd"> following:</span>
<span class="sd"> * 'severity'</span>
<span class="sd"> * 'context'</span>
<span class="sd"> * 'detail'</span>
<span class="sd"> * 'hint'</span>
<span class="sd"> * 'file'</span>
<span class="sd"> * 'line'</span>
<span class="sd"> * 'function'</span>
<span class="sd"> * 'position'</span>
<span class="sd"> * 'internal_position'</span>
<span class="sd"> * 'internal_query'</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Message.isconsistent"><a class="viewcode-back" href="../../reference.html#postgresql.api.Message.isconsistent">[docs]</a> <span class="k">def</span> <span class="nf">isconsistent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Whether the fields of the `other` Message object is consistent with the</span>
<span class="sd"> fields of `self`.</span>
<span class="sd"> This *must* return the result of the comparison of code, source, message,</span>
<span class="sd"> and details.</span>
<span class="sd"> This method is provided as the alternative to overriding equality;</span>
<span class="sd"> often, pointer equality is the desirable means for comparison, but</span>
<span class="sd"> equality of the fields is also necessary.</span>
<span class="sd"> """</span>
</div></div>
<span class="k">class</span> <span class="nc">Result</span><span class="p">(</span><span class="n">Element</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> A result is an object managing the results of a prepared statement.</span>
<span class="sd"> These objects represent a binding of parameters to a given statement object.</span>
<span class="sd"> For results that were constructed on the server and a reference passed back</span>
<span class="sd"> to the client, statement and parameters may be None.</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">'RESULT'</span>
<span class="n">_e_factors</span> <span class="o">=</span> <span class="p">(</span><span class="s">'statement'</span><span class="p">,</span> <span class="s">'parameters'</span><span class="p">,</span> <span class="s">'cursor_id'</span><span class="p">)</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="bp">None</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Close the Result handle.</span>
<span class="sd"> """</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">cursor_id</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The cursor's identifier.</span>
<span class="sd"> """</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">sql_column_types</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> The type of the columns produced by the cursor.</span>
<span class="sd"> A sequence of `str` objects stating the SQL type name::</span>
<span class="sd"> ['INTEGER', 'CHARACTER VARYING', 'INTERVAL']</span>
<span class="sd"> """</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">pg_column_types</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="nb">int</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> The type Oids of the columns produced by the cursor.</span>
<span class="sd"> A sequence of `int` objects stating the SQL type name::</span>
<span class="sd"> [27, 28]</span>
<span class="sd"> """</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">column_names</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> The attribute names of the columns produced by the cursor.</span>
<span class="sd"> A sequence of `str` objects stating the column name::</span>
<span class="sd"> ['column1', 'column2', 'emp_name']</span>
<span class="sd"> """</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">column_types</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> The Python types of the columns produced by the cursor.</span>
<span class="sd"> A sequence of type objects::</span>
<span class="sd"> [<class 'int'>, <class 'str'>]</span>
<span class="sd"> """</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">(</span><span class="nb">tuple</span><span class="p">,</span> <span class="bp">None</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> The parameters bound to the cursor. `None`, if unknown and an empty tuple</span>
<span class="sd"> `()`, if no parameters were given.</span>
<span class="sd"> These should be the *original* parameters given to the invoked statement.</span>
<span class="sd"> This should only be `None` when the cursor is created from an identifier,</span>
<span class="sd"> `postgresql.api.Database.cursor_from_id`.</span>
<span class="sd"> """</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">statement</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">(</span><span class="s">"Statement"</span><span class="p">,</span> <span class="bp">None</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> The query object used to create the cursor. `None`, if unknown.</span>
<span class="sd"> This should only be `None` when the cursor is created from an identifier,</span>
<span class="sd"> `postgresql.api.Database.cursor_from_id`.</span>
<span class="sd"> """</span>
<span class="k">class</span> <span class="nc">Chunks</span><span class="p">(</span>
<span class="n">Result</span><span class="p">,</span>
<span class="n">collections</span><span class="o">.</span><span class="n">Iterator</span><span class="p">,</span>
<span class="n">collections</span><span class="o">.</span><span class="n">Iterable</span><span class="p">,</span>
<span class="p">):</span>
<span class="k">pass</span>
<div class="viewcode-block" id="Cursor"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cursor">[docs]</a><span class="k">class</span> <span class="nc">Cursor</span><span class="p">(</span>
<span class="n">Result</span><span class="p">,</span>
<span class="n">collections</span><span class="o">.</span><span class="n">Iterator</span><span class="p">,</span>
<span class="n">collections</span><span class="o">.</span><span class="n">Iterable</span><span class="p">,</span>
<span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> A `Cursor` object is an interface to a sequence of tuples(rows). A result</span>
<span class="sd"> set. Cursors publish a file-like interface for reading tuples from a cursor</span>
<span class="sd"> declared on the database.</span>
<span class="sd"> `Cursor` objects are created by invoking the `Statement.declare`</span>
<span class="sd"> method or by opening a cursor using an identifier via the</span>
<span class="sd"> `Database.cursor_from_id` method.</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">'CURSOR'</span>
<span class="n">_seek_whence_map</span> <span class="o">=</span> <span class="p">{</span>
<span class="mi">0</span> <span class="p">:</span> <span class="s">'ABSOLUTE'</span><span class="p">,</span>
<span class="mi">1</span> <span class="p">:</span> <span class="s">'RELATIVE'</span><span class="p">,</span>
<span class="mi">2</span> <span class="p">:</span> <span class="s">'FROM_END'</span><span class="p">,</span>
<span class="mi">3</span> <span class="p">:</span> <span class="s">'FORWARD'</span><span class="p">,</span>
<span class="mi">4</span> <span class="p">:</span> <span class="s">'BACKWARD'</span>
<span class="p">}</span>
<span class="n">_direction_map</span> <span class="o">=</span> <span class="p">{</span>
<span class="bp">True</span> <span class="p">:</span> <span class="s">'FORWARD'</span><span class="p">,</span>
<span class="bp">False</span> <span class="p">:</span> <span class="s">'BACKWARD'</span><span class="p">,</span>
<span class="p">}</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cursor.clone"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cursor.clone">[docs]</a> <span class="k">def</span> <span class="nf">clone</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="s">"Cursor"</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Create a new cursor using the same factors as `self`.</span>
<span class="sd"> """</span>
</div>
<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="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cursor.direction"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cursor.direction">[docs]</a> <span class="k">def</span> <span class="nf">direction</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The default `direction` argument for read().</span>
<span class="sd"> When `True` reads are FORWARD.</span>
<span class="sd"> When `False` reads are BACKWARD.</span>
<span class="sd"> Cursor operation option.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cursor.read"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cursor.read">[docs]</a> <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
<span class="n">quantity</span> <span class="p">:</span> <span class="s">"Number of rows to read"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">direction</span> <span class="p">:</span> <span class="s">"Direction to fetch in, defaults to `self.direction`"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="s">"Row"</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> Read, fetch, the specified number of rows and return them in a list.</span>
<span class="sd"> If quantity is `None`, all records will be fetched.</span>
<span class="sd"> `direction` can be used to override the default configured direction.</span>
<span class="sd"> This alters the cursor's position.</span>
<span class="sd"> Read does not directly correlate to FETCH. If zero is given as the</span>
<span class="sd"> quantity, an empty sequence *must* be returned.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</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="o">-></span> <span class="s">"Row"</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Get the next tuple in the cursor.</span>
<span class="sd"> Advances the cursor position by one.</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cursor.seek"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cursor.seek">[docs]</a> <span class="k">def</span> <span class="nf">seek</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">whence</span> <span class="o">=</span> <span class="s">'ABSOLUTE'</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Set the cursor's position to the given offset with respect to the</span>
<span class="sd"> whence parameter and the configured direction.</span>
<span class="sd"> Whence values:</span>
<span class="sd"> ``0`` or ``"ABSOLUTE"``</span>
<span class="sd"> Absolute.</span>
<span class="sd"> ``1`` or ``"RELATIVE"``</span>
<span class="sd"> Relative.</span>
<span class="sd"> ``2`` or ``"FROM_END"``</span>
<span class="sd"> Absolute from end.</span>
<span class="sd"> ``3`` or ``"FORWARD"``</span>
<span class="sd"> Relative forward.</span>
<span class="sd"> ``4`` or ``"BACKWARD"``</span>
<span class="sd"> Relative backward.</span>
<span class="sd"> Direction effects whence. If direction is BACKWARD, ABSOLUTE positioning</span>
<span class="sd"> will effectively be FROM_END, RELATIVE's position will be negated, and</span>
<span class="sd"> FROM_END will effectively be ABSOLUTE.</span>
<span class="sd"> """</span>
</div></div>
<span class="k">class</span> <span class="nc">Execution</span><span class="p">(</span><span class="n">metaclass</span> <span class="o">=</span> <span class="n">abc</span><span class="o">.</span><span class="n">ABCMeta</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> The abstract class of execution methods.</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">parameters</span> <span class="p">:</span> <span class="s">"Positional Parameters"</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="s">"Row"</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> Execute the prepared statement with the given arguments as parameters.</span>
<span class="sd"> Usage:</span>
<span class="sd"> >>> p=db.prepare("SELECT column FROM ttable WHERE key = $1")</span>
<span class="sd"> >>> p('identifier')</span>
<span class="sd"> [...]</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">column</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">parameters</span><span class="p">)</span> <span class="o">-></span> <span class="n">collections</span><span class="o">.</span><span class="n">Iterable</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Return an iterator producing the values of first column of the</span>
<span class="sd"> rows produced by the cursor created from the statement bound with the</span>
<span class="sd"> given parameters.</span>
<span class="sd"> Column iterators are never scrollable.</span>
<span class="sd"> Supporting cursors will be WITH HOLD when outside of a transaction to</span>
<span class="sd"> allow cross-transaction access.</span>
<span class="sd"> `column` is designed for the situations involving large data sets.</span>
<span class="sd"> Each iteration returns a single value.</span>
<span class="sd"> column expressed in sibling terms::</span>
<span class="sd"> return map(operator.itemgetter(0), self.rows(*parameters))</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">chunks</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">parameters</span><span class="p">)</span> <span class="o">-></span> <span class="n">collections</span><span class="o">.</span><span class="n">Iterable</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Return an iterator producing sequences of rows produced by the cursor</span>
<span class="sd"> created from the statement bound with the given parameters.</span>
<span class="sd"> Chunking iterators are *never* scrollable.</span>
<span class="sd"> Supporting cursors will be WITH HOLD when outside of a transaction.</span>
<span class="sd"> `chunks` is designed for moving large data sets efficiently.</span>
<span class="sd"> Each iteration returns sequences of rows *normally* of length(seq) ==</span>
<span class="sd"> chunksize. If chunksize is unspecified, a default, positive integer will</span>
<span class="sd"> be filled in. The rows contained in the sequences are only required to</span>
<span class="sd"> support the basic `collections.Sequence` interfaces; simple and quick</span>
<span class="sd"> sequence types should be used.</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">rows</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">parameters</span><span class="p">)</span> <span class="o">-></span> <span class="n">collections</span><span class="o">.</span><span class="n">Iterable</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Return an iterator producing rows produced by the cursor</span>
<span class="sd"> created from the statement bound with the given parameters.</span>
<span class="sd"> Row iterators are never scrollable.</span>
<span class="sd"> Supporting cursors will be WITH HOLD when outside of a transaction to</span>
<span class="sd"> allow cross-transaction access.</span>
<span class="sd"> `rows` is designed for the situations involving large data sets.</span>
<span class="sd"> Each iteration returns a single row. Arguably, best implemented::</span>
<span class="sd"> return itertools.chain.from_iterable(self.chunks(*parameters))</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">column</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">parameters</span><span class="p">)</span> <span class="o">-></span> <span class="n">collections</span><span class="o">.</span><span class="n">Iterable</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Return an iterator producing the values of the first column in</span>
<span class="sd"> the cursor created from the statement bound with the given parameters.</span>
<span class="sd"> Column iterators are never scrollable.</span>
<span class="sd"> Supporting cursors will be WITH HOLD when outside of a transaction to</span>
<span class="sd"> allow cross-transaction access.</span>
<span class="sd"> `column` is designed for the situations involving large data sets.</span>
<span class="sd"> Each iteration returns a single value. `column` is equivalent to::</span>
<span class="sd"> return map(operator.itemgetter(0), self.rows(*parameters))</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">declare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">parameters</span><span class="p">)</span> <span class="o">-></span> <span class="n">Cursor</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Return a scrollable cursor with hold using the statement bound with the</span>
<span class="sd"> given parameters.</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">first</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">parameters</span><span class="p">)</span> <span class="o">-></span> <span class="s">"'First' object that is returned by the query"</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Execute the prepared statement with the given arguments as parameters.</span>
<span class="sd"> If the statement returns rows with multiple columns, return the first</span>
<span class="sd"> row. If the statement returns rows with a single column, return the</span>
<span class="sd"> first column in the first row. If the query does not return rows at all,</span>
<span class="sd"> return the count or `None` if no count exists in the completion message.</span>
<span class="sd"> Usage:</span>
<span class="sd"> >>> db.prepare("SELECT * FROM ttable WHERE key = $1").first("somekey")</span>
<span class="sd"> ('somekey', 'somevalue')</span>
<span class="sd"> >>> db.prepare("SELECT 'foo'").first()</span>
<span class="sd"> 'foo'</span>
<span class="sd"> >>> db.prepare("INSERT INTO atable (col) VALUES (1)").first()</span>
<span class="sd"> 1</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">load_rows</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="s">"A iterable of tuples to execute the statement with"</span>
<span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Given an iterable, `iterable`, feed the produced parameters to the</span>
<span class="sd"> query. This is a bulk-loading interface for parameterized queries.</span>
<span class="sd"> Effectively, it is equivalent to:</span>
<span class="sd"> >>> q = db.prepare(sql)</span>
<span class="sd"> >>> for i in iterable:</span>
<span class="sd"> ... q(*i)</span>
<span class="sd"> Its purpose is to allow the implementation to take advantage of the</span>
<span class="sd"> knowledge that a series of parameters are to be loaded so that the</span>
<span class="sd"> operation can be optimized.</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">load_chunks</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="s">"A iterable of chunks of tuples to execute the statement with"</span>
<span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Given an iterable, `iterable`, feed the produced parameters of the chunks</span>
<span class="sd"> produced by the iterable to the query. This is a bulk-loading interface</span>
<span class="sd"> for parameterized queries.</span>
<span class="sd"> Effectively, it is equivalent to:</span>
<span class="sd"> >>> ps = db.prepare(...)</span>
<span class="sd"> >>> for c in iterable:</span>
<span class="sd"> ... for i in c:</span>
<span class="sd"> ... q(*i)</span>
<span class="sd"> Its purpose is to allow the implementation to take advantage of the</span>
<span class="sd"> knowledge that a series of chunks of parameters are to be loaded so</span>
<span class="sd"> that the operation can be optimized.</span>
<span class="sd"> """</span>
<div class="viewcode-block" id="Statement"><a class="viewcode-back" href="../../reference.html#postgresql.api.Statement">[docs]</a><span class="k">class</span> <span class="nc">Statement</span><span class="p">(</span>
<span class="n">Element</span><span class="p">,</span>
<span class="n">collections</span><span class="o">.</span><span class="n">Callable</span><span class="p">,</span>
<span class="n">collections</span><span class="o">.</span><span class="n">Iterable</span><span class="p">,</span>
<span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Instances of `Statement` are returned by the `prepare` method of</span>
<span class="sd"> `Database` instances.</span>
<span class="sd"> A Statement is an Iterable as well as Callable.</span>
<span class="sd"> The Iterable interface is supported for queries that take no arguments at</span>
<span class="sd"> all. It allows the syntax::</span>
<span class="sd"> >>> for x in db.prepare('select * FROM table'):</span>
<span class="sd"> ... pass</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">'STATEMENT'</span>
<span class="n">_e_factors</span> <span class="o">=</span> <span class="p">(</span><span class="s">'database'</span><span class="p">,</span> <span class="s">'statement_id'</span><span class="p">,</span> <span class="s">'string'</span><span class="p">,)</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Statement.statement_id"><a class="viewcode-back" href="../../reference.html#postgresql.api.Statement.statement_id">[docs]</a> <span class="k">def</span> <span class="nf">statement_id</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The statment's identifier.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Statement.string"><a class="viewcode-back" href="../../reference.html#postgresql.api.Statement.string">[docs]</a> <span class="k">def</span> <span class="nf">string</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">object</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The SQL string of the prepared statement.</span>
<span class="sd"> `None` if not available. This can happen in cases where a statement is</span>
<span class="sd"> prepared on the server and a reference to the statement is sent to the</span>
<span class="sd"> client which subsequently uses the statement via the `Database`'s</span>
<span class="sd"> `statement` constructor.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Statement.sql_parameter_types"><a class="viewcode-back" href="../../reference.html#postgresql.api.Statement.sql_parameter_types">[docs]</a> <span class="k">def</span> <span class="nf">sql_parameter_types</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> The type of the parameters required by the statement.</span>
<span class="sd"> A sequence of `str` objects stating the SQL type name::</span>
<span class="sd"> ['INTEGER', 'VARCHAR', 'INTERVAL']</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Statement.sql_column_types"><a class="viewcode-back" href="../../reference.html#postgresql.api.Statement.sql_column_types">[docs]</a> <span class="k">def</span> <span class="nf">sql_column_types</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> The type of the columns produced by the statement.</span>
<span class="sd"> A sequence of `str` objects stating the SQL type name::</span>
<span class="sd"> ['INTEGER', 'VARCHAR', 'INTERVAL']</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Statement.pg_parameter_types"><a class="viewcode-back" href="../../reference.html#postgresql.api.Statement.pg_parameter_types">[docs]</a> <span class="k">def</span> <span class="nf">pg_parameter_types</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="nb">int</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> The type Oids of the parameters required by the statement.</span>
<span class="sd"> A sequence of `int` objects stating the PostgreSQL type Oid::</span>
<span class="sd"> [27, 28]</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Statement.pg_column_types"><a class="viewcode-back" href="../../reference.html#postgresql.api.Statement.pg_column_types">[docs]</a> <span class="k">def</span> <span class="nf">pg_column_types</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="nb">int</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> The type Oids of the columns produced by the statement.</span>
<span class="sd"> A sequence of `int` objects stating the SQL type name::</span>
<span class="sd"> [27, 28]</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Statement.column_names"><a class="viewcode-back" href="../../reference.html#postgresql.api.Statement.column_names">[docs]</a> <span class="k">def</span> <span class="nf">column_names</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> The attribute names of the columns produced by the statement.</span>
<span class="sd"> A sequence of `str` objects stating the column name::</span>
<span class="sd"> ['column1', 'column2', 'emp_name']</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Statement.column_types"><a class="viewcode-back" href="../../reference.html#postgresql.api.Statement.column_types">[docs]</a> <span class="k">def</span> <span class="nf">column_types</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="nb">type</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> The Python types of the columns produced by the statement.</span>
<span class="sd"> A sequence of type objects::</span>
<span class="sd"> [<class 'int'>, <class 'str'>]</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Statement.parameter_types"><a class="viewcode-back" href="../../reference.html#postgresql.api.Statement.parameter_types">[docs]</a> <span class="k">def</span> <span class="nf">parameter_types</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="nb">type</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> The Python types expected of parameters given to the statement.</span>
<span class="sd"> A sequence of type objects::</span>
<span class="sd"> [<class 'int'>, <class 'str'>]</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Statement.clone"><a class="viewcode-back" href="../../reference.html#postgresql.api.Statement.clone">[docs]</a> <span class="k">def</span> <span class="nf">clone</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="s">"Statement"</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Create a new statement object using the same factors as `self`.</span>
<span class="sd"> When used for refreshing plans, the new clone should replace references to</span>
<span class="sd"> the original.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Statement.close"><a class="viewcode-back" href="../../reference.html#postgresql.api.Statement.close">[docs]</a> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="bp">None</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Close the prepared statement releasing resources associated with it.</span>
<span class="sd"> """</span></div></div>
<span class="n">Execution</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">Statement</span><span class="p">)</span>
<span class="n">PreparedStatement</span> <span class="o">=</span> <span class="n">Statement</span>
<div class="viewcode-block" id="StoredProcedure"><a class="viewcode-back" href="../../reference.html#postgresql.api.StoredProcedure">[docs]</a><span class="k">class</span> <span class="nc">StoredProcedure</span><span class="p">(</span>
<span class="n">Element</span><span class="p">,</span>
<span class="n">collections</span><span class="o">.</span><span class="n">Callable</span><span class="p">,</span>
<span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> A function stored on the database.</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">'FUNCTION'</span>
<span class="n">_e_factors</span> <span class="o">=</span> <span class="p">(</span><span class="s">'database'</span><span class="p">,)</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span> <span class="o">-></span> <span class="p">(</span><span class="nb">object</span><span class="p">,</span> <span class="n">Cursor</span><span class="p">,</span> <span class="n">collections</span><span class="o">.</span><span class="n">Iterable</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Execute the procedure with the given arguments. If keyword arguments are</span>
<span class="sd"> passed they must be mapped to the argument whose name matches the key.</span>
<span class="sd"> If any positional arguments are given, they must fill in gaps created by</span>
<span class="sd"> the stated keyword arguments. If too few or too many arguments are</span>
<span class="sd"> given, a TypeError must be raised. If a keyword argument is passed where</span>
<span class="sd"> the procedure does not have a corresponding argument name, then,</span>
<span class="sd"> likewise, a TypeError must be raised.</span>
<span class="sd"> In the case where the `StoredProcedure` references a set returning</span>
<span class="sd"> function(SRF), the result *must* be an iterable. SRFs that return single</span>
<span class="sd"> columns *must* return an iterable of that column; not row data. If the</span>
<span class="sd"> SRF returns a composite(OUT parameters), it *should* return a `Cursor`.</span>
<span class="sd"> """</span>
<span class="c">##</span>
<span class="c"># Arguably, it would be wiser to isolate blocks, and savepoints, but the utility</span>
<span class="c"># of the separation is not significant. It's really</span>
<span class="c"># more interesting as a formality that the user may explicitly state the</span>
<span class="c"># type of the transaction. However, this capability is not completely absent</span>
<span class="c"># from the current interface as the configuration parameters, or lack thereof,</span>
<span class="c"># help imply the expectations.</span></div>
<div class="viewcode-block" id="Transaction"><a class="viewcode-back" href="../../reference.html#postgresql.api.Transaction">[docs]</a><span class="k">class</span> <span class="nc">Transaction</span><span class="p">(</span><span class="n">Element</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> A `Tranaction` is an element that represents a transaction in the session.</span>
<span class="sd"> Once created, it's ready to be started, and subsequently committed or</span>
<span class="sd"> rolled back.</span>
<span class="sd"> Read-only transaction:</span>
<span class="sd"> >>> with db.xact(mode = 'read only'):</span>
<span class="sd"> ... ...</span>
<span class="sd"> Read committed isolation:</span>
<span class="sd"> >>> with db.xact(isolation = 'READ COMMITTED'):</span>
<span class="sd"> ... ...</span>
<span class="sd"> Savepoints are created if inside a transaction block:</span>
<span class="sd"> >>> with db.xact():</span>
<span class="sd"> ... with db.xact():</span>
<span class="sd"> ... ...</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">'XACT'</span>
<span class="n">_e_factors</span> <span class="o">=</span> <span class="p">(</span><span class="s">'database'</span><span class="p">,)</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Transaction.mode"><a class="viewcode-back" href="../../reference.html#postgresql.api.Transaction.mode">[docs]</a> <span class="k">def</span> <span class="nf">mode</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> The mode of the transaction block:</span>
<span class="sd"> START TRANSACTION [ISOLATION] <mode>;</span>
<span class="sd"> The `mode` property is a string and will be directly interpolated into the</span>
<span class="sd"> START TRANSACTION statement.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Transaction.isolation"><a class="viewcode-back" href="../../reference.html#postgresql.api.Transaction.isolation">[docs]</a> <span class="k">def</span> <span class="nf">isolation</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> The isolation level of the transaction block:</span>
<span class="sd"> START TRANSACTION <isolation> [MODE];</span>
<span class="sd"> The `isolation` property is a string and will be directly interpolated into</span>
<span class="sd"> the START TRANSACTION statement.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Transaction.start"><a class="viewcode-back" href="../../reference.html#postgresql.api.Transaction.start">[docs]</a> <span class="k">def</span> <span class="nf">start</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="bp">None</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Start the transaction.</span>
<span class="sd"> If the database is in a transaction block, the transaction should be</span>
<span class="sd"> configured as a savepoint. If any transaction block configuration was</span>
<span class="sd"> applied to the transaction, raise a `postgresql.exceptions.OperationError`.</span>
<span class="sd"> If the database is not in a transaction block, start one using the</span>
<span class="sd"> configuration where:</span>
<span class="sd"> `self.isolation` specifies the ``ISOLATION LEVEL``. Normally, ``READ</span>
<span class="sd"> COMMITTED``, ``SERIALIZABLE``, or ``READ UNCOMMITTED``.</span>
<span class="sd"> `self.mode` specifies the mode of the transaction. Normally, ``READ</span>
<span class="sd"> ONLY`` or ``READ WRITE``.</span>
<span class="sd"> If the transaction is already open, do nothing.</span>
<span class="sd"> If the transaction has been committed or aborted, raise an</span>
<span class="sd"> `postgresql.exceptions.OperationError`.</span>
<span class="sd"> """</span></div>
<span class="n">begin</span> <span class="o">=</span> <span class="n">start</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Transaction.commit"><a class="viewcode-back" href="../../reference.html#postgresql.api.Transaction.commit">[docs]</a> <span class="k">def</span> <span class="nf">commit</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="bp">None</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Commit the transaction.</span>
<span class="sd"> If the transaction is a block, issue a COMMIT statement.</span>
<span class="sd"> If the transaction was started inside a transaction block, it should be</span>
<span class="sd"> identified as a savepoint, and the savepoint should be released.</span>
<span class="sd"> If the transaction has already been committed, do nothing.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Transaction.rollback"><a class="viewcode-back" href="../../reference.html#postgresql.api.Transaction.rollback">[docs]</a> <span class="k">def</span> <span class="nf">rollback</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="bp">None</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Abort the transaction.</span>
<span class="sd"> If the transaction is a savepoint, ROLLBACK TO the savepoint identifier.</span>
<span class="sd"> If the transaction is a transaction block, issue an ABORT.</span>
<span class="sd"> If the transaction has already been aborted, do nothing.</span>
<span class="sd"> """</span></div>
<span class="n">abort</span> <span class="o">=</span> <span class="n">rollback</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Run the `start` method and return self.</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">__exit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">typ</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="n">tb</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> If an exception is indicated by the parameters, run the transaction's</span>
<span class="sd"> `rollback` method iff the database is still available(not closed), and</span>
<span class="sd"> return a `False` value.</span>
<span class="sd"> If an exception is not indicated, but the database's transaction state is</span>
<span class="sd"> in error, run the transaction's `rollback` method and raise a</span>
<span class="sd"> `postgresql.exceptions.InFailedTransactionError`. If the database is</span>
<span class="sd"> unavailable, the `rollback` method should cause a</span>
<span class="sd"> `postgresql.exceptions.ConnectionDoesNotExistError` exception to occur.</span>
<span class="sd"> Otherwise, run the transaction's `commit` method.</span>
<span class="sd"> When the `commit` is ultimately unsuccessful or not ran at all, the purpose</span>
<span class="sd"> of __exit__ is to resolve the error state of the database iff the</span>
<span class="sd"> database is available(not closed) so that more commands can be after the</span>
<span class="sd"> block's exit.</span>
<span class="sd"> """</span>
</div>
<div class="viewcode-block" id="Settings"><a class="viewcode-back" href="../../reference.html#postgresql.api.Settings">[docs]</a><span class="k">class</span> <span class="nc">Settings</span><span class="p">(</span>
<span class="n">Element</span><span class="p">,</span>
<span class="n">collections</span><span class="o">.</span><span class="n">MutableMapping</span>
<span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> A mapping interface to the session's settings. This provides a direct</span>
<span class="sd"> interface to ``SHOW`` or ``SET`` commands. Identifiers and values need</span>
<span class="sd"> not be quoted specially as the implementation must do that work for the</span>
<span class="sd"> user.</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">'SETTINGS'</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Return the setting corresponding to the given key. The result should be</span>
<span class="sd"> consistent with what the ``SHOW`` command returns. If the key does not</span>
<span class="sd"> exist, raise a KeyError.</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">__setitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Set the setting with the given key to the given value. The action should</span>
<span class="sd"> be consistent with the effect of the ``SET`` command.</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Create a context manager applying the given settings on __enter__ and</span>
<span class="sd"> restoring the old values on __exit__.</span>
<span class="sd"> >>> with db.settings(search_path = 'local,public'):</span>
<span class="sd"> ... ...</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Settings.get"><a class="viewcode-back" href="../../reference.html#postgresql.api.Settings.get">[docs]</a> <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">default</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Get the setting with the corresponding key. If the setting does not</span>
<span class="sd"> exist, return the `default`.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Settings.getset"><a class="viewcode-back" href="../../reference.html#postgresql.api.Settings.getset">[docs]</a> <span class="k">def</span> <span class="nf">getset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">keys</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Return a dictionary containing the key-value pairs of the requested</span>
<span class="sd"> settings. If *any* of the keys do not exist, a `KeyError` must be raised</span>
<span class="sd"> with the set of keys that did not exist.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Settings.update"><a class="viewcode-back" href="../../reference.html#postgresql.api.Settings.update">[docs]</a> <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mapping</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> For each key-value pair, incur the effect of the `__setitem__` method.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Settings.keys"><a class="viewcode-back" href="../../reference.html#postgresql.api.Settings.keys">[docs]</a> <span class="k">def</span> <span class="nf">keys</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Return an iterator to all of the settings' keys.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Settings.values"><a class="viewcode-back" href="../../reference.html#postgresql.api.Settings.values">[docs]</a> <span class="k">def</span> <span class="nf">values</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Return an iterator to all of the settings' values.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Settings.items"><a class="viewcode-back" href="../../reference.html#postgresql.api.Settings.items">[docs]</a> <span class="k">def</span> <span class="nf">items</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Return an iterator to all of the setting value pairs.</span>
<span class="sd"> """</span>
</div></div>
<div class="viewcode-block" id="Database"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database">[docs]</a><span class="k">class</span> <span class="nc">Database</span><span class="p">(</span><span class="n">Element</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> The interface to an individual database. `Connection` objects inherit from</span>
<span class="sd"> this</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">'DATABASE'</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.backend_id"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.backend_id">[docs]</a> <span class="k">def</span> <span class="nf">backend_id</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="bp">None</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> The backend's process identifier.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.version_info"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.version_info">[docs]</a> <span class="k">def</span> <span class="nf">version_info</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">tuple</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> A version tuple of the database software similar Python's `sys.version_info`.</span>
<span class="sd"> >>> db.version_info</span>
<span class="sd"> (8, 1, 3, '', 0)</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.client_address"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.client_address">[docs]</a> <span class="k">def</span> <span class="nf">client_address</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="bp">None</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> The client address that the server sees. This is obtainable by querying</span>
<span class="sd"> the ``pg_catalog.pg_stat_activity`` relation.</span>
<span class="sd"> `None` if unavailable.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.client_port"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.client_port">[docs]</a> <span class="k">def</span> <span class="nf">client_port</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="bp">None</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> The client port that the server sees. This is obtainable by querying</span>
<span class="sd"> the ``pg_catalog.pg_stat_activity`` relation.</span>
<span class="sd"> `None` if unavailable.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.xact"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.xact">[docs]</a> <span class="k">def</span> <span class="nf">xact</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
<span class="n">isolation</span> <span class="p">:</span> <span class="s">"ISOLATION LEVEL to use with the transaction"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">mode</span> <span class="p">:</span> <span class="s">"Mode of the transaction, READ ONLY or READ WRITE"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-></span> <span class="n">Transaction</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Create a `Transaction` object using the given keyword arguments as its</span>
<span class="sd"> configuration.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.settings"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.settings">[docs]</a> <span class="k">def</span> <span class="nf">settings</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Settings</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> A `Settings` instance bound to the `Database`.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.do"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.do">[docs]</a> <span class="k">def</span> <span class="nf">do</span><span class="p">(</span><span class="n">language</span><span class="p">,</span> <span class="n">source</span><span class="p">)</span> <span class="o">-></span> <span class="bp">None</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Execute a DO statement using the given language and source.</span>
<span class="sd"> Always returns `None`.</span>
<span class="sd"> Likely to be a function of Connection.execute.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.execute"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.execute">[docs]</a> <span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span> <span class="o">-></span> <span class="bp">None</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Execute an arbitrary block of SQL. Always returns `None` and raise</span>
<span class="sd"> an exception on error.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.prepare"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.prepare">[docs]</a> <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span> <span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">Statement</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Create a new `Statement` instance bound to the connection</span>
<span class="sd"> using the given SQL.</span>
<span class="sd"> >>> s = db.prepare("SELECT 1")</span>
<span class="sd"> >>> c = s()</span>
<span class="sd"> >>> c.next()</span>
<span class="sd"> (1,)</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.statement_from_id"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.statement_from_id">[docs]</a> <span class="k">def</span> <span class="nf">statement_from_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
<span class="n">statement_id</span> <span class="p">:</span> <span class="s">"The statement's identification string."</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-></span> <span class="n">Statement</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Create a `Statement` object that was already prepared on the</span>
<span class="sd"> server. The distinction between this and a regular query is that it</span>
<span class="sd"> must be explicitly closed if it is no longer desired, and it is</span>
<span class="sd"> instantiated using the statement identifier as opposed to the SQL</span>
<span class="sd"> statement itself.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.cursor_from_id"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.cursor_from_id">[docs]</a> <span class="k">def</span> <span class="nf">cursor_from_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
<span class="n">cursor_id</span> <span class="p">:</span> <span class="s">"The cursor's identification string."</span>
<span class="p">)</span> <span class="o">-></span> <span class="n">Cursor</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Create a `Cursor` object from the given `cursor_id` that was already</span>
<span class="sd"> declared on the server.</span>
<span class="sd"> `Cursor` objects created this way must *not* be closed when the object</span>
<span class="sd"> is garbage collected. Rather, the user must explicitly close it for</span>
<span class="sd"> the server resources to be released. This is in contrast to `Cursor`</span>
<span class="sd"> objects that are created by invoking a `Statement` or a SRF</span>
<span class="sd"> `StoredProcedure`.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.proc"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.proc">[docs]</a> <span class="k">def</span> <span class="nf">proc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
<span class="n">procedure_id</span> <span class="p">:</span> \
<span class="s">"The procedure identifier; a valid ``regprocedure`` or Oid."</span>
<span class="p">)</span> <span class="o">-></span> <span class="n">StoredProcedure</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Create a `StoredProcedure` instance using the given identifier.</span>
<span class="sd"> The `proc_id` given can be either an ``Oid``, or a ``regprocedure``</span>
<span class="sd"> that identifies the stored procedure to create the interface for.</span>
<span class="sd"> >>> p = db.proc('version()')</span>
<span class="sd"> >>> p()</span>
<span class="sd"> 'PostgreSQL 8.3.0'</span>
<span class="sd"> >>> qstr = "select oid from pg_proc where proname = 'generate_series'"</span>
<span class="sd"> >>> db.prepare(qstr).first()</span>
<span class="sd"> 1069</span>
<span class="sd"> >>> generate_series = db.proc(1069)</span>
<span class="sd"> >>> list(generate_series(1,5))</span>
<span class="sd"> [1, 2, 3, 4, 5]</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.reset"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.reset">[docs]</a> <span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="bp">None</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Reset the connection into it's original state.</span>
<span class="sd"> Issues a ``RESET ALL`` to the database. If the database supports</span>
<span class="sd"> removing temporary tables created in the session, then remove them.</span>
<span class="sd"> Reapply initial configuration settings such as path.</span>
<span class="sd"> The purpose behind this method is to provide a soft-reconnect method</span>
<span class="sd"> that re-initializes the connection into its original state. One</span>
<span class="sd"> obvious use of this would be in a connection pool where the connection</span>
<span class="sd"> is being recycled.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.notify"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.notify">[docs]</a> <span class="k">def</span> <span class="nf">notify</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">channels</span><span class="p">,</span> <span class="o">**</span><span class="n">channel_and_payload</span><span class="p">)</span> <span class="o">-></span> <span class="nb">int</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> NOTIFY the channels with the given payload.</span>
<span class="sd"> Equivalent to issuing "NOTIFY <channel>" or "NOTIFY <channel>, <payload>"</span>
<span class="sd"> for each item in `channels` and `channel_and_payload`. All NOTIFYs issued</span>
<span class="sd"> *must* occur in the same transaction.</span>
<span class="sd"> The items in `channels` can either be a string or a tuple. If a string,</span>
<span class="sd"> no payload is given, but if an item is a `builtins.tuple`, the second item</span>
<span class="sd"> will be given as the payload. `channels` offers a means to issue NOTIFYs</span>
<span class="sd"> in guaranteed order.</span>
<span class="sd"> The items in `channel_and_payload` are all payloaded NOTIFYs where the</span>
<span class="sd"> keys are the channels and the values are the payloads. Order is undefined.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.listen"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.listen">[docs]</a> <span class="k">def</span> <span class="nf">listen</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">channels</span><span class="p">)</span> <span class="o">-></span> <span class="bp">None</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Start listening to the given channels.</span>
<span class="sd"> Equivalent to issuing "LISTEN <x>" for x in channels.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.unlisten"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.unlisten">[docs]</a> <span class="k">def</span> <span class="nf">unlisten</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">channels</span><span class="p">)</span> <span class="o">-></span> <span class="bp">None</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Stop listening to the given channels.</span>
<span class="sd"> Equivalent to issuing "UNLISTEN <x>" for x in channels.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.listening_channels"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.listening_channels">[docs]</a> <span class="k">def</span> <span class="nf">listening_channels</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="s">"channel name"</span><span class="p">,</span> <span class="o">...</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> Return an *iterator* to all the channels currently being listened to.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Database.iternotifies"><a class="viewcode-back" href="../../reference.html#postgresql.api.Database.iternotifies">[docs]</a> <span class="k">def</span> <span class="nf">iternotifies</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="bp">None</span><span class="p">)</span> <span class="o">-></span> <span class="n">collections</span><span class="o">.</span><span class="n">Iterator</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Return an iterator to the notifications received by the connection. The</span>
<span class="sd"> iterator *must* produce triples in the form ``(channel, payload, pid)``.</span>
<span class="sd"> If timeout is not `None`, `None` *must* be emitted at the specified</span>
<span class="sd"> timeout interval. If the timeout is zero, all the pending notifications</span>
<span class="sd"> *must* be yielded by the iterator and then `StopIteration` *must* be</span>
<span class="sd"> raised.</span>
<span class="sd"> If the connection is closed for any reason, the iterator *must* silently</span>
<span class="sd"> stop by raising `StopIteration`. Further error control is then the</span>
<span class="sd"> responsibility of the user.</span>
<span class="sd"> """</span>
</div></div>
<span class="k">class</span> <span class="nc">TypeIO</span><span class="p">(</span><span class="n">Element</span><span class="p">):</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">'TYPIO'</span>
<span class="k">def</span> <span class="nf">_e_metas</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="p">()</span>
<span class="k">class</span> <span class="nc">SocketFactory</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">fatal_exception</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="ne">Exception</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The exception that is raised by sockets that indicate a fatal error.</span>
<span class="sd"> The exception can be a base exception as the `fatal_error_message` will</span>
<span class="sd"> indicate if that particular exception is actually fatal.</span>
<span class="sd"> """</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">timeout_exception</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="ne">Exception</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The exception raised by the socket when an operation could not be</span>
<span class="sd"> completed due to a configured time constraint.</span>
<span class="sd"> """</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">tryagain_exception</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="ne">Exception</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The exception raised by the socket when an operation was interrupted, but</span>
<span class="sd"> should be tried again.</span>
<span class="sd"> """</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">tryagain</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">err</span> <span class="p">:</span> <span class="ne">Exception</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Whether or not `err` suggests the operation should be tried again.</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">fatal_exception_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">err</span> <span class="p">:</span> <span class="ne">Exception</span><span class="p">)</span> <span class="o">-></span> <span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="bp">None</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> A function returning a string describing the failure, this string will be</span>
<span class="sd"> given to the `postgresql.exceptions.ConnectionFailure` instance that will</span>
<span class="sd"> subsequently be raised by the `Connection` object.</span>
<span class="sd"> Returns `None` when `err` is not actually fatal.</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">socket_secure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">socket</span> <span class="p">:</span> <span class="s">"socket object"</span><span class="p">)</span> <span class="o">-></span> <span class="s">"secured socket"</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Return a reference to the secured socket using the given parameters.</span>
<span class="sd"> If securing the socket for the connector is impossible, the user should</span>
<span class="sd"> never be able to instantiate the connector with parameters requesting</span>
<span class="sd"> security.</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">socket_factory_sequence</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="p">[</span><span class="n">collections</span><span class="o">.</span><span class="n">Callable</span><span class="p">]:</span>
<span class="sd">"""</span>
<span class="sd"> Return a sequence of `SocketCreator`s that `Connection` objects will use to</span>
<span class="sd"> create the socket object.</span>
<span class="sd"> """</span>
<div class="viewcode-block" id="Category"><a class="viewcode-back" href="../../reference.html#postgresql.api.Category">[docs]</a><span class="k">class</span> <span class="nc">Category</span><span class="p">(</span><span class="n">Element</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> A category is an object that initializes the subject connection for a</span>
<span class="sd"> specific purpose.</span>
<span class="sd"> Arguably, a runtime class for use with connections.</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">'CATEGORY'</span>
<span class="n">_e_factors</span> <span class="o">=</span> <span class="p">()</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">connection</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Initialize the given connection in order to conform to the category.</span>
<span class="sd"> """</span>
</div>
<div class="viewcode-block" id="Connector"><a class="viewcode-back" href="../../reference.html#postgresql.api.Connector">[docs]</a><span class="k">class</span> <span class="nc">Connector</span><span class="p">(</span><span class="n">Element</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> A connector is an object providing the necessary information to establish a</span>
<span class="sd"> connection. This includes credentials, database settings, and many times</span>
<span class="sd"> addressing information.</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">'CONNECTOR'</span>
<span class="n">_e_factors</span> <span class="o">=</span> <span class="p">(</span><span class="s">'driver'</span><span class="p">,</span> <span class="s">'category'</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Create and connect. Arguments will be given to the `Connection` instance's</span>
<span class="sd"> `connect` method.</span>
<span class="sd"> """</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">driver</span><span class="o">.</span><span class="n">connection</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</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">user</span> <span class="p">:</span> <span class="s">"required keyword specifying the user name(str)"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">password</span> <span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">database</span> <span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">settings</span> <span class="p">:</span> <span class="p">(</span><span class="nb">dict</span><span class="p">,</span> <span class="p">[(</span><span class="nb">str</span><span class="p">,</span><span class="nb">str</span><span class="p">)])</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">category</span> <span class="p">:</span> <span class="n">Category</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="p">):</span>
<span class="k">if</span> <span class="n">user</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="c"># sure, it's a "required" keyword, makes for better documentation</span>
<span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">"'user' is a required keyword"</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">user</span> <span class="o">=</span> <span class="n">user</span>
<span class="bp">self</span><span class="o">.</span><span class="n">password</span> <span class="o">=</span> <span class="n">password</span>
<span class="bp">self</span><span class="o">.</span><span class="n">database</span> <span class="o">=</span> <span class="n">database</span>
<span class="bp">self</span><span class="o">.</span><span class="n">settings</span> <span class="o">=</span> <span class="n">settings</span>
<span class="bp">self</span><span class="o">.</span><span class="n">category</span> <span class="o">=</span> <span class="n">category</span>
<span class="k">if</span> <span class="n">category</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">category</span><span class="p">,</span> <span class="n">Category</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">"'category' must a be `None` or `postgresql.api.Category`"</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Connection"><a class="viewcode-back" href="../../reference.html#postgresql.api.Connection">[docs]</a><span class="k">class</span> <span class="nc">Connection</span><span class="p">(</span><span class="n">Database</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> The interface to a connection to a PostgreSQL database. This is a</span>
<span class="sd"> `Database` interface with the additional connection management tools that</span>
<span class="sd"> are particular to using a remote database.</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">'CONNECTION'</span>
<span class="n">_e_factors</span> <span class="o">=</span> <span class="p">(</span><span class="s">'connector'</span><span class="p">,)</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Connection.connector"><a class="viewcode-back" href="../../reference.html#postgresql.api.Connection.connector">[docs]</a> <span class="k">def</span> <span class="nf">connector</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Connector</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The :py:class:`Connector` instance facilitating the `Connection` object's</span>
<span class="sd"> communication and initialization.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Connection.query"><a class="viewcode-back" href="../../reference.html#postgresql.api.Connection.query">[docs]</a> <span class="k">def</span> <span class="nf">query</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Execution</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The :py:class:`Execution` instance providing a one-shot query interface::</span>
<span class="sd"> connection.query.<method>(sql, *parameters) == connection.prepare(sql).<method>(*parameters)</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Connection.closed"><a class="viewcode-back" href="../../reference.html#postgresql.api.Connection.closed">[docs]</a> <span class="k">def</span> <span class="nf">closed</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> `True` if the `Connection` is closed, `False` if the `Connection` is</span>
<span class="sd"> open.</span>
<span class="sd"> >>> db.closed</span>
<span class="sd"> True</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Connection.clone"><a class="viewcode-back" href="../../reference.html#postgresql.api.Connection.clone">[docs]</a> <span class="k">def</span> <span class="nf">clone</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="s">"Connection"</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Create another connection using the same factors as `self`. The returned</span>
<span class="sd"> object should be open and ready for use.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Connection.connect"><a class="viewcode-back" href="../../reference.html#postgresql.api.Connection.connect">[docs]</a> <span class="k">def</span> <span class="nf">connect</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="bp">None</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Establish the connection to the server and initialize the category.</span>
<span class="sd"> Does nothing if the connection is already established.</span>
<span class="sd"> """</span>
<span class="n">cat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">connector</span><span class="o">.</span><span class="n">category</span>
<span class="k">if</span> <span class="n">cat</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="n">cat</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Connection.close"><a class="viewcode-back" href="../../reference.html#postgresql.api.Connection.close">[docs]</a> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="bp">None</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Close the connection.</span>
<span class="sd"> Does nothing if the connection is already closed.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Establish the connection and return self.</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">__exit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">typ</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="n">tb</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Closes the connection and returns `False` when an exception is passed in,</span>
<span class="sd"> `True` when `None`.</span>
<span class="sd"> """</span>
</div>
<div class="viewcode-block" id="Driver"><a class="viewcode-back" href="../../reference.html#postgresql.api.Driver">[docs]</a><span class="k">class</span> <span class="nc">Driver</span><span class="p">(</span><span class="n">Element</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> The `Driver` element provides the `Connector` and other information</span>
<span class="sd"> pertaining to the implementation of the driver. Information about what the</span>
<span class="sd"> driver supports is available in instances.</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">"DRIVER"</span>
<span class="n">_e_factors</span> <span class="o">=</span> <span class="p">()</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Driver.connect"><a class="viewcode-back" href="../../reference.html#postgresql.api.Driver.connect">[docs]</a> <span class="k">def</span> <span class="nf">connect</span><span class="p">(</span><span class="o">**</span><span class="n">kw</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Create a connection using the given parameters for the Connector.</span>
<span class="sd"> """</span>
</div></div>
<div class="viewcode-block" id="Installation"><a class="viewcode-back" href="../../reference.html#postgresql.api.Installation">[docs]</a><span class="k">class</span> <span class="nc">Installation</span><span class="p">(</span><span class="n">Element</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Interface to a PostgreSQL installation. Instances would provide various</span>
<span class="sd"> information about an installation of PostgreSQL accessible by the Python</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">"INSTALLATION"</span>
<span class="n">_e_factors</span> <span class="o">=</span> <span class="p">()</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Installation.version"><a class="viewcode-back" href="../../reference.html#postgresql.api.Installation.version">[docs]</a> <span class="k">def</span> <span class="nf">version</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> A version string consistent with what `SELECT version()` would output.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Installation.version_info"><a class="viewcode-back" href="../../reference.html#postgresql.api.Installation.version_info">[docs]</a> <span class="k">def</span> <span class="nf">version_info</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> A tuple specifying the version in a form similar to Python's</span>
<span class="sd"> sys.version_info. (8, 3, 3, 'final', 0)</span>
<span class="sd"> See `postgresql.versionstring`.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Installation.type"><a class="viewcode-back" href="../../reference.html#postgresql.api.Installation.type">[docs]</a> <span class="k">def</span> <span class="nf">type</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> The "type" of PostgreSQL. Normally, the first component of the string</span>
<span class="sd"> returned by pg_config.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Installation.ssl"><a class="viewcode-back" href="../../reference.html#postgresql.api.Installation.ssl">[docs]</a> <span class="k">def</span> <span class="nf">ssl</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> Whether the installation supports SSL.</span>
<span class="sd"> """</span>
</div></div>
<div class="viewcode-block" id="Cluster"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cluster">[docs]</a><span class="k">class</span> <span class="nc">Cluster</span><span class="p">(</span><span class="n">Element</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Interface to a PostgreSQL cluster--a data directory. An implementation of</span>
<span class="sd"> this provides a means to control a server.</span>
<span class="sd"> """</span>
<span class="n">_e_label</span> <span class="o">=</span> <span class="s">'CLUSTER'</span>
<span class="n">_e_factors</span> <span class="o">=</span> <span class="p">(</span><span class="s">'installation'</span><span class="p">,</span> <span class="s">'data_directory'</span><span class="p">)</span>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cluster.installation"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cluster.installation">[docs]</a> <span class="k">def</span> <span class="nf">installation</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Installation</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The installation used by the cluster.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cluster.data_directory"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cluster.data_directory">[docs]</a> <span class="k">def</span> <span class="nf">data_directory</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span>
<span class="sd">"""</span>
<span class="sd"> The path to the data directory of the cluster.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cluster.init"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cluster.init">[docs]</a> <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">initdb</span> <span class="p">:</span> <span class="s">"path to the initdb to use"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">user</span> <span class="p">:</span> <span class="s">"name of the cluster's superuser"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">password</span> <span class="p">:</span> <span class="s">"superuser's password"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">encoding</span> <span class="p">:</span> <span class="s">"the encoding to use for the cluster"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">locale</span> <span class="p">:</span> <span class="s">"the locale to use for the cluster"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">collate</span> <span class="p">:</span> <span class="s">"the collation to use for the cluster"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">ctype</span> <span class="p">:</span> <span class="s">"the ctype to use for the cluster"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">monetary</span> <span class="p">:</span> <span class="s">"the monetary to use for the cluster"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">numeric</span> <span class="p">:</span> <span class="s">"the numeric to use for the cluster"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">time</span> <span class="p">:</span> <span class="s">"the time to use for the cluster"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">text_search_config</span> <span class="p">:</span> <span class="s">"default text search configuration"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="n">xlogdir</span> <span class="p">:</span> <span class="s">"location for the transaction log directory"</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
<span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Create the cluster at the `data_directory` associated with the Cluster</span>
<span class="sd"> instance.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cluster.drop"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cluster.drop">[docs]</a> <span class="k">def</span> <span class="nf">drop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Kill the server and completely remove the data directory.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cluster.start"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cluster.start">[docs]</a> <span class="k">def</span> <span class="nf">start</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Start the cluster.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cluster.stop"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cluster.stop">[docs]</a> <span class="k">def</span> <span class="nf">stop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Signal the server to shutdown.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cluster.kill"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cluster.kill">[docs]</a> <span class="k">def</span> <span class="nf">kill</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Kill the server.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cluster.restart"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cluster.restart">[docs]</a> <span class="k">def</span> <span class="nf">restart</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Restart the cluster.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cluster.wait_until_started"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cluster.wait_until_started">[docs]</a> <span class="k">def</span> <span class="nf">wait_until_started</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
<span class="n">timeout</span> <span class="p">:</span> <span class="s">"maximum time to wait"</span> <span class="o">=</span> <span class="mi">10</span>
<span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> After the start() method is ran, the database may not be ready for use.</span>
<span class="sd"> This method provides a mechanism to block until the cluster is ready for</span>
<span class="sd"> use.</span>
<span class="sd"> If the `timeout` is reached, the method *must* throw a</span>
<span class="sd"> `postgresql.exceptions.ClusterTimeoutError`.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cluster.wait_until_stopped"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cluster.wait_until_stopped">[docs]</a> <span class="k">def</span> <span class="nf">wait_until_stopped</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
<span class="n">timeout</span> <span class="p">:</span> <span class="s">"maximum time to wait"</span> <span class="o">=</span> <span class="mi">10</span>
<span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> After the stop() method is ran, the database may still be running.</span>
<span class="sd"> This method provides a mechanism to block until the cluster is completely</span>
<span class="sd"> shutdown.</span>
<span class="sd"> If the `timeout` is reached, the method *must* throw a</span>
<span class="sd"> `postgresql.exceptions.ClusterTimeoutError`.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@property</span>
<span class="nd">@abc.abstractmethod</span>
<div class="viewcode-block" id="Cluster.settings"><a class="viewcode-back" href="../../reference.html#postgresql.api.Cluster.settings">[docs]</a> <span class="k">def</span> <span class="nf">settings</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> A `Settings` interface to the ``postgresql.conf`` file associated with the</span>
<span class="sd"> cluster.</span>
<span class="sd"> """</span>
</div>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Start the cluster if it's not already running, and wait for it to be</span>
<span class="sd"> readied.</span>
<span class="sd"> """</span>
<span class="nd">@abc.abstractmethod</span>
<span class="k">def</span> <span class="nf">__exit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc</span><span class="p">,</span> <span class="n">val</span><span class="p">,</span> <span class="n">tb</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Stop the cluster and wait for it to shutdown *iff* it was started by the</span>
<span class="sd"> corresponding enter.</span>
<span class="sd"> """</span>
</div>
<span class="n">__docformat__</span> <span class="o">=</span> <span class="s">'reStructuredText'</span>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">'__main__'</span><span class="p">:</span>
<span class="n">help</span><span class="p">(</span><span class="n">__package__</span> <span class="o">+</span> <span class="s">'.api'</span><span class="p">)</span>
<span class="c">##</span>
<span class="c"># vim: ts=3:sw=3:noet:</span>
</pre></div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">py-postgresql 1.1.0 documentation</a> »</li>
<li><a href="../index.html" >Module code</a> »</li>
<li><a href="../postgresql.html" >postgresql</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright Python+Postgres.
Last updated on Mar 31, 2014.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.2.
</div>
</body>
</html>
|