Scope Parsing¶
Scope parsing is handled by the ScopeParser
type.
Additionally, Scope
objects define a
parse()
method which wraps parser
usage.
ScopeParser
provides classmethods as its primary interface, so there
is no need to instantiate the parser in order to use it.
ScopeParser Reference¶
- class globus_sdk.scopes.ScopeParser[source]¶
Bases:
object
The
ScopeParser
handles the conversion of strings to scopes.Most interfaces are classmethods, meaning users should prefer usage like
ScopeParser.parse("foo")
- classmethod merge_scopes(scopes_a, scopes_b)[source]¶
Given two lists of Scopes, merge them into one list of Scopes by parsing them as one combined scope string.
- classmethod parse(scope_string)[source]¶
Parse an arbitrary scope string to a list of scopes.
Zero or more than one scope may be returned, as in the case of an empty string or space-delimited scopes.
Warning
Parsing passes through an intermediary representation which treats scopes as a graph. This ensures that the behavior of parses matches the treatment of scope strings in Globus Auth authorization flows. However, this also means that the parsing does not allow for strings which represent consent trees with structures in which the same scope appears in multiple parts of the tree.
- class globus_sdk.scopes.ScopeCycleError[source]¶
The error raised if scope parsing discovers a cycle.
Utility Functions
globus_sdk.scopes
also provides helper functions which are used to
manipulate scope objects.
- globus_sdk.scopes.scopes_to_str(scopes)[source]¶
Normalize a scope collection to a space-separated scope string.
- Parameters:
scopes (ScopeCollectionType) – A scope string or object, or an iterable of scope strings or objects.
- Returns:
A space-separated scope string.
- Return type:
Example usage:
>>> scopes_to_str(Scope("foo")) 'foo' >>> scopes_to_str(Scope("foo"), "bar", Scope("qux")) 'foo bar qux'
- globus_sdk.scopes.scopes_to_scope_list(scopes)[source]¶
Normalize a scope collection to a list of Scope objects.
- Parameters:
scopes (ScopeCollectionType) – A scope string or object, or an iterable of scope strings or objects.
- Returns:
A list of Scope objects.
- Return type:
Example usage:
>>> scopes_to_scope_list(Scope("foo")) [Scope('foo')] >>> scopes_to_scope_list(Scope("foo"), "bar baz", Scope("qux")) [Scope('foo'), Scope('bar'), Scope('baz'), Scope('qux')]