Package: scopelist
ImportantThis package is outdated. It’s replacement can be found athttps://pypi.python.org/pypi/scopesscopelistexposes theScopeListclass, a container type intended to
simplify checking authorization scope.InstallationYou can install scopelist from PyPi:> pip install scopelistThat should install all the dependencies for you. If you want to install
directly from source, clone the git repository and run the standardpython setup.py installcommand.DependenciesPython 2.7, 3.2+UsageScopeList implements the__contains__magic method, making it easy
to check if a particular scope and permission is expressed a list of
scopes.>>> from scopelist import ScopeList
>>> ScopeList(['user/emails+r'])
ScopeList(['user/emails'])
>>> 'user/emails' in ScopeList(['user/emails'])
TrueA ScopeList in fact works like any immutable sequence.>>> len(ScopeList(['user/emails', 'user/repo']))
2
>>> ScopeList(['user/emails+r', 'user/repo+aaaaa'])[1]
'user/repo+a'
>>> list(ScopeList(['user/emails+r', 'user/repo+aaaaa']))
['user/emails', 'user/repo+a']
>>> ['foo/bar', 'foo/baz'] in ScopeList.from_string('foo')
True
>>> ['foo/bar', 'foo/baz', 'extra'] in ScopeList(['foo', 'bar'])
FalseThey can be parsed directly from strings too>>> ScopeList.from_string("user/emails+r   user/emails+n")
ScopeList(['user/emails', 'user/emails+n'])>>> ScopeList.from_string("user/emails+r:user/emails+n", item_sep=":")
ScopeList(['user/emails', 'user/emails+n'])PermissionsYou can append letters to scope items to express certain permissions.
Any ascii letter that follows the permission separator (+by
default) is interpreted as a permission. When checking for an item
in the scope list, both its value and permission must match at least
one item in the list.>>> 'user/emails+a' in ScopeList(['user/emails'])
False
>>> 'user/emails+a' in ScopeList(['user/emails+a'])
TrueIndicate multiple permissions in a scope list item by including more than
one letter after the+symbol. Duplicate permissions are ignored.>>> 'user/repo+w' in ScopeList(['user/repo+abcd', 'user/repo+rw'])
TruePermissions are totally arbitrary, except that+ris assumed by
default when no permissions are explicitly given.>>> 'user/emails+r' in ScopeList(['user/emails'])
TrueYou can change the default permissions to whatever you like.>>> 'user/emails+n' in ScopeList(['user/emails'], default_mode='n')
True
>>> 'user/emails+q' in ScopeList(['user/emails'], default_mode='pq')
True
>>> 'user/emails+p' in ScopeList(['user/emails'], default_mode='pq')
TrueThe permissions separator is also configurable.>>> 'user/emails|r' in ScopeList(['user/emails'], mode_sep='|')
TrueParentsThe/symbol is the default child separator. Parent scope items
automatically ‘contain’ child items in the scope list.>>> 'user/emails+r' in ScopeList(['user'])
True
>>> 'user/emails+w' in ScopeList(['user'])
False
>>> 'user/emails+rw' in ScopeList(['user+w', 'user/emails+r'])
TrueThe child separator can also be changed:>>> 'user:emails+r' in ScopeList(['user'], child_sep=':')
TrueLicenseCopyright (c) 2016 Te-jé RodgersPermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.