/usr/share/doc/python-repoze.what/html/Manual/ManagingSources.html is in python-repoze.what 1.0.9-2.
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 | <!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>How to manage groups and permission sources — repoze.what 1.0.9 documentation</title>
<link rel="stylesheet" href="../_static/repoze.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.0.9',
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="repoze.what 1.0.9 documentation" href="../index.html" />
<link rel="up" title="The repoze.what Manual" href="index.html" />
<link rel="next" title="repoze.what.plugins – Available plugins for repoze.what" href="Plugins/index.html" />
<link rel="prev" title="Creating your own single predicate checkers" href="Predicates/Writing.html" />
</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 class="right" >
<a href="Plugins/index.html" title="repoze.what.plugins – Available plugins for repoze.what"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="Predicates/Writing.html" title="Creating your own single predicate checkers"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">repoze.what 1.0.9 documentation</a> »</li>
<li><a href="index.html" accesskey="U">The <tt class="docutils literal docutils literal docutils literal docutils literal"><span class="pre">repoze.what</span></tt> Manual</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="module-repoze.what.adapters">
<span id="how-to-manage-groups-and-permission-sources"></span><h1>How to manage groups and permission sources<a class="headerlink" href="#module-repoze.what.adapters" title="Permalink to this headline">¶</a></h1>
<div class="topic">
<p class="topic-title first">Overview</p>
<p>It’s possible for you to manage your groups and permissions under a
<a class="reference internal" href="GettingStarted.html#term-source"><em class="xref std std-term">source</em></a>-independent API and here you will learn how to do it.</p>
</div>
<p><a class="reference internal" href="GettingStarted.html#term-source-adapter"><em class="xref std std-term">Source adapters</em></a> enable you to
retrieve information from your <a class="reference internal" href="GettingStarted.html#term-group-source"><em class="xref std std-term">groups</em></a> and
<a class="reference internal" href="GettingStarted.html#term-permission-source"><em class="xref std std-term">permissions</em></a>, as well as manage them, under an API
absolutely independent of the source type. You may take advantage
of this functionality to manage your sources from your own application or to
write an application-independent front-end to manage groups and permissions
in arbitrary WSGI applications using <a class="reference internal" href="../index.html#module-repoze.what" title="repoze.what: Authorization framework for WSGI applications"><tt class="xref py py-mod docutils literal"><span class="pre">repoze.what</span></tt></a>.</p>
<p>This functionality will also enable you to switch from one back-end to another
with no need to update your code (except for the part where you instance the
source adapter).</p>
<div class="section" id="managing-your-sources">
<h2>Managing your sources<a class="headerlink" href="#managing-your-sources" title="Permalink to this headline">¶</a></h2>
<p>Sources are managed from their respective adapters. For example, to manage the
groups defined in a database, you can use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">repoze.what.plugins.sql</span> <span class="kn">import</span> <span class="n">SqlGroupsAdapter</span>
<span class="kn">from</span> <span class="nn">your_model</span> <span class="kn">import</span> <span class="n">User</span><span class="p">,</span> <span class="n">Group</span><span class="p">,</span> <span class="n">DBSession</span>
<span class="n">groups</span> <span class="o">=</span> <span class="n">SqlGroupsAdapter</span><span class="p">(</span><span class="n">Group</span><span class="p">,</span> <span class="n">User</span><span class="p">,</span> <span class="n">DBSession</span><span class="p">)</span>
</pre></div>
</div>
<p>Or to manage the permissions defined in an XML file, you could use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">repoze.what.plugins.xml</span> <span class="kn">import</span> <span class="n">XMLGroupsAdapter</span>
<span class="n">permissions</span> <span class="o">=</span> <span class="n">XMLGroupsAdapter</span><span class="p">(</span><span class="s">'/path/to/permissions.xml'</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition tip">
<p class="first admonition-title">Tip</p>
<p>As of v1.0.1, you can re-use the same adapters used by <a class="reference internal" href="../index.html#module-repoze.what" title="repoze.what: Authorization framework for WSGI applications"><tt class="xref py py-mod docutils literal"><span class="pre">repoze.what</span></tt></a>
to control access. You will find them in the WSGI environment:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="c"># This is where repoze.what adapters are kept:</span>
<span class="n">adapters</span> <span class="o">=</span> <span class="n">environ</span><span class="p">[</span><span class="s">'repoze.what.adapters'</span><span class="p">]</span>
<span class="c"># Now let's extract the group and permission adapters:</span>
<span class="n">group_adapters</span> <span class="o">=</span> <span class="n">adapters</span><span class="p">[</span><span class="s">'groups'</span><span class="p">]</span>
<span class="n">permission_adapters</span> <span class="o">=</span> <span class="n">adapters</span><span class="p">[</span><span class="s">'permissions'</span><span class="p">]</span>
</pre></div>
</div>
</div>
<div class="section" id="retrieving-all-the-available-sections-from-a-source">
<h3>Retrieving all the available <a class="reference internal" href="GettingStarted.html#term-section"><em class="xref std std-term">sections</em></a> from a source<a class="headerlink" href="#retrieving-all-the-available-sections-from-a-source" title="Permalink to this headline">¶</a></h3>
<p>To get all the groups from the group source above, you may use the code below,
which will return a dictionary whose keys are the name of the groups and the
items are the username of the users that belong to such groups:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">get_all_sections</span><span class="p">()</span>
<span class="go">{u'admins': set([u'gustavo', u'adolfo']), u'developers': set([u'narea'])}</span>
</pre></div>
</div>
<p>And to get all the permissions from the permission source above, you may use
the code below, which will return a dictionary whose keys are the name of the
permissions and the items are the name of the groups that are granted such
permissions:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">permissions</span><span class="o">.</span><span class="n">get_all_sections</span><span class="p">()</span>
<span class="go">{u'upload-images': set([u'admins', u'developers']), u'write-post': set()}</span>
</pre></div>
</div>
</div>
<div class="section" id="retrieving-all-the-items-from-a-given-section">
<h3>Retrieving all the <a class="reference internal" href="GettingStarted.html#term-item"><em class="xref std std-term">items</em></a> from a given <a class="reference internal" href="GettingStarted.html#term-section"><em class="xref std std-term">section</em></a><a class="headerlink" href="#retrieving-all-the-items-from-a-given-section" title="Permalink to this headline">¶</a></h3>
<p>To get all the users that belong to a given group in the group source above,
you may use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">get_section_items</span><span class="p">(</span><span class="s">u'admins'</span><span class="p">)</span>
<span class="go">set([u'gustavo', u'adolfo'])</span>
</pre></div>
</div>
<p>And to get all the groups that are granted a given permission in the permission
source above:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">permissions</span><span class="o">.</span><span class="n">get_section_items</span><span class="p">(</span><span class="s">u'upload-images'</span><span class="p">)</span>
<span class="go">set([u'admins', u'developers'])</span>
</pre></div>
</div>
</div>
<div class="section" id="setting-the-items-of-a-given-section">
<h3>Setting the <a class="reference internal" href="GettingStarted.html#term-item"><em class="xref std std-term">items</em></a> of a given <a class="reference internal" href="GettingStarted.html#term-section"><em class="xref std std-term">section</em></a><a class="headerlink" href="#setting-the-items-of-a-given-section" title="Permalink to this headline">¶</a></h3>
<p>To set the members of a given group in the group source above, you may use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">set_section_items</span><span class="p">(</span><span class="s">u'admins'</span><span class="p">,</span> <span class="p">[</span><span class="s">u'rms'</span><span class="p">,</span> <span class="s">u'guido'</span><span class="p">])</span>
</pre></div>
</div>
<p>And to set the groups that are granted a given permission in the permission
source above:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">permissions</span><span class="o">.</span><span class="n">set_section_items</span><span class="p">(</span><span class="s">u'write-post'</span><span class="p">,</span> <span class="p">[</span><span class="s">u'admins'</span><span class="p">])</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p><tt class="docutils literal"><span class="pre">set_section_items</span></tt> will <cite>override</cite> the previous set of items. See, for
example:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">get_all_sections</span><span class="p">()</span>
<span class="go">{u'admins': set([u'gustavo', u'adolfo']), u'developers': set([u'narea'])}</span>
<span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">set_section_items</span><span class="p">(</span><span class="s">u'admins'</span><span class="p">,</span> <span class="p">[</span><span class="s">u'rms'</span><span class="p">,</span> <span class="s">u'guido'</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">get_all_sections</span><span class="p">()</span>
<span class="go">{u'admins': set([u'rms', u'guido']), u'developers': set([u'narea'])}</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="including-items-in-a-section">
<h3>Including <a class="reference internal" href="GettingStarted.html#term-item"><em class="xref std std-term">items</em></a> in a <a class="reference internal" href="GettingStarted.html#term-section"><em class="xref std std-term">section</em></a><a class="headerlink" href="#including-items-in-a-section" title="Permalink to this headline">¶</a></h3>
<p>To add one the item to a given group of the group source above, you may use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">include_item</span><span class="p">(</span><span class="s">u'admins'</span><span class="p">,</span> <span class="s">u'rms'</span><span class="p">)</span>
</pre></div>
</div>
<p>Or to include many users at once:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">include_items</span><span class="p">(</span><span class="s">u'admins'</span><span class="p">,</span> <span class="p">[</span><span class="s">u'rms'</span><span class="p">,</span> <span class="s">u'guido'</span><span class="p">])</span>
</pre></div>
</div>
<p>And to grant a given permission to one group in the permission source above:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">permissions</span><span class="o">.</span><span class="n">include_item</span><span class="p">(</span><span class="s">u'write-post'</span><span class="p">,</span> <span class="s">u'admins'</span><span class="p">)</span>
</pre></div>
</div>
<p>Or to grant the same permission to many groups at once:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">permissions</span><span class="o">.</span><span class="n">include_items</span><span class="p">(</span><span class="s">u'write-post'</span><span class="p">,</span> <span class="p">[</span><span class="s">u'admins'</span><span class="p">,</span> <span class="s">u'developers'</span><span class="p">])</span>
</pre></div>
</div>
</div>
<div class="section" id="excluding-items-from-a-section">
<h3>Excluding <a class="reference internal" href="GettingStarted.html#term-item"><em class="xref std std-term">items</em></a> from a <a class="reference internal" href="GettingStarted.html#term-section"><em class="xref std std-term">section</em></a><a class="headerlink" href="#excluding-items-from-a-section" title="Permalink to this headline">¶</a></h3>
<p>To remove one the items from a given group of the group source above, you may
use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">exclude_item</span><span class="p">(</span><span class="s">u'admins'</span><span class="p">,</span> <span class="s">u'gustavo'</span><span class="p">)</span>
</pre></div>
</div>
<p>Or to exclude many items at once:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">exclude_items</span><span class="p">(</span><span class="s">u'admins'</span><span class="p">,</span> <span class="p">[</span><span class="s">u'gustavo'</span><span class="p">,</span> <span class="s">u'adolfo'</span><span class="p">])</span>
</pre></div>
</div>
<p>And to deny a given permission to one group in the permission source above:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">permissions</span><span class="o">.</span><span class="n">exclude_item</span><span class="p">(</span><span class="s">u'upload-images'</span><span class="p">,</span> <span class="s">u'developers'</span><span class="p">)</span>
</pre></div>
</div>
<p>Or to grant the same permission to many groups at once:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">permissions</span><span class="o">.</span><span class="n">exclude_items</span><span class="p">(</span><span class="s">u'upload-images'</span><span class="p">,</span> <span class="p">[</span><span class="s">u'admins'</span><span class="p">,</span> <span class="s">u'developers'</span><span class="p">])</span>
</pre></div>
</div>
</div>
<div class="section" id="adding-a-section-to-a-source">
<h3>Adding a <a class="reference internal" href="GettingStarted.html#term-section"><em class="xref std std-term">section</em></a> to a <a class="reference internal" href="GettingStarted.html#term-source"><em class="xref std std-term">source</em></a><a class="headerlink" href="#adding-a-section-to-a-source" title="Permalink to this headline">¶</a></h3>
<p>To create a group in the group source above, you may use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">create_section</span><span class="p">(</span><span class="s">u'designers'</span><span class="p">)</span>
</pre></div>
</div>
<p>And to create a permission in the permission source above:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">permissions</span><span class="o">.</span><span class="n">create_section</span><span class="p">(</span><span class="s">u'edit-post'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="renaming-a-section">
<h3>Renaming a <a class="reference internal" href="GettingStarted.html#term-section"><em class="xref std std-term">section</em></a><a class="headerlink" href="#renaming-a-section" title="Permalink to this headline">¶</a></h3>
<p>To rename a group in the group source above, you may use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">edit_section</span><span class="p">(</span><span class="s">u'designers'</span><span class="p">,</span> <span class="s">u'graphic-designers'</span><span class="p">)</span>
</pre></div>
</div>
<p>And to rename a permission in the permission source above:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">permissions</span><span class="o">.</span><span class="n">edit_section</span><span class="p">(</span><span class="s">u'write-post'</span><span class="p">,</span> <span class="s">u'create-post'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="removing-a-section-from-a-source">
<h3>Removing a <a class="reference internal" href="GettingStarted.html#term-section"><em class="xref std std-term">section</em></a> from a <a class="reference internal" href="GettingStarted.html#term-source"><em class="xref std std-term">source</em></a><a class="headerlink" href="#removing-a-section-from-a-source" title="Permalink to this headline">¶</a></h3>
<p>To remove a group from the group source above, you may use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">delete_section</span><span class="p">(</span><span class="s">u'developers'</span><span class="p">)</span>
</pre></div>
</div>
<p>And to remove a permission from the permission source above:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">permissions</span><span class="o">.</span><span class="n">delete_section</span><span class="p">(</span><span class="s">u'write-post'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="checking-whether-the-source-is-writable">
<h3>Checking whether the <a class="reference internal" href="GettingStarted.html#term-source"><em class="xref std std-term">source</em></a> is writable<a class="headerlink" href="#checking-whether-the-source-is-writable" title="Permalink to this headline">¶</a></h3>
<p>Some adapters may not support writting the source, or some source types may
be read-only (e.g., a source served over HTTP), or some source types may be
writable but the current source itself may be read-only (e.g., a read-only
file). For this reason, you should check whether you can write to the source
– You will get a <a class="reference internal" href="#repoze.what.adapters.SourceError" title="repoze.what.adapters.SourceError"><tt class="xref py py-class docutils literal"><span class="pre">SourceError</span></tt></a> exception if you try to write to a
read-only source.</p>
<p>To check whether the group source above is writable, you may use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">groups</span><span class="o">.</span><span class="n">is_writable</span>
<span class="go">True</span>
</pre></div>
</div>
<p>And to check whether the permission source above is writable:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">permissions</span><span class="o">.</span><span class="n">is_writable</span>
<span class="go">False</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="possible-problems">
<h2>Possible problems<a class="headerlink" href="#possible-problems" title="Permalink to this headline">¶</a></h2>
<p>While dealing with an adapter, the following exceptions may be raised if an
error occurs:</p>
<dl class="exception">
<dt id="repoze.what.adapters.AdapterError">
<em class="property">exception </em><tt class="descclassname">repoze.what.adapters.</tt><tt class="descname">AdapterError</tt><a class="headerlink" href="#repoze.what.adapters.AdapterError" title="Permalink to this definition">¶</a></dt>
<dd><p>Base exception for problems in the source adapters.</p>
<p>It’s never raised directly.</p>
</dd></dl>
<dl class="exception">
<dt id="repoze.what.adapters.SourceError">
<em class="property">exception </em><tt class="descclassname">repoze.what.adapters.</tt><tt class="descname">SourceError</tt><a class="headerlink" href="#repoze.what.adapters.SourceError" title="Permalink to this definition">¶</a></dt>
<dd><p>Exception for problems with the source itself.</p>
<div class="admonition attention">
<p class="first admonition-title">Attention</p>
<p class="last">If you are creating a <a class="reference internal" href="GettingStarted.html#term-source-adapter"><em class="xref std std-term">source adapter</em></a>, this is the only
exception you should raise.</p>
</div>
</dd></dl>
<dl class="exception">
<dt id="repoze.what.adapters.ExistingSectionError">
<em class="property">exception </em><tt class="descclassname">repoze.what.adapters.</tt><tt class="descname">ExistingSectionError</tt><a class="headerlink" href="#repoze.what.adapters.ExistingSectionError" title="Permalink to this definition">¶</a></dt>
<dd><p>Exception raised when trying to add an existing group.</p>
</dd></dl>
<dl class="exception">
<dt id="repoze.what.adapters.NonExistingSectionError">
<em class="property">exception </em><tt class="descclassname">repoze.what.adapters.</tt><tt class="descname">NonExistingSectionError</tt><a class="headerlink" href="#repoze.what.adapters.NonExistingSectionError" title="Permalink to this definition">¶</a></dt>
<dd><p>Exception raised when trying to use a non-existing group.</p>
</dd></dl>
<dl class="exception">
<dt id="repoze.what.adapters.ItemPresentError">
<em class="property">exception </em><tt class="descclassname">repoze.what.adapters.</tt><tt class="descname">ItemPresentError</tt><a class="headerlink" href="#repoze.what.adapters.ItemPresentError" title="Permalink to this definition">¶</a></dt>
<dd><p>Exception raised when trying to add an item to a group that already
contains it.</p>
</dd></dl>
<dl class="exception">
<dt id="repoze.what.adapters.ItemNotPresentError">
<em class="property">exception </em><tt class="descclassname">repoze.what.adapters.</tt><tt class="descname">ItemNotPresentError</tt><a class="headerlink" href="#repoze.what.adapters.ItemNotPresentError" title="Permalink to this definition">¶</a></dt>
<dd><p>Exception raised when trying to remove an item from a group that doesn’t
contain it.</p>
</dd></dl>
</div>
<div class="section" id="writing-your-own-source-adapters">
<h2>Writing your own source adapters<a class="headerlink" href="#writing-your-own-source-adapters" title="Permalink to this headline">¶</a></h2>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">It’s <cite>very</cite> unlikely that you’ll want to write a <a class="reference internal" href="GettingStarted.html#term-source-adapter"><em class="xref std std-term">source adapter</em></a>, so
if you get bored reading this section, it’s absolutely safe for you to skip
it and come back later if you <cite>ever</cite> need to create an adapter.</p>
</div>
<p>Both <a class="reference internal" href="GettingStarted.html#term-group-adapter"><em class="xref std std-term">group</em></a> and <a class="reference internal" href="GettingStarted.html#term-permission-adapter"><em class="xref std std-term">permission</em></a>
<a class="reference internal" href="GettingStarted.html#term-source-adapter"><em class="xref std std-term">adapters</em></a> must extend the abstract class
<a class="reference internal" href="#repoze.what.adapters.BaseSourceAdapter" title="repoze.what.adapters.BaseSourceAdapter"><tt class="xref py py-class docutils literal"><span class="pre">BaseSourceAdapter</span></tt></a>:</p>
<dl class="class">
<dt id="repoze.what.adapters.BaseSourceAdapter">
<em class="property">class </em><tt class="descclassname">repoze.what.adapters.</tt><tt class="descname">BaseSourceAdapter</tt><big>(</big><em>writable=True</em><big>)</big><a class="headerlink" href="#repoze.what.adapters.BaseSourceAdapter" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for <a class="reference internal" href="GettingStarted.html#term-source-adapter"><em class="xref std std-term">source adapters</em></a>.</p>
<p>Please note that these abstract methods may only raise one exception:
<a class="reference internal" href="#repoze.what.adapters.SourceError" title="repoze.what.adapters.SourceError"><tt class="xref py py-class docutils literal"><span class="pre">SourceError</span></tt></a>, which is raised if there was a problem while dealing
with the source. They may not raise other exceptions because they should not
validate anything but the source (not even the parameters they get).</p>
<dl class="attribute">
<dt>
<tt class="descname">is_writable = True</tt></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body">bool</td>
</tr>
</tbody>
</table>
<p>Whether the adapter can write to the source.</p>
<p>If the source type handled by your adapter doesn’t support write
access, or if your adapter itself doesn’t support writting to the
source (yet), then you should set this value to <tt class="docutils literal"><span class="pre">False</span></tt> in the class
itself; it will get overriden if the <tt class="docutils literal"><span class="pre">writable</span></tt> parameter in
<a class="reference internal" href="#repoze.what.adapters.BaseSourceAdapter.__init__" title="repoze.what.adapters.BaseSourceAdapter.__init__"><tt class="xref py py-meth docutils literal"><span class="pre">the</span> <span class="pre">contructor</span></tt></a> is set, unless you
explicitly disable that parameter:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># ...</span>
<span class="k">class</span> <span class="nc">MyFakeAdapter</span><span class="p">(</span><span class="n">BaseSourceAdapter</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">():</span>
<span class="nb">super</span><span class="p">(</span><span class="n">MyFakeAdapter</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">writable</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="c"># ...</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>If it’s <tt class="docutils literal"><span class="pre">False</span></tt>, then you don’t have to define the methods that
modify the source because they won’t be used:</p>
<ul class="last simple">
<li><a class="reference internal" href="#repoze.what.adapters.BaseSourceAdapter._include_items" title="repoze.what.adapters.BaseSourceAdapter._include_items"><tt class="xref py py-meth docutils literal"><span class="pre">_include_items()</span></tt></a></li>
<li><a class="reference internal" href="#repoze.what.adapters.BaseSourceAdapter._exclude_items" title="repoze.what.adapters.BaseSourceAdapter._exclude_items"><tt class="xref py py-meth docutils literal"><span class="pre">_exclude_items()</span></tt></a></li>
<li><a class="reference internal" href="#repoze.what.adapters.BaseSourceAdapter._create_section" title="repoze.what.adapters.BaseSourceAdapter._create_section"><tt class="xref py py-meth docutils literal"><span class="pre">_create_section()</span></tt></a></li>
<li><a class="reference internal" href="#repoze.what.adapters.BaseSourceAdapter._edit_section" title="repoze.what.adapters.BaseSourceAdapter._edit_section"><tt class="xref py py-meth docutils literal"><span class="pre">_edit_section()</span></tt></a></li>
<li><a class="reference internal" href="#repoze.what.adapters.BaseSourceAdapter._delete_section" title="repoze.what.adapters.BaseSourceAdapter._delete_section"><tt class="xref py py-meth docutils literal"><span class="pre">_delete_section()</span></tt></a></li>
</ul>
</div>
</dd></dl>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Do not ever cache the results – that is <a class="reference internal" href="#repoze.what.adapters.BaseSourceAdapter" title="repoze.what.adapters.BaseSourceAdapter"><tt class="xref py py-class docutils literal"><span class="pre">BaseSourceAdapter</span></tt></a>‘s
job. It requests a given datum once, not multiple times, thanks to
its internal cache.</p>
</div>
<dl class="method">
<dt id="repoze.what.adapters.BaseSourceAdapter.__init__">
<tt class="descname">__init__</tt><big>(</big><em>writable=True</em><big>)</big><a class="headerlink" href="#repoze.what.adapters.BaseSourceAdapter.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>Run common setup for source adapters.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>writable</strong> (<em>bool</em>) – Whether the source is writable.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="repoze.what.adapters.BaseSourceAdapter._get_all_sections">
<tt class="descname">_get_all_sections</tt><big>(</big><big>)</big><a class="headerlink" href="#repoze.what.adapters.BaseSourceAdapter._get_all_sections" title="Permalink to this definition">¶</a></dt>
<dd><p>Return all the sections found in the source.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">All the sections found in the source.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">dict</td>
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">Raises SourceError:</th></tr>
<tr class="field-odd field"><td> </td><td class="field-body">If there was a problem with the source while
retrieving the sections.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="repoze.what.adapters.BaseSourceAdapter._get_section_items">
<tt class="descname">_get_section_items</tt><big>(</big><em>section</em><big>)</big><a class="headerlink" href="#repoze.what.adapters.BaseSourceAdapter._get_section_items" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the items of the section called <tt class="docutils literal"><span class="pre">section</span></tt>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>section</strong> (<em>unicode</em>) – The name of the section to be fetched.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The items of the section.</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">set</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Raises SourceError:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body">If there was a problem with the source while
retrieving the section.</td>
</tr>
</tbody>
</table>
<div class="admonition attention">
<p class="first admonition-title">Attention</p>
<p class="last">When implementing this method, don’t check whether the
section really exists; that’s already done when this method is
called.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="repoze.what.adapters.BaseSourceAdapter._find_sections">
<tt class="descname">_find_sections</tt><big>(</big><em>hint</em><big>)</big><a class="headerlink" href="#repoze.what.adapters.BaseSourceAdapter._find_sections" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the sections that meet a given criteria.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>hint</strong> (<em>dict or unicode</em>) – repoze.what’s credentials dictionary or a group name.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The sections that meet the criteria.</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">tuple</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Raises SourceError:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body">If there was a problem with the source while
retrieving the sections.</td>
</tr>
</tbody>
</table>
<p>This method depends on the type of adapter that is implementing it:</p>
<ul class="simple">
<li>If it’s a <tt class="docutils literal"><span class="pre">group</span></tt> source adapter, it returns the groups the
authenticated user belongs to. In this case, hint represents
repoze.what’s credentials dict. Please note that hint is not an
user name because some adapters may need something else to find the
groups the authenticated user belongs to. For example, LDAP adapters
need the full Distinguished Name (DN) in the credentials dict, or a
given adapter may only need the email address, so the user name alone
would be useless in both situations.</li>
<li>If it’s a <tt class="docutils literal"><span class="pre">permission</span></tt> source adapter, it returns the name of the
permissions granted to the group in question; here hint represents
the name of such a group.</li>
</ul>
</dd></dl>
<dl class="method">
<dt id="repoze.what.adapters.BaseSourceAdapter._include_items">
<tt class="descname">_include_items</tt><big>(</big><em>section</em>, <em>items</em><big>)</big><a class="headerlink" href="#repoze.what.adapters.BaseSourceAdapter._include_items" title="Permalink to this definition">¶</a></dt>
<dd><p>Add <tt class="docutils literal"><span class="pre">items</span></tt> to the <tt class="docutils literal"><span class="pre">section</span></tt>, in the source.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>section</strong> (<em>unicode</em>) – The section to contain the items.</li>
<li><strong>items</strong> (<em>tuple</em>) – The new items of the section.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Raises SourceError:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body"><p class="first last">If the items could not be added to the section.</p>
</td>
</tr>
</tbody>
</table>
<div class="admonition attention">
<p class="first admonition-title">Attention</p>
<p class="last">When implementing this method, don’t check whether the
section really exists or the items are already included; that’s
already done when this method is called.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="repoze.what.adapters.BaseSourceAdapter._exclude_items">
<tt class="descname">_exclude_items</tt><big>(</big><em>section</em>, <em>items</em><big>)</big><a class="headerlink" href="#repoze.what.adapters.BaseSourceAdapter._exclude_items" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove <tt class="docutils literal"><span class="pre">items</span></tt> from the <tt class="docutils literal"><span class="pre">section</span></tt>, in the source.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>section</strong> (<em>unicode</em>) – The section that contains the items.</li>
<li><strong>items</strong> (<em>tuple</em>) – The items to be removed from section.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Raises SourceError:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body"><p class="first last">If the items could not be removed from the section.</p>
</td>
</tr>
</tbody>
</table>
<div class="admonition attention">
<p class="first admonition-title">Attention</p>
<p class="last">When implementing this method, don’t check whether the
section really exists or the items are already included; that’s
already done when this method is called.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="repoze.what.adapters.BaseSourceAdapter._item_is_included">
<tt class="descname">_item_is_included</tt><big>(</big><em>section</em>, <em>item</em><big>)</big><a class="headerlink" href="#repoze.what.adapters.BaseSourceAdapter._item_is_included" title="Permalink to this definition">¶</a></dt>
<dd><p>Check whether <tt class="docutils literal"><span class="pre">item</span></tt> is included in <tt class="docutils literal"><span class="pre">section</span></tt>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>section</strong> (<em>unicode</em>) – The name of the item to look for.</li>
<li><strong>section</strong> – The name of the section that may include the item.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Whether the item is included in section or not.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">bool</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Raises SourceError:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body"><p class="first last">If there was a problem with the source.</p>
</td>
</tr>
</tbody>
</table>
<div class="admonition attention">
<p class="first admonition-title">Attention</p>
<p class="last">When implementing this method, don’t check whether the
section really exists; that’s already done when this method is
called.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="repoze.what.adapters.BaseSourceAdapter._create_section">
<tt class="descname">_create_section</tt><big>(</big><em>section</em><big>)</big><a class="headerlink" href="#repoze.what.adapters.BaseSourceAdapter._create_section" title="Permalink to this definition">¶</a></dt>
<dd><p>Add <tt class="docutils literal"><span class="pre">section</span></tt> to the source.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>section</strong> (<em>unicode</em>) – The section name.</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Raises SourceError:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body">If the section could not be added.</td>
</tr>
</tbody>
</table>
<div class="admonition attention">
<p class="first admonition-title">Attention</p>
<p class="last">When implementing this method, don’t check whether the
section already exists; that’s already done when this method is
called.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="repoze.what.adapters.BaseSourceAdapter._edit_section">
<tt class="descname">_edit_section</tt><big>(</big><em>section</em>, <em>new_section</em><big>)</big><a class="headerlink" href="#repoze.what.adapters.BaseSourceAdapter._edit_section" title="Permalink to this definition">¶</a></dt>
<dd><p>Edit <tt class="docutils literal"><span class="pre">section</span></tt>‘s properties.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>section</strong> (<em>unicode</em>) – The current name of the section.</li>
<li><strong>new_section</strong> (<em>unicode</em>) – The new name of the section.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Raises SourceError:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body"><p class="first last">If the section could not be edited.</p>
</td>
</tr>
</tbody>
</table>
<div class="admonition attention">
<p class="first admonition-title">Attention</p>
<p class="last">When implementing this method, don’t check whether the
section really exists; that’s already done when this method is
called.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="repoze.what.adapters.BaseSourceAdapter._delete_section">
<tt class="descname">_delete_section</tt><big>(</big><em>section</em><big>)</big><a class="headerlink" href="#repoze.what.adapters.BaseSourceAdapter._delete_section" title="Permalink to this definition">¶</a></dt>
<dd><p>Delete <tt class="docutils literal"><span class="pre">section</span></tt>.</p>
<p>It removes the <tt class="docutils literal"><span class="pre">section</span></tt> from the source.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>section</strong> (<em>unicode</em>) – The name of the section to be deleted.</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Raises SourceError:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body">If the section could not be deleted.</td>
</tr>
</tbody>
</table>
<div class="admonition attention">
<p class="first admonition-title">Attention</p>
<p class="last">When implementing this method, don’t check whether the
section really exists; that’s already done when this method is
called.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="repoze.what.adapters.BaseSourceAdapter._section_exists">
<tt class="descname">_section_exists</tt><big>(</big><em>section</em><big>)</big><a class="headerlink" href="#repoze.what.adapters.BaseSourceAdapter._section_exists" title="Permalink to this definition">¶</a></dt>
<dd><p>Check whether <tt class="docutils literal"><span class="pre">section</span></tt> is defined in the source.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>section</strong> (<em>unicode</em>) – The name of the section to check.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Whether the section is the defined in the source or not.</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">bool</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Raises SourceError:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body">If there was a problem with the source.</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<div class="section" id="sample-source-adapters">
<h3>Sample <a class="reference internal" href="GettingStarted.html#term-source-adapter"><em class="xref std std-term">source adapters</em></a><a class="headerlink" href="#sample-source-adapters" title="Permalink to this headline">¶</a></h3>
<p>The following class illustrates how a <a class="reference internal" href="GettingStarted.html#term-group-adapter"><em class="xref std std-term">group adapter</em></a> may look like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">repoze.what.adapters</span> <span class="kn">import</span> <span class="n">BaseSourceAdapter</span>
<span class="k">class</span> <span class="nc">FakeGroupSourceAdapter</span><span class="p">(</span><span class="n">BaseSourceAdapter</span><span class="p">):</span>
<span class="sd">"""Mock group source adapter"""</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="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">FakeGroupSourceAdapter</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</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">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">u'admins'</span><span class="p">:</span> <span class="nb">set</span><span class="p">([</span><span class="s">u'rms'</span><span class="p">]),</span>
<span class="s">u'developers'</span><span class="p">:</span> <span class="nb">set</span><span class="p">([</span><span class="s">u'rms'</span><span class="p">,</span> <span class="s">u'linus'</span><span class="p">]),</span>
<span class="s">u'trolls'</span><span class="p">:</span> <span class="nb">set</span><span class="p">([</span><span class="s">u'sballmer'</span><span class="p">]),</span>
<span class="s">u'python'</span><span class="p">:</span> <span class="nb">set</span><span class="p">(),</span>
<span class="s">u'php'</span><span class="p">:</span> <span class="nb">set</span><span class="p">()</span>
<span class="p">}</span>
<span class="k">def</span> <span class="nf">_get_all_sections</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="o">.</span><span class="n">fake_sections</span>
<span class="k">def</span> <span class="nf">_get_section_items</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">_find_sections</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">credentials</span><span class="p">):</span>
<span class="n">username</span> <span class="o">=</span> <span class="n">credentials</span><span class="p">[</span><span class="s">'repoze.what.userid'</span><span class="p">]</span>
<span class="k">return</span> <span class="nb">set</span><span class="p">([</span><span class="n">n</span> <span class="k">for</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">g</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
<span class="k">if</span> <span class="n">username</span> <span class="ow">in</span> <span class="n">g</span><span class="p">])</span>
<span class="k">def</span> <span class="nf">_include_items</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">items</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span> <span class="o">|=</span> <span class="n">items</span>
<span class="k">def</span> <span class="nf">_exclude_items</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">items</span><span class="p">):</span>
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">items</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_item_is_included</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
<span class="k">return</span> <span class="n">item</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">_create_section</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">_edit_section</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">new_section</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">new_section</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span>
<span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">_delete_section</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">):</span>
<span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">_section_exists</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">section</span><span class="p">)</span>
</pre></div>
</div>
<p>And the following class illustrates how a <a class="reference internal" href="GettingStarted.html#term-permission-adapter"><em class="xref std std-term">permission adapter</em></a> may look
like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">repoze.what.adapters</span> <span class="kn">import</span> <span class="n">BaseSourceAdapter</span>
<span class="k">class</span> <span class="nc">FakePermissionSourceAdapter</span><span class="p">(</span><span class="n">BaseSourceAdapter</span><span class="p">):</span>
<span class="sd">"""Mock permissions source adapter"""</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="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">FakePermissionSourceAdapter</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</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">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">u'see-site'</span><span class="p">:</span> <span class="nb">set</span><span class="p">([</span><span class="s">u'trolls'</span><span class="p">]),</span>
<span class="s">u'edit-site'</span><span class="p">:</span> <span class="nb">set</span><span class="p">([</span><span class="s">u'admins'</span><span class="p">,</span> <span class="s">u'developers'</span><span class="p">]),</span>
<span class="s">u'commit'</span><span class="p">:</span> <span class="nb">set</span><span class="p">([</span><span class="s">u'developers'</span><span class="p">])</span>
<span class="p">}</span>
<span class="k">def</span> <span class="nf">_get_all_sections</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="o">.</span><span class="n">fake_sections</span>
<span class="k">def</span> <span class="nf">_get_section_items</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">_find_sections</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">group_name</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">set</span><span class="p">([</span><span class="n">n</span> <span class="k">for</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
<span class="k">if</span> <span class="n">group_name</span> <span class="ow">in</span> <span class="n">p</span><span class="p">])</span>
<span class="k">def</span> <span class="nf">_include_items</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">items</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span> <span class="o">|=</span> <span class="n">items</span>
<span class="k">def</span> <span class="nf">_exclude_items</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">items</span><span class="p">):</span>
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">items</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_item_is_included</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
<span class="k">return</span> <span class="n">item</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">_create_section</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">_edit_section</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">new_section</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">new_section</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span>
<span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">_delete_section</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">):</span>
<span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="p">[</span><span class="n">section</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">_section_exists</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">fake_sections</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">section</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="module-repoze.what.adapters.testutil">
<span id="testing-your-source-adapters-with-testutil"></span><h3>Testing your source adapters with <a class="reference internal" href="#module-repoze.what.adapters.testutil" title="repoze.what.adapters.testutil: Automatic tests for repoze.what source adapters"><tt class="xref py py-mod docutils literal"><span class="pre">testutil</span></tt></a><a class="headerlink" href="#module-repoze.what.adapters.testutil" title="Permalink to this headline">¶</a></h3>
<p><a class="reference internal" href="../index.html#module-repoze.what" title="repoze.what: Authorization framework for WSGI applications"><tt class="xref py py-mod docutils literal"><span class="pre">repoze.what</span></tt></a> provides convenient utilities to automate the verification
of your adapters. This utility is the <a class="reference internal" href="#module-repoze.what.adapters.testutil" title="repoze.what.adapters.testutil: Automatic tests for repoze.what source adapters"><tt class="xref py py-mod docutils literal"><span class="pre">repoze.what.adapters.testutil</span></tt></a>
module, made up four test cases, which when extended must define the adapter
(as <tt class="docutils literal"><span class="pre">self.adapter</span></tt>) in the setup, as well as call this class’ <tt class="docutils literal"><span class="pre">setUp()</span></tt>
method:</p>
<dl class="class">
<dt id="repoze.what.adapters.testutil.ReadOnlyGroupsAdapterTester">
<em class="property">class </em><tt class="descclassname">repoze.what.adapters.testutil.</tt><tt class="descname">ReadOnlyGroupsAdapterTester</tt><a class="headerlink" href="#repoze.what.adapters.testutil.ReadOnlyGroupsAdapterTester" title="Permalink to this definition">¶</a></dt>
<dd><p>Test case for read-only groups source adapters.</p>
<p>The groups source used for the tests must only contain the following
groups (aka “sections”) and their relevant users (aka “items”; if any):</p>
<ul>
<li><dl class="first docutils">
<dt>admins</dt>
<dd><ul class="first last simple">
<li>rms</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>developers</dt>
<dd><ul class="first last simple">
<li>rms</li>
<li>linus</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>trolls</dt>
<dd><ul class="first last simple">
<li>sballmer</li>
</ul>
</dd>
</dl>
</li>
<li><p class="first">python</p>
</li>
<li><p class="first">php</p>
</li>
</ul>
<dl class="attribute">
<dt id="repoze.what.adapters.testutil.ReadOnlyGroupsAdapterTester.adapter">
<tt class="descname">adapter</tt><a class="headerlink" href="#repoze.what.adapters.testutil.ReadOnlyGroupsAdapterTester.adapter" title="Permalink to this definition">¶</a></dt>
<dd><p>An instance of the <a class="reference internal" href="GettingStarted.html#term-group-adapter"><em class="xref std std-term">group adapter</em></a> to be tested.</p>
</dd></dl>
<p>For example, a test case for the mock group adapter
<tt class="docutils literal"><span class="pre">FakeReadOnlyGroupSourceAdapter</span></tt> may look like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">repoze.what.adapters.testutil</span> <span class="kn">import</span> <span class="n">ReadOnlyGroupsAdapterTester</span>
<span class="k">class</span> <span class="nc">TestReadOnlyGroupsAdapterTester</span><span class="p">(</span><span class="n">ReadOnlyGroupsAdapterTester</span><span class="p">,</span>
<span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">setUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">TestReadOnlyGroupsAdapterTester</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">setUp</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">adapter</span> <span class="o">=</span> <span class="n">FakeReadOnlyGroupSourceAdapter</span><span class="p">()</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><a class="reference internal" href="#repoze.what.adapters.testutil.GroupsAdapterTester" title="repoze.what.adapters.testutil.GroupsAdapterTester"><tt class="xref py py-class docutils literal"><span class="pre">GroupsAdapterTester</span></tt></a> extends this test case to check write
operations.</p>
</div>
</dd></dl>
<dl class="class">
<dt id="repoze.what.adapters.testutil.ReadOnlyPermissionsAdapterTester">
<em class="property">class </em><tt class="descclassname">repoze.what.adapters.testutil.</tt><tt class="descname">ReadOnlyPermissionsAdapterTester</tt><a class="headerlink" href="#repoze.what.adapters.testutil.ReadOnlyPermissionsAdapterTester" title="Permalink to this definition">¶</a></dt>
<dd><p>Test case for read-only permissions source adapters.</p>
<p>The permissions source used for the tests must only contain the following
permissions (aka “sections”) and their relevant groups (aka “items”; if
any):</p>
<ul>
<li><dl class="first docutils">
<dt>see-site</dt>
<dd><ul class="first last simple">
<li>trolls</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>edit-site</dt>
<dd><ul class="first last simple">
<li>admins</li>
<li>developers</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>commit</dt>
<dd><ul class="first last simple">
<li>developers</li>
</ul>
</dd>
</dl>
</li>
</ul>
<dl class="attribute">
<dt id="repoze.what.adapters.testutil.ReadOnlyPermissionsAdapterTester.adapter">
<tt class="descname">adapter</tt><a class="headerlink" href="#repoze.what.adapters.testutil.ReadOnlyPermissionsAdapterTester.adapter" title="Permalink to this definition">¶</a></dt>
<dd><p>An instance of the <a class="reference internal" href="GettingStarted.html#term-permission-adapter"><em class="xref std std-term">permission adapter</em></a> to be tested.</p>
</dd></dl>
<p>For example, a test case for the mock permission adapter defined above
(<tt class="docutils literal"><span class="pre">FakeReadOnlyPermissionSourceAdapter</span></tt>) may look like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">repoze.what.adapters.testutil</span> <span class="kn">import</span> <span class="n">ReadOnlyPermissionsAdapterTester</span>
<span class="k">class</span> <span class="nc">TestReadOnlyPermissionsAdapterTester</span><span class="p">(</span><span class="n">ReadOnlyPermissionsAdapterTester</span><span class="p">,</span>
<span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">setUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">TestReadOnlyPermissionsAdapterTester</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">setUp</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">adapter</span> <span class="o">=</span> <span class="n">FakeReadOnlyPermissionSourceAdapter</span><span class="p">()</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><a class="reference internal" href="#repoze.what.adapters.testutil.PermissionsAdapterTester" title="repoze.what.adapters.testutil.PermissionsAdapterTester"><tt class="xref py py-class docutils literal"><span class="pre">PermissionsAdapterTester</span></tt></a> extends this test case to check write
operations.</p>
</div>
</dd></dl>
<dl class="class">
<dt id="repoze.what.adapters.testutil.GroupsAdapterTester">
<em class="property">class </em><tt class="descclassname">repoze.what.adapters.testutil.</tt><tt class="descname">GroupsAdapterTester</tt><a class="headerlink" href="#repoze.what.adapters.testutil.GroupsAdapterTester" title="Permalink to this definition">¶</a></dt>
<dd><p>Test case for groups source adapters.</p>
<p>This test case extends <a class="reference internal" href="#repoze.what.adapters.testutil.ReadOnlyGroupsAdapterTester" title="repoze.what.adapters.testutil.ReadOnlyGroupsAdapterTester"><tt class="xref py py-class docutils literal"><span class="pre">ReadOnlyGroupsAdapterTester</span></tt></a> to test
write operations in read & write adapters and it should be set up the same
way as its parent. For example, a test case for the mock group adapter
<tt class="docutils literal"><span class="pre">FakeGroupSourceAdapter</span></tt> may look like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">repoze.what.adapters.testutil</span> <span class="kn">import</span> <span class="n">GroupsAdapterTester</span>
<span class="k">class</span> <span class="nc">TestGroupsAdapterTester</span><span class="p">(</span><span class="n">GroupsAdapterTester</span><span class="p">,</span> <span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">setUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">TestGroupsAdapterTester</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">setUp</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">adapter</span> <span class="o">=</span> <span class="n">FakeGroupSourceAdapter</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="class">
<dt id="repoze.what.adapters.testutil.PermissionsAdapterTester">
<em class="property">class </em><tt class="descclassname">repoze.what.adapters.testutil.</tt><tt class="descname">PermissionsAdapterTester</tt><a class="headerlink" href="#repoze.what.adapters.testutil.PermissionsAdapterTester" title="Permalink to this definition">¶</a></dt>
<dd><p>Test case for permissions source adapters.</p>
<p>This test case extends <a class="reference internal" href="#repoze.what.adapters.testutil.ReadOnlyPermissionsAdapterTester" title="repoze.what.adapters.testutil.ReadOnlyPermissionsAdapterTester"><tt class="xref py py-class docutils literal"><span class="pre">ReadOnlyPermissionsAdapterTester</span></tt></a> to test
write operations in read & write adapters and it should be set up the same
way as its parent. For example, a test case for the mock group adapter
<tt class="docutils literal"><span class="pre">FakePermissionSourceAdapter</span></tt> may look like this:</p>
<p>For example, a test case for the mock permission adapter defined above
(<tt class="docutils literal"><span class="pre">FakePermissionSourceAdapter</span></tt>) may look like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">repoze.what.adapters.testutil</span> <span class="kn">import</span> <span class="n">PermissionsAdapterTester</span>
<span class="k">class</span> <span class="nc">TestPermissionsAdapterTester</span><span class="p">(</span><span class="n">PermissionsAdapterTester</span><span class="p">,</span>
<span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">setUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">TestPermissionsAdapterTester</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">setUp</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">adapter</span> <span class="o">=</span> <span class="n">FakePermissionSourceAdapter</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<div class="admonition attention">
<p class="first admonition-title">Attention</p>
<p class="last"><a class="reference internal" href="#module-repoze.what.adapters.testutil" title="repoze.what.adapters.testutil: Automatic tests for repoze.what source adapters"><tt class="xref py py-mod docutils literal"><span class="pre">repoze.what.adapters.testutil</span></tt></a> is not a full replacement for a test
suite, so you are still highly encouraged to write the relevant/missing
tests to lead the code coverage of your adapters to 100%.</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../index.html">
<img class="logo" src="../_static/logo_hi.gif" alt="Logo"/>
</a></p>
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">How to manage groups and permission sources</a><ul>
<li><a class="reference internal" href="#managing-your-sources">Managing your sources</a><ul>
<li><a class="reference internal" href="#retrieving-all-the-available-sections-from-a-source">Retrieving all the available <tt class="docutils literal"><span class="pre">sections</span></tt> from a source</a></li>
<li><a class="reference internal" href="#retrieving-all-the-items-from-a-given-section">Retrieving all the <tt class="docutils literal"><span class="pre">items</span></tt> from a given <tt class="docutils literal"><span class="pre">section</span></tt></a></li>
<li><a class="reference internal" href="#setting-the-items-of-a-given-section">Setting the <tt class="docutils literal"><span class="pre">items</span></tt> of a given <tt class="docutils literal"><span class="pre">section</span></tt></a></li>
<li><a class="reference internal" href="#including-items-in-a-section">Including <tt class="docutils literal"><span class="pre">items</span></tt> in a <tt class="docutils literal"><span class="pre">section</span></tt></a></li>
<li><a class="reference internal" href="#excluding-items-from-a-section">Excluding <tt class="docutils literal"><span class="pre">items</span></tt> from a <tt class="docutils literal"><span class="pre">section</span></tt></a></li>
<li><a class="reference internal" href="#adding-a-section-to-a-source">Adding a <tt class="docutils literal"><span class="pre">section</span></tt> to a <tt class="docutils literal"><span class="pre">source</span></tt></a></li>
<li><a class="reference internal" href="#renaming-a-section">Renaming a <tt class="docutils literal"><span class="pre">section</span></tt></a></li>
<li><a class="reference internal" href="#removing-a-section-from-a-source">Removing a <tt class="docutils literal"><span class="pre">section</span></tt> from a <tt class="docutils literal"><span class="pre">source</span></tt></a></li>
<li><a class="reference internal" href="#checking-whether-the-source-is-writable">Checking whether the <tt class="docutils literal"><span class="pre">source</span></tt> is writable</a></li>
</ul>
</li>
<li><a class="reference internal" href="#possible-problems">Possible problems</a></li>
<li><a class="reference internal" href="#writing-your-own-source-adapters">Writing your own source adapters</a><ul>
<li><a class="reference internal" href="#sample-source-adapters">Sample <tt class="docutils literal"><span class="pre">source</span> <span class="pre">adapters</span></tt></a></li>
<li><a class="reference internal" href="#module-repoze.what.adapters.testutil">Testing your source adapters with <tt class="docutils literal"><span class="pre">testutil</span></tt></a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="Predicates/Writing.html"
title="previous chapter">Creating your own single predicate checkers</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="Plugins/index.html"
title="next chapter"><tt class="docutils literal docutils literal"><span class="pre">repoze.what.plugins</span></tt> – Available plugins for <tt class="docutils literal docutils literal"><span class="pre">repoze.what</span></tt></a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/Manual/ManagingSources.txt"
rel="nofollow">Show Source</a></li>
</ul>
<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 class="right" >
<a href="Plugins/index.html" title="repoze.what.plugins – Available plugins for repoze.what"
>next</a> |</li>
<li class="right" >
<a href="Predicates/Writing.html" title="Creating your own single predicate checkers"
>previous</a> |</li>
<li><a href="../index.html">repoze.what 1.0.9 documentation</a> »</li>
<li><a href="index.html" >The <tt class="docutils literal docutils literal docutils literal docutils literal"><span class="pre">repoze.what</span></tt> Manual</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2008, The Repoze Project.
Last updated on May 03, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>
|