A container class for authorization scopes
Project description
scopes
=========
|build-status| |license| |coveralls| |pypi|
*scopes* exposes the ``Set`` class, a container type intended to
simplify checking authorization scope.
Installation
------------
You can install scopes from PyPi::
> pip install scopes
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
-----
scopes.Set implements the ``__contains__`` magic method, making it easy
to check if a particular scope and permission is expressed in a set of
scopes.
>>> from scopes import Set
>>> Set(['user/emails+r'])
Set(['user/emails'])
>>> 'user/emails' in Set(['user/emails'])
True
>>> ('foo/bar', 'foo/baz') <= Set('foo')
True
>>> ['foo/bar', 'foo/baz', 'extra'] <= Set(['foo', 'bar'])
False
>>> Set(['foo', 'bar']) >= ('foo/bar', 'foo/baz')
True
A Set in fact works almost like any set type.
>>> len(Set(['user/emails', 'user/repo']))
2
>>> list(Set(['user/emails+r', 'user/repo+aaaaa']).formatted())
['user/emails', 'user/repo+a']
They can be quickly parsed from strings too.
>>> Set("user/emails+r user/emails+n")
Set(['user/emails', 'user/emails+n'])
This method uses a single space as a separator.
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 Set(['user/emails'])
False
>>> 'user/emails+a' in Set(['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 Set(['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 Set(['user/emails'])
True
You can change the default permissions to whatever you like.
>>> 'user/emails+n' in Set(['user/emails'], default_permissions='n')
True
>>> 'user/emails+q' in Set(['user/emails'], default_permissions='pq')
True
>>> 'user/emails+p' in Set(['user/emails'], default_permissions='pq')
True
The permissions separator is also configurable.
>>> 'user/emails|r' in Set(['user/emails'], permission_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 Set(['user'])
True
>>> 'user/emails+w' in Set(['user'])
False
>>> 'user/emails+rw' in Set(['user+w', 'user/emails+r'])
True
The child separator can also be changed:
>>> 'user:emails+r' in Set(['user'], child_sep=':')
True
.. |build-status| image:: https://travis-ci.org/te-je/scopes.svg?branch=develop
:target: https://travis-ci.org/te-je/scopes?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/scopes/develop/LICENSE.rst
:alt: License
:scale: 100%
.. |pypi| image:: https://img.shields.io/pypi/v/scopes.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/scopes
:scale: 100%
.. |coveralls| image:: https://coveralls.io/repos/github/te-je/scopes/badge.svg?branch=develop
:target: https://coveralls.io/github/te-je/scopes?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|
*scopes* exposes the ``Set`` class, a container type intended to
simplify checking authorization scope.
Installation
------------
You can install scopes from PyPi::
> pip install scopes
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
-----
scopes.Set implements the ``__contains__`` magic method, making it easy
to check if a particular scope and permission is expressed in a set of
scopes.
>>> from scopes import Set
>>> Set(['user/emails+r'])
Set(['user/emails'])
>>> 'user/emails' in Set(['user/emails'])
True
>>> ('foo/bar', 'foo/baz') <= Set('foo')
True
>>> ['foo/bar', 'foo/baz', 'extra'] <= Set(['foo', 'bar'])
False
>>> Set(['foo', 'bar']) >= ('foo/bar', 'foo/baz')
True
A Set in fact works almost like any set type.
>>> len(Set(['user/emails', 'user/repo']))
2
>>> list(Set(['user/emails+r', 'user/repo+aaaaa']).formatted())
['user/emails', 'user/repo+a']
They can be quickly parsed from strings too.
>>> Set("user/emails+r user/emails+n")
Set(['user/emails', 'user/emails+n'])
This method uses a single space as a separator.
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 Set(['user/emails'])
False
>>> 'user/emails+a' in Set(['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 Set(['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 Set(['user/emails'])
True
You can change the default permissions to whatever you like.
>>> 'user/emails+n' in Set(['user/emails'], default_permissions='n')
True
>>> 'user/emails+q' in Set(['user/emails'], default_permissions='pq')
True
>>> 'user/emails+p' in Set(['user/emails'], default_permissions='pq')
True
The permissions separator is also configurable.
>>> 'user/emails|r' in Set(['user/emails'], permission_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 Set(['user'])
True
>>> 'user/emails+w' in Set(['user'])
False
>>> 'user/emails+rw' in Set(['user+w', 'user/emails+r'])
True
The child separator can also be changed:
>>> 'user:emails+r' in Set(['user'], child_sep=':')
True
.. |build-status| image:: https://travis-ci.org/te-je/scopes.svg?branch=develop
:target: https://travis-ci.org/te-je/scopes?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/scopes/develop/LICENSE.rst
:alt: License
:scale: 100%
.. |pypi| image:: https://img.shields.io/pypi/v/scopes.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/scopes
:scale: 100%
.. |coveralls| image:: https://coveralls.io/repos/github/te-je/scopes/badge.svg?branch=develop
:target: https://coveralls.io/github/te-je/scopes?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
scopes-0.2.0.zip
(12.9 kB
view details)
Built Distribution
File details
Details for the file scopes-0.2.0.zip
.
File metadata
- Download URL: scopes-0.2.0.zip
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27e7a11cac56f5adf209d079bf4fd7e54db5ff50404c9bb0cb07690f5998321f |
|
MD5 | 77fd9cbd9c987bd2a023bd0ca9e483cf |
|
BLAKE2b-256 | b4f98d36edf49f25c86ce14bf6b7b383948819a60fa362acf375edc3a47b49eb |
File details
Details for the file scopes-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: scopes-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42f7458d22277647ee5f8fc38b90e321646b4bf5b54cb88b6ecf9867bd54d8da |
|
MD5 | 52b1fda508e103d4486e4d42bfa6f512 |
|
BLAKE2b-256 | ae64edbdc210f435fe8e95200e85470184b4c0fe2f0ee13c577a27940943b8e6 |