A container class for authorization scopes
Project description
scopelist
=========
|build-status| |license| |coveralls| |pypi|
.. important:: This package is outdated. It's replacement can be found at https://pypi.python.org/pypi/scopes
*scopelist* exposes the ``ScopeList`` class, a container type intended to
simplify checking authorization scope.
Installation
------------
You can install scopelist from PyPi::
> pip install scopelist
That should install all the dependencies for you. If you want to install
directly from source, clone the git repository and run the standard
`python setup.py install` command.
Dependencies
~~~~~~~~~~~~
* Python 2.7, 3.2+
Usage
-----
ScopeList 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'])
True
A 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'])
False
They 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'])
Permissions
~~~~~~~~~~~
You 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'])
True
Indicate 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'])
True
Permissions are totally arbitrary, except that ``+r`` is assumed by
default when no permissions are explicitly given.
>>> 'user/emails+r' in ScopeList(['user/emails'])
True
You 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')
True
The permissions separator is also configurable.
>>> 'user/emails|r' in ScopeList(['user/emails'], mode_sep='|')
True
Parents
~~~~~~~
The ``/`` 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'])
True
The child separator can also be changed:
>>> 'user:emails+r' in ScopeList(['user'], child_sep=':')
True
.. |build-status| image:: https://travis-ci.org/te-je/scopelist.svg?branch=develop
:target: https://travis-ci.org/te-je/scopelist?branch=develop
:alt: build status
:scale: 100%
.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg
:target: https://raw.githubusercontent.com/te-je/scopelist/develop/LICENSE.rst
:alt: License
:scale: 100%
.. |pypi| image:: https://img.shields.io/pypi/v/scopelist.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/scopelist
:scale: 100%
.. |coveralls| image:: https://coveralls.io/repos/github/te-je/scopelist/badge.svg?branch=develop
:target: https://coveralls.io/github/te-je/scopelist?branch=develop
License
-------
Copyright (c) 2016 Te-jé Rodgers
Permission 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.
=========
|build-status| |license| |coveralls| |pypi|
.. important:: This package is outdated. It's replacement can be found at https://pypi.python.org/pypi/scopes
*scopelist* exposes the ``ScopeList`` class, a container type intended to
simplify checking authorization scope.
Installation
------------
You can install scopelist from PyPi::
> pip install scopelist
That should install all the dependencies for you. If you want to install
directly from source, clone the git repository and run the standard
`python setup.py install` command.
Dependencies
~~~~~~~~~~~~
* Python 2.7, 3.2+
Usage
-----
ScopeList 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'])
True
A 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'])
False
They 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'])
Permissions
~~~~~~~~~~~
You 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'])
True
Indicate 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'])
True
Permissions are totally arbitrary, except that ``+r`` is assumed by
default when no permissions are explicitly given.
>>> 'user/emails+r' in ScopeList(['user/emails'])
True
You 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')
True
The permissions separator is also configurable.
>>> 'user/emails|r' in ScopeList(['user/emails'], mode_sep='|')
True
Parents
~~~~~~~
The ``/`` 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'])
True
The child separator can also be changed:
>>> 'user:emails+r' in ScopeList(['user'], child_sep=':')
True
.. |build-status| image:: https://travis-ci.org/te-je/scopelist.svg?branch=develop
:target: https://travis-ci.org/te-je/scopelist?branch=develop
:alt: build status
:scale: 100%
.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg
:target: https://raw.githubusercontent.com/te-je/scopelist/develop/LICENSE.rst
:alt: License
:scale: 100%
.. |pypi| image:: https://img.shields.io/pypi/v/scopelist.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/scopelist
:scale: 100%
.. |coveralls| image:: https://coveralls.io/repos/github/te-je/scopelist/badge.svg?branch=develop
:target: https://coveralls.io/github/te-je/scopelist?branch=develop
License
-------
Copyright (c) 2016 Te-jé Rodgers
Permission 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
scopelist-0.1.3.zip
(12.4 kB
view details)
Built Distribution
File details
Details for the file scopelist-0.1.3.zip
.
File metadata
- Download URL: scopelist-0.1.3.zip
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3178f55a6b65302d548092a6dc303887780f1b8d3cc29456c013c14db25403f7 |
|
MD5 | 80577fcc0bbffa144cf2a7efc97b3c73 |
|
BLAKE2b-256 | ac1f39505b26ea3040c4ac6a5140178b7454e99fb0b1b801e8438186239c4bc7 |
File details
Details for the file scopelist-0.1.3-py2.py3-none-any.whl
.
File metadata
- Download URL: scopelist-0.1.3-py2.py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0daaa3628395ebda907fb23bcb34da1afaa11a9f7f1f6213f1974d60549a9d0 |
|
MD5 | 4d6c55bd4243969fd1ba8af7d0c64f9f |
|
BLAKE2b-256 | 41e841b96e27587c2940051746c851bd9551f02b73f60c31eede601c08725cd2 |